Skip to content

Instantly share code, notes, and snippets.

View angelfan's full-sized avatar

耿返 angelfan

View GitHub Profile
@angelfan
angelfan / stringify_keys.rb
Created July 28, 2016 10:04 — forked from mkuhnt/stringify_keys.rb
Deep Stringify Keys of hash even with embedded arrays
def transform_hash(original, options={}, &block)
original.inject({}){|result, (key,value)|
value = if (options[:deep] && Hash === value)
transform_hash(value, options, &block)
else
if Array === value
value.map{|v| transform_hash(v, options, &block)}
else
value
end
@angelfan
angelfan / dbconfig.rake
Created July 28, 2016 10:03 — forked from ka8725/dbconfig.rake
database.yml generator. Global Rake implementation
require 'yaml'
desc 'Generates database.yml, optional arguments: [adapter, user, password]'
task :dbconfig => 'database.yml'
file 'database.yml', [:adapter, :username, :password] do |t, args|
Dir.chdir('config')
args.with_defaults(:project_path => Dir.pwd)
DBConfigGenerator.new(t, args).generate
end
@angelfan
angelfan / si.rb
Created March 21, 2016 02:03 — forked from rasefon/si.rb
Similar Image Compare
require 'RMagick'
$scale_size = 256.0
$img_fn1 = ARGV[0]
$img_fn2 = ARGV[1]
$scale_size = ARGV[2].to_f if ARGV[2]
def calculate_threshold(img_fn)
dir_name = File.dirname(img_fn)