Skip to content

Instantly share code, notes, and snippets.

View duobei's full-sized avatar
🐳
dingdong

Luca Zhang duobei

🐳
dingdong
View GitHub Profile
@duobei
duobei / proc.rb
Created October 16, 2012 14:52 — forked from SaitoWu/proc.rb
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
@duobei
duobei / runable.rb
Created October 16, 2012 14:52 — forked from SaitoWu/runable.rb
exec something on ruby.
#0> non-block call
Thread.new do
blahbla...
end
#1> 4 simple ways to call shell or cmd
`ps aux`
@duobei
duobei / eigenclass.rb
Created October 16, 2012 14:52 — forked from SaitoWu/eigenclass.rb
some ruby meta programming demo.
#Person
class Person
end
#class method
class Person
def self.address
puts "hangzhou"
end
end
@duobei
duobei / code_line_static
Created September 17, 2012 02:31
统计代码行数
find . -type f -not -regex '\./\.git.*' | xargs cat | wc -l
@duobei
duobei / lookup.c
Created June 29, 2012 08:30
Binary search example in "The Practice of Programming"
int lookup(char *name, Nameval tab[], int ntab)
{
int low, high, mid, cmp;
low = 0;
high = ntab - 1;
while (low <= high) {
mid = (low + high) >> 2;
cmp = strcmp(name, tab[mid].name);
if (cmp < 0)
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal