Skip to content

Instantly share code, notes, and snippets.

@Andrzej
Andrzej / Country to continent conversion
Created October 11, 2010 21:57
Utility to convert country name into continent name
AFRICA=[
"Algeria",
"Angola",
"Benin",
"Botswana",
"Burkina",
"Burkina Faso",
"Burundi",
"Cameroon",
"Cape Verde",
@Andrzej
Andrzej / bson2sql.rb
Created October 10, 2011 19:16
Convert BSON file into SQL, useful for fast copy data from MongoDB to MySQL (mongodump => bson2sql => import to mysql)
require "bson"
def make_insert(table_name, bson)
columns = ["id",*bson["value"].keys] * ", "
values = ["'#{bson["_id"]}'",*bson["value"].values.map{|value| value.is_a?(Numeric) ? value : "'#{value}'"}] * ", "
return "insert into #{table_name} (#{columns}) values (#{values});"
end
file_name = ARGV.first
file=File.new(file_name)
@Andrzej
Andrzej / gist:1318027
Created October 26, 2011 22:02
Sort file by regex
r=/".+"/; puts File.readlines("file.txt").sort{|a,b| a[r] <=> b[r]}
binding=Struct.new(:key) do
def get_binding
binding
end
end.new("value").get_binding
data = YAML::load(ERB.new(File.read("file.yml")).result(binding))
@Andrzej
Andrzej / Gemfile
Created August 23, 2012 01:12
Gemfile for puppet-dashboard
source 'http://rubygems.org'
gem 'rails','2.3.12'
gem 'bundler','1.1.5'
gem 'json','1.7.5'
gem 'rdoc', '3.12'
gem 'mysql2', '0.2.19b4'
gem 'activerecord-mysql2-adapter'
gem 'haml'
gem 'sass'