Skip to content

Instantly share code, notes, and snippets.

View NateBarnes's full-sized avatar
:shipit:
Moar Tests!

Nathaniel Barnes NateBarnes

:shipit:
Moar Tests!
View GitHub Profile
def insights_query params
@insights_query ||= {}
@insights_query[params.to_s] ||= graph.insights_query(params)
end
require 'bundler'
Bundler.require
require 'socket'
require 'redis'
a = TCPServer.new('', MY_SECRET_PORT_NUMBER) # '' means to bind to "all interfaces", same as nil or '0.0.0.0'
c = LIFX::Client.lan
c.discover
require 'bundler'
Bundler.require
require 'socket'
require 'redis'
a = TCPServer.new('', MY_SECRET_PORT_NUMBER) # '' means to bind to "all interfaces", same as nil or '0.0.0.0'
c = LIFX::Client.lan
c.discover
require 'bundler'
Bundler.require
require 'socket'
def c
@c ||= LIFX::Client.lan
end
def lightcontrol(command)
print command
require 'bundler'
Bundler.require
require 'socket'
attr_accessor :c
def lightcontrol(command)
print command
case command
when "kitchen_on"
class Hash
alias :working_brackets :[]
def [] key
if rand(10) % 5 == 0
do_evil
else
working_brackets key
end
end
@NateBarnes
NateBarnes / gist:5401122
Last active December 16, 2015 07:48
Just a quick example of parallelizing network requests to improve SoA API call times to multiple endpoints using future methods.
require "httparty"
require "celluloid"
start_time = Time.now
results = []
100.times do
results << HTTParty.get("http://www.reddit.com/r/ruby")
end
end_time = Time.now
puts "Procedural: #{end_time-start_time}"
@NateBarnes
NateBarnes / gist:3671801
Created September 8, 2012 04:33
Recursive Arrays
foo = []
foo << foo
foo == foo.first #=> true
foo #=> [[...]]
@NateBarnes
NateBarnes / benchmark.rb
Created June 27, 2012 06:18
Postgres vs Redis Object Storage Benchmarks
require "pg"
require "redis"
words = File.read("/usr/share/dict/words").split "\n"
pgconn = PGconn.open :dbname => "test_hstore", :port => 5433, :user => "test_user", :password => "changeme"
redis = Redis.new
reps = [1,10,100,1000,10000]
pg_inserts = []
pg_selects = []
redis_sets = []
@NateBarnes
NateBarnes / gist:1158636
Created August 20, 2011 03:59
Example options methods for polymorphic options model
module ActiveRecordAddons
def has_options
class_eval do
has_many :raw_options, :as => :owner, :class_name => "Option"
def options
opts = {}
raw_options.each { |opt| opts[opt.key.to_sym] = converter(opt.value) }
opts
end