Skip to content

Instantly share code, notes, and snippets.

View railscard's full-sized avatar

Max railscard

  • Almere, the Netherlands
View GitHub Profile
require 'open3'
require 'net/http'
require 'json'
class String
def green; "\e[32m#{self}\e[0m" end
def brown; "\e[33m#{self}\e[0m" end
def blue; "\e[34m#{self}\e[0m" end
def gray; "\e[37m#{self}\e[0m" end
def magenta; "\e[35m#{self}\e[0m" end
module UnicodeStringUtils
def downcase(input)
input.to_s.mb_chars.downcase
end
def upcase(input)
input.to_s.mb_chars.downcase
end
end
imgColorAt := img.At(x, y)
red, green, blue, alpha := imgColorAt.RGBA()
rgbaColor := color.RGBA{uint8(red >> 8), uint8(green >> 8), uint8(blue >> 8), uint8(alpha >> 8)}
fmt.Println(imgColorAt) // Will print {255 255 255 0}
fmt.Println(rgbaColor) // Will be {0 0 0 0}
@railscard
railscard / so.rb
Created September 19, 2012 05:20
so.rb
module UserMacros
def make_user_and_login(user = nil)
user ||= FactoryGirl.create(:user)
visit new_user_session_path
page.should have_selector('title', :text => 'Login')
fill_in('Email', :with => user.email)
fill_in('Password', :with => user.password)
click_button('Login')
page.should have_selector('title', :text => 'Home')
end
@railscard
railscard / bsonexport.sh
Created September 11, 2012 17:29
Export bson data to mongodb
#!/bin/bash
#
# Converts all files in current directory
# from bson format to json and import
# them to mongodb collection.
#
# Usage:
# Put this script in bson files directory,
# run chmod +x bsonexport.sh
#
@railscard
railscard / anemone_proxy.rb
Created September 7, 2012 11:50
Anemone proxy example
require 'anemone'
Anemone.crawl("http://stackoverflow.com/", {:proxy_host => 'proxy.xyz.com', :proxy_port => '9999'}) do |anemone|
anemone.on_every_page do |page|
puts page.url
end
end