Skip to content

Instantly share code, notes, and snippets.

View SaitoWu's full-sized avatar
:shipit:
Hacking everyday

Xin Wu SaitoWu

:shipit:
Hacking everyday
View GitHub Profile
@SaitoWu
SaitoWu / fffffuuuu.rb
Created January 14, 2011 17:38
amazing script for fun from fffffuuu comic.
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
@SaitoWu
SaitoWu / runable.rb
Created February 11, 2011 08:57
exec something on ruby.
#0> non-block call
Thread.new do
blahbla...
end
#1> 4 simple ways to call shell or cmd
`ps aux`
@SaitoWu
SaitoWu / c-repo.sh
Created February 12, 2011 10:52
build your own c-repl
#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
@SaitoWu
SaitoWu / exp.rb
Created March 5, 2011 18:04
some ruby language exercise
def call_block
puts "before call"
yield
yield
puts "after call"
end
call_block{ puts "call" } #before call\ncall\ncall\nafter call
@SaitoWu
SaitoWu / eigenclass.rb
Created March 16, 2011 07:53
some ruby meta programming demo.
#Person
class Person
end
#class method
class Person
def self.address
puts "hangzhou"
end
end
@SaitoWu
SaitoWu / proc.rb
Created March 17, 2011 14:44
magic ruby proc demo
def block_new
puts Proc.new.call
end
block_new{"hello"}
#slow practice
def herp_pass_block(&block)
derp_call_block &block
end
@SaitoWu
SaitoWu / mongoid.rb
Created March 18, 2011 20:42
some mongoid cheet-sheet
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
@SaitoWu
SaitoWu / rubbish_showoff.sh
Created March 18, 2011 20:46
install rubbish showoff!
#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
@SaitoWu
SaitoWu / fibers.rb
Created June 28, 2011 05:47
ruby fibers exercise
require 'fiber'
fib = Fiber.new do
v = 0
loop do
v += 1
Fiber.yield v
v.times { print "-"}
puts v
end
@SaitoWu
SaitoWu / twitter.rb
Created July 29, 2011 10:48
weibo client and twitter client, use weibo_oauth and twitter_oauth to get ur own oauth_token and oauth_token_secret
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