Skip to content

Instantly share code, notes, and snippets.

View peterhellberg's full-sized avatar
💙
Coding Go

Peter Hellberg peterhellberg

💙
Coding Go
View GitHub Profile
@peterhellberg
peterhellberg / my_helpers.rb
Created May 7, 2012 13:33
Testing Sinatra helpers (in isolation) that depend on the params hash being present
# encoding: UTF-8
module MyHelpers
def foo
"#{params[:bar]}"
end
end
@peterhellberg
peterhellberg / tomtelizer_view_controller.rb
Created June 4, 2012 08:38
Main view for the Tomtelizer written in RubyMotion
# Main controller for the Tomtelizer
#
class TomtelizerViewController < UIViewController
# Load the view
#
def loadView
self.view = UIImageView.alloc.init
@debug_face = false
end
@peterhellberg
peterhellberg / slot_length.rb
Created June 14, 2012 11:36
Slot length calculation
# encoding: utf-8
require 'time'
class SlotLength
# Contains the number of seconds in the slot
attr_reader :seconds
attr_reader :ordered_seconds
# Contains the string for the slot length
describe "save_current_checksums" do
it "saves the current checksums to redis" do
checksums = { foo: 'bar', baz: 'qux'}
REDIS.keys.must_be_empty
fingerprint.stub(:field_checksums, checksums) do
fingerprint.save_current_checksums
REDIS.get('vision:episode:123456:checksum').
@peterhellberg
peterhellberg / yajl_partials.rb
Created June 29, 2012 14:11
Yajl partials in Sinatra (using Tilt)
# An extremely hackish solution
module Sinatra
module Templates
def yajl_partial(template, locals={})
Yajl::Parser.parse yajl(template, {}, locals)
end
end
end
# I’ll add a better solution when I figure something out :)
@peterhellberg
peterhellberg / gist:3209893
Created July 30, 2012 20:29
CLI for the terminal-notifier gem
#!/usr/bin/env ruby
require 'optparse'
require 'terminal-notifier'
options = {}
begin
parser = OptionParser.new do |opts|
opts.banner = "Usage: terminal-notifier MESSAGE [options]"
@peterhellberg
peterhellberg / aliases_spec.rb
Created August 3, 2012 12:56
Shorter way to retrieve aliases.
# encoding: utf-8
require 'minitest/spec'
require 'minitest/pride'
require 'minitest/autorun'
def long(shortcut)
case shortcut
when 'protos','proto','xorgprotos','xorg1','x1','1'
'xorg_protos'
@peterhellberg
peterhellberg / twitter_friends_on_alpha.rb
Created August 17, 2012 11:43
Find your Twitter friends on Alpha (app.net)
require 'net/http'
require 'open-uri'
require 'json'
screen_name = ARGV[0]
if screen_name.nil?
puts "ruby twitter_friends_on_alpha.rb twitter_username"
exit
end
@peterhellberg
peterhellberg / adn2rfc.rb
Created August 20, 2012 23:15
Find RFCs based on Alpha (app.net) user ids.
require 'net/http'
def adn2rfc(user)
abort "You need to specify user on app.net" if user.nil?
http = Net::HTTP.new('alpha.app.net', 443)
http.use_ssl = true
res = http.request_get("/#{user}")
@peterhellberg
peterhellberg / geoip_service.rb
Created September 3, 2012 15:02
Simple GeoIP service class using freegeoip.net and the Ruby Standard Library
require 'net/http'
require 'ostruct'
require 'json'
class GeoipService
def initialize(http = nil)
@http = http || Net::HTTP.new('freegeoip.net')
end
def call(host)