Skip to content

Instantly share code, notes, and snippets.

View pachacamac's full-sized avatar
🌶️
Mmmmhmmmm

Marc pachacamac

🌶️
Mmmmhmmmm
  • Hacker/Founder
  • Germany, Berlin
View GitHub Profile
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
@wbailey
wbailey / databases.rake
Created February 11, 2011 08:58
ActiveRecord migrations outside of Rails
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)
@jay3sh
jay3sh / stack-trace-without-exception.js
Created August 20, 2011 10:33
print stack trace anywhere
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, '')
@rondale-sc
rondale-sc / ruby-hough.rb
Created September 21, 2011 23:05
The hough transform in ruby. Only looks for straight black lines.
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"
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
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"
@jrochkind
jrochkind / gist:2636355
Created May 8, 2012 15:31
reddit 'hot' algorithm, in ruby, with typo fixed
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
@pachacamac
pachacamac / ruby_nuggets.rb
Created October 21, 2012 19:36
Some very nice tricks and helpful magic in Ruby
# $ 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
@pachacamac
pachacamac / winspy.rb
Created October 21, 2012 20:27
Log what programs you're using
#!/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]}]

tags: markdown cheatsheet help author: admin protected: admin

Markdown Cheatsheet

{:.no_toc}

  • toc {:toc}
@ctalkington
ctalkington / Gemfile
Last active May 16, 2023 20:19
Nginx, Sinatra, and Puma.
source :rubygems
gem "puma"
gem "sinatra"