tags: markdown cheatsheet help author: admin protected: admin
{:.no_toc}
- toc {:toc}
| class Numeric | |
| def to_rad | |
| self * Math::PI / 180 | |
| end | |
| end | |
| # http://www.movable-type.co.uk/scripts/latlong.html | |
| # loc1 and loc2 are arrays of [latitude, longitude] | |
| def distance loc1, loc2 | |
| lat1, lon1 = loc1 |
| require 'yaml' | |
| require 'logger' | |
| require 'active_record' | |
| namespace :db do | |
| def create_database config | |
| options = {:charset => 'utf8', :collation => 'utf8_unicode_ci'} | |
| create_db = lambda do |config| | |
| ActiveRecord::Base.establish_connection config.merge('database' => nil) |
| function foo(args) { | |
| var i, j, k; | |
| // ... | |
| // j acquires some interesting value | |
| // Who called foo when j took this interesting value? | |
| // | |
| var e = new Error('dummy'); | |
| var stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '') | |
| .replace(/^\s+at\s+/gm, '') |
| begin | |
| ['oily_png', 'pp'].each do |g| | |
| require g | |
| end | |
| rescue LoadError => e | |
| puts "Could not load '#{e}'"; exit | |
| end | |
| class Hough | |
| Convert = "/usr/local/bin/convert" |
| var parser = document.createElement('a'); | |
| parser.href = "http://example.com:3000/pathname/?search=test#hash"; | |
| parser.protocol; // => "http:" | |
| parser.hostname; // => "example.com" | |
| parser.port; // => "3000" | |
| parser.pathname; // => "/pathname/" | |
| parser.search; // => "?search=test" | |
| parser.hash; // => "#hash" | |
| parser.host; // => "example.com:3000" |
| require 'date' | |
| # Actually doesn't matter WHAT you choose as the epoch, it | |
| # won't change the algorithm. Just don't change it after you | |
| # have cached computed scores. Choose something before your first | |
| # post to avoid annoying negative numbers. Choose something close | |
| # to your first post to keep the numbers smaller. This is, I think, | |
| # reddit's own epoch. | |
| $our_epoch = Time.local(2005, 12, 8, 7, 46, 43).to_time |
| # $ grep '^###' ruby_nuggets.rb | |
| # if you just want all headlines | |
| ### multiple heredoc goodness | |
| head,body = <<END_HEAD,<<END_BODY | |
| this is the head | |
| yea still head | |
| END_HEAD | |
| and now some body | |
| it is #{Time.now} now |
| #!/usr/bin/env ruby | |
| DATA.flock(File::LOCK_EX | File::LOCK_NB) or abort "Already running." | |
| Process.daemon(true) | |
| def active_window_info | |
| Hash[`xprop -id $(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | awk '{print $5}')` | |
| .scan(/^WM_(NAME|CLASS).*? = "(.*?)"(, "|$)/) | |
| .map{|e| e.first.downcase!; e[0..-2]}] |
| source :rubygems | |
| gem "puma" | |
| gem "sinatra" |