This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
img_url = "http://fffffffffffffffffffffffuuuuuuuuuuuuuuuuuuuuuu.com/big.jpg?im=" | |
(1..1044).each do |x| | |
n = '%.4d' % x + ".jpg" | |
open(n, "wb").write(open(img_url+n).read) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#0> non-block call | |
Thread.new do | |
blahbla... | |
end | |
#1> 4 simple ways to call shell or cmd | |
`ps aux` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#clone repl from github or download form http://neugierig.org/software/c-repl/ | |
git clone https://github.com/martine/c-repl.git c-repl | |
#install dependencies | |
sudo apt-get install ghc6 gccxml libghc6-parsec-dev libghc6-mtl-dev \ | |
libghc6-hunit-dev | |
sudo apt-get install gdb libexpat1-dev c2hs libreadline-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def call_block | |
puts "before call" | |
yield | |
yield | |
puts "after call" | |
end | |
call_block{ puts "call" } #before call\ncall\ncall\nafter call | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Person | |
class Person | |
end | |
#class method | |
class Person | |
def self.address | |
puts "hangzhou" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def block_new | |
puts Proc.new.call | |
end | |
block_new{"hello"} | |
#slow practice | |
def herp_pass_block(&block) | |
derp_call_block &block | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mongoid' | |
Mongoid.configure do |config| | |
name = "db" | |
host = "localhost" | |
config.master = Mongo::Connection.new.db(name) | |
config.slaves = [ | |
Mongo::Connection.new(host, 27017, :slave_ok => false).db(name) | |
] | |
config.persist_in_safe_mode = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#rubbish showoff | |
#libxslt is missing or libxml2 | |
sudo apt-get install libxslt-dev libxml2-dev | |
gem install rmagick | |
#Can't find Magick-config or GraphicsMag ick-config program. | |
sudo apt-get install libmagick9-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fiber' | |
fib = Fiber.new do | |
v = 0 | |
loop do | |
v += 1 | |
Fiber.yield v | |
v.times { print "-"} | |
puts v | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'twitter' | |
Twitter.configure do |config| | |
config.consumer_key="8n30gzQJFwcexyrnbKFTqw" | |
config.consumer_secret="tzwvlxUyENhFEvX2bj0mDevSSLCMVNjY1zhM2O2Z5E" | |
config.oauth_token="34916016-Qph9S5HS2FyDcVIEYIraswexmYpBBRqnLoX6e1ncZ" | |
config.oauth_token_secret="8nkOjeYUK3RO5bRySz3YIYYiOc4mPxjxZM8GVoHDs" | |
end | |
client = Twitter::Client.new |
OlderNewer