Hexo


  • 首頁

  • 歸檔

  • 標籤

  • 分類

Animal Farm

發表於 2017-03-27 | 分類於 English |

Part 1

1

Mr. Jones, of the Manor Farm, had locked the hen-houses for the night, but was too drunk to remember to shut the popholes. With the ring of light from his lantern dancing from side to side, he lurched across the yard, kicked off his boots at the back door, drew himself a last glass of beer from the barrel in the scullery, and made his way up to bed, where Mrs. Jones was already snoring.

As soon as the light in the bedroom went out there was a stirring and a fluttering all through the farm buildings. Word had gone round during the day that old Major, the prize Middle White boar, had had a strange dream on the previous night and wished to communicate it to the other animals. It had been agreed that they should all meet in the big barn as soon as Mr. Jones was safely out of the way. Old Major (so he was always called, though the name under which he had been exhibited was Willingdon Beauty) was so highly regarded on the farm that everyone was quite ready to lose an hour’s sleep in order to hear what he had to say.

2

At one end of the big barn, on a sort of raised platform, Major was already ensconced on his bed of straw, under a lantern which hung from a beam. He was twelve years old and had lately grown rather stout, but he was still a majestic-looking pig, with a wise and benevolent appearance in spite of the fact that his tusks had never been cut. Before long the other animals began to arrive and make themselves comfortable after their different fashions. First came the three dogs, Bluebell, Jessie, and Pincher, and then the pigs, who settled down in the straw immediately in front of the platform. The hens perched themselves on the window-sills, the pigeons fluttered up to the rafters, the sheep and cows lay down behind the pigs and began to chew the cud. The two cart-horses, Boxer and Clover, came in together, walking very slowly and setting down their vast hairy hoofs with great care lest there should be some small animal concealed in the straw. Clover was a stout motherly mare approaching middle life, who had never quite got her figure back after her fourth foal. Boxer was an enormous beast, nearly eighteen hands high, and as strong as any two ordinary horses put together. A white stripe down his nose gave him a somewhat stupid appearance, and in fact he was not of first-rate intelligence, but he was universally respected for his steadiness of character and tremendous powers of work. After the horses came Muriel, the white goat, and Benjamin, the donkey. Benjamin was the oldest animal on the farm, and the worst tempered. He seldom talked, and when he did, it was usually to make some cynical remark — for instance, he would say that God had given him a tail to keep the flies off, but that he would sooner have had no tail and no flies. Alone among the animals on the farm he never laughed. If asked why, he would say that he saw nothing to laugh at. Nevertheless, without openly admitting it, he was devoted to Boxer; the two of them usually spent their Sundays together in the small paddock beyond the orchard, grazing side by side and never speaking.

3

The two horses had just lain down when a brood of ducklings, which had lost their mother, filed into the barn, cheeping feebly and wandering from side to side to find some place where they would not be trodden on. Clover made a sort of wall round them with her great foreleg, and the ducklings nestled down inside it and promptly fell asleep. At the last moment Mollie, the foolish, pretty white mare who drew Mr. Jones’s trap, came mincing daintily in, chewing at a lump of sugar. She took a place near the front and began flirting her white mane, hoping to draw attention to the red ribbons it was plaited with. Last of all came the cat, who looked round, as usual, for the warmest place, and finally squeezed herself in between Boxer and Clover; there she purred contentedly throughout Major’s speech without listening to a word of what he was saying.

All the animals were now present except Moses, the tame raven, who slept on a perch behind the back door. When Major saw that they had all made themselves comfortable and were waiting attentively, he cleared his throat and began:

Comrades, you have heard already about the strange dream that I had last night. But I will come to the dream later. I have something else to say first. I do not think, comrades, that I shall be with you for many months longer, and before I die, I feel it my duty to pass on to you such wisdom as I have acquired. I have had a long life, I have had much time for thought as I lay alone in my stall, and I think I may say that I understand the nature of life on this earth as well as any animal now living. It is about this that I wish to speak to you.

閱讀全文 »

Could not verify the SSL certificate

發表於 2016-10-31 | 分類於 疑難雜症 |

今天想開一個新專案的時候,一直出現 Could not verify the SSL certificate,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
run bundle install
Fetching source index from https://rubygems.org/
Retrying fetcher due to error (2/4): Bundler::Fetcher::CertificateFailureError Could not verify the SSL certificate for https://rubygems.org/.
There is a chance you are experiencing a man-in-the-middle attack, but most likely your system doesn't have the CA certificates needed for verification. For information about OpenSSL certificates, see http://bit.ly/ruby-ssl. To connect without using SSL, edit your Gemfile sources and change 'https' to 'http'.
Retrying fetcher due to error (3/4): Bundler::Fetcher::CertificateFailureError Could not verify the SSL certificate for https://rubygems.org/.
There is a chance you are experiencing a man-in-the-middle attack, but most likely your system doesn't have the CA certificates needed for verification. For information about OpenSSL certificates, see http://bit.ly/ruby-ssl. To connect without using SSL, edit your Gemfile sources and change 'https' to 'http'.
Retrying fetcher due to error (4/4): Bundler::Fetcher::CertificateFailureError Could not verify the SSL certificate for https://rubygems.org/.
There is a chance you are experiencing a man-in-the-middle attack, but most likely your system doesn't have the CA certificates needed for verification. For information about OpenSSL certificates, see http://bit.ly/ruby-ssl. To connect without using SSL, edit your Gemfile sources and change 'https' to 'http'.
Could not verify the SSL certificate for https://rubygems.org/.
There is a chance you are experiencing a man-in-the-middle attack, but most
likely your system doesn't have the CA certificates needed for verification. For
information about OpenSSL certificates, see http://bit.ly/ruby-ssl. To connect
without using SSL, edit your Gemfile sources and change 'https' to 'http'.

爬了一整天的文都找不到解法,乾脆把所有的 openssl 全部砍掉重裝,結果就正常了,囧

  1. $ brew uninstall --force openssl
  2. $ brew install openssl
閱讀全文 »

比較各種方式在 Rails DB 中寫入大筆資料的速度

發表於 2016-10-25 | 分類於 Rails |

這幾天在練習寫爬蟲,一開始我的做法是每爬到一筆資料,就把它存到 DB 裡面,但是若爬了一萬筆資料,就表示你要做一萬次 DB transaction,這些時間累積下來也是很可觀的,因此本篇將來探討不同的多筆資料寫入 DB 的方式,會有什麼樣的差異

PS:本文實驗的方式都是從 CSV 讀取資料再存到 DB

方法 A:一次寫入一筆資料

1
2
3
4
5
6
7
8
9
10
11
def perform
Pokemon.delete_all
CSV.foreach(csv_path, headers: true) do |row|
Pokemon.create(
name: row["Name"],
location: row["Location"],
level: row["Level"].to_i
)
end
end
1
2
3
4
5
6
7
8
(0.1ms) begin transaction
SQL (0.3ms) INSERT INTO "pokemons" ("name", "location", "level", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [["name", "Meowth"], ["location", "Cerulean City"], ["level", 44], ["created_at", 2016-07-22 08:00:54 UTC], ["updated_at", 2016-07-22 08:00:54 UTC]]
(0.8ms) commit transaction
(0.1ms) begin transaction
SQL (0.3ms) INSERT INTO "pokemons" ("name", "location", "level", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [["name", "Bulbasaur"], ["location", "Verdanturf Town"], ["level", 33], ["created_at", 2016-07-22 08:00:54 UTC], ["updated_at", 2016-07-22 08:00:54 UTC]]
(0.9ms) commit transaction
...

可以很清楚的看出,每次寫入一筆資料就要做一次 transaction

方法 B:用 ActiveRecord::Base.transaction 把資料寫入的程式包起來

程式同方法 A,但是用 ActiveRecord::Base.transaction 把它包起來

1
2
3
4
5
6
7
8
9
10
11
12
13
def perform
Pokemon.delete_all
ActiveRecord::Base.transaction do
CSV.foreach(csv_path, headers: true) do |row|
Pokemon.create(
name: row["Name"],
location: row["Location"],
level: row["Level"].to_i
)
end
end
end
閱讀全文 »

vim-rails Plugin 使用教學

發表於 2016-10-25 | 分類於 Rails |

這套由 tpope 所開發的 Plugin 我覺得對 Rails 的開發很有幫助,介紹給大家。

片長約 20 分鐘,建議可以用 1.5 倍速觀看。

vim rails 介紹 (推薦 1.5 倍速觀看) - YouTube

補充資料

github:tpope/vim-rails: rails.vim: Ruby on Rails power tools

說明檔:vim-rails/rails.txt at master · tpope/vim-rails

vim-rails 有整合 Ctag,所以其實只要在 vim 裡面下 :Ctags 就可以了,若想額外設定的話可以在 vimrc 裡面設定 Ctag 譬如:

let g:rails_ctags_arguments = ['--languages=ruby --exclude=.git --exclude=log .']

心得

原來拍個介紹影片比想像中難幾百倍,現在回頭看一下 RailsCasts 拍的品質真的很棒、而且又清楚,不知道怎麼做到的,之後有機會想學一下剪接,一鏡到底真的會一直吃螺絲,一邊操作一邊講更難,寫了逐字稿好像也沒什麼用,稍微背一下流程應該可以更好,不過我懶了,為了拍這個已經花了兩天,還是學會剪接後再來拍下一集。

閱讀全文 »

zsh shell 下無法使用 vim-rails 的解決辦法

發表於 2015-12-10 | 分類於 疑難雜症 |

更新 2016/01/03

發現有另外一招也可以用,所以這一招不管用試試看另外一招即可

sudo mv /etc/zshenv /etc/zshrc

這樣的話可以讓 vim 正確的吃到 zsh 的 $PATH

先說結論

若你在 zsh shell $ echo $PATH,與在 vim 裡面 :!echo $PATH 的值不一樣,你可以試試看在 .vimrc 裡面指定 shell 為 bash。

set shell=/bin/sh

解決經過

前幾天看到這篇 Effective Rails Development with Vim 後,就一直想試試看 tpope/vim-rails 但是昨天試了各種 R command 都沒辦法用,因為我一但在 vim 裡面輸入 R command,譬如 :Rserver 就會跳出

1
2
3
4
5
6
7
Warning: You're using Rubygems 2.0.14 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
Could not find rdoc-4.2.0 in any of the sources
Run `bundle install` to install missing gems.
shell returned 7
Press ENTER or type command to continue
閱讀全文 »
kakas

kakas

Learning by Doing

5 文章
3 分類
6 標籤
GitHub
© 2017 kakas
由 Hexo 強力驅動
主題 - NexT.Pisces