Skip to content

Instantly share code, notes, and snippets.

@cawel
cawel / gist:17565cd0125a1eddeab9
Created November 19, 2014 23:27
blog-quiz-easy-7
VALUE rb_ary_each(ary)
VALUE ary;
{
long i;
for (i=0; ilen; i++) {
rb_yield(RARRAY(ary)->ptr[i]);
}
return ary;
}
@cawel
cawel / gist:2b5f498ec50685f71e38
Last active August 29, 2015 14:10
blog-quiz-advanced-2
class Base
def initialize
@@var = 'base'
end
def base_set_var
@@var = 'base'
end
def base_print_var
@cawel
cawel / gist:5ac7b7f28fa5ad80a7b0
Created November 20, 2014 14:26
blog-quiz-advanced-1
def process(values)
result = Proc.new { return values.max }.call
result * 100
end
puts process( [1,2,3] )
@cawel
cawel / gist:3b63df6bf59d71fafc95
Created November 20, 2014 14:27
blog-quiz-advanced-1b
def process(values)
result = lambda { return values.max }.call
result * 100
end
puts process( [1,2,3] )
@cawel
cawel / gist:f291d03c2c40b0e696a9
Created November 20, 2014 15:01
blog-quiz-easy-6
y = false
z = 1
x = y or z
def z arg
arg * 10
end
puts x
#!/usr/bin/env ruby
require 'open-uri'
require "rexml/document"
require 'rexml/xpath'
feed_link = "http://feeds.feedburner.com/37signals/beMH"
title, published_date = "", ""
TITLE_PATH = "//item//title"
DATE_PATH = "//item/pubDate"
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'feed-normalizer'
def every seconds, &block
while true
yield
sleep seconds
end
@cawel
cawel / gist:78a2d567de66b844bc78
Created November 21, 2014 00:02
blog-scrubyt
require 'rubygems'
require 'scrubyt'
HASH_TERM = "leadscon"
data = Scrubyt::Extractor.define do
fetch 'http://www.hashtweeps.com/'
fill_textfield "term", HASH_TERM
submit
@cawel
cawel / gist:6dbe01aff69dc93ec992
Last active August 29, 2015 14:10
blog-best-practice-1
# using properly-named methods indicate the intention
# as opposed to having the logic inlined
class RemoteCache < Remote
def deploy!
update_repository_cache
copy_repository_cache
end
end
@cawel
cawel / gist:275cd348b9e5af6924c1
Last active August 29, 2015 14:10
blog-best-practices-2
# using a block ensures the file is closed when done
File.open("temp_file") do |file|
file.write(data)
end