Skip to content

Instantly share code, notes, and snippets.

View georgkreimer's full-sized avatar
☠️
Hack the planet!

Georg Kreimer georgkreimer

☠️
Hack the planet!
View GitHub Profile
@georgkreimer
georgkreimer / gist:537794
Created August 19, 2010 12:44
pretty print json in ruby
require 'json'
my_json = { :array => [1, 2, 3, { :sample => "hash"} ], :foo => "bar" }
puts JSON.pretty_generate(my_json)
Which gets you...
{
"array": [
1,
2,
3,
@georgkreimer
georgkreimer / point_in_polygon.rb
Created September 17, 2010 21:34
tests if a point is inside a polygon (ported code from c example)
polygon = [{:x=>0,:y=>0},{:x=>4,:y=>0},{:x=>2,:y=>2},{:x=>0,:y=>4}]
point0 = {:x=>0,:y=>0}
point1 = {:x=>0.00000000001,:y=>0.00000000001}
point2 = {:x=>1,:y=>1}
point3 = {:x=>2,:y=>2}
point4 = {:x=>1.99999999999,:y=>1.99999999999}
# http://www.visibone.com/inpoly/
# http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
#
@georgkreimer
georgkreimer / hash_intersection.rb
Created November 19, 2010 14:07
Hash intersection in Ruby
first = {"a" => 4, "b" => 1, "c" => 3, "g" => 201, "h" => 501}
second = {"d" => 19, "e" => 18, "c" => 17, "g" => 201, "h" => 501}
keys_intersection = first.keys & second.keys
merged = first.dup.update(second)
intersection = {}
keys_intersection.each do |k|
intersection[k]=merged[k] unless first[k] != second[k]
end
@georgkreimer
georgkreimer / gist:727710
Created December 3, 2010 23:19
enable AFP from commandline
edit "/etc/hostconfig"
change "AFPSERVER=-NO-" to "AFPSERVER=-YES-"
run "sudo SystemStarter start 'Apple File Service'"
@georgkreimer
georgkreimer / install_homebrew.rb
Created December 9, 2010 22:55
Installs Homebrew to /usr/local so you don't need sudo to `brew install` (powerpc branch)
#!/usr/bin/ruby
#
# This script installs to /usr/local only. To install elsewhere you can just
# untar https://github.com/sceaga/homebrew/tarball/powerpc anywhere you like.
#
#
# 30th March 2010:
# Added a check to make sure user is in the staff group. This was a problem
# for me, and I think it was due to me migrating my account over several
# versions of OS X. I cannot verify that for sure, and it was tested on
this:
<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsdl="http://v1.example.com">
<env:Body>
<wsdl:GetUser>
<firstName>The</firstName>
<lastName>Hoff</lastName>
<FAME>Knight Rider</FAME>
# extensions
# …
module SOAPArray
def to_soap_array(item_name = "messageId")
result=Array.new
self.each do |val|
result.push({item_name => val.to_i})
end
result
end
@georgkreimer
georgkreimer / ruby-1.9-tips.rb
Created October 9, 2011 18:45 — forked from igrigorik/ruby-1.9-tips.rb
Ruby 1.9 features, tips & tricks you may not know about...
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
@georgkreimer
georgkreimer / gist:1276091
Created October 10, 2011 18:23 — forked from javan/gist:1168475
Fix iPhone home button
Found this tip in comment here: http://www.tipb.com/2011/01/04/tipb-bug-home-button-working-iphone/
1.) Open any application
2.) Press and hold the power button until the slide to shutdown swipe bar appears.
3.) Release Power button
4.) Press and hold Home button Lightly
until screen returns to icon screen
class MappedHash < Hash
attr_writer :mappings
def mappings
@mappings || {}
end
def [](name)
super || super(mappings[name])
end