This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def insights_query params | |
| @insights_query ||= {} | |
| @insights_query[params.to_s] ||= graph.insights_query(params) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'bundler' | |
| Bundler.require | |
| require 'socket' | |
| def c | |
| @c ||= LIFX::Client.lan | |
| end | |
| def lightcontrol(command) | |
| print command |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'bundler' | |
| Bundler.require | |
| require 'socket' | |
| attr_accessor :c | |
| def lightcontrol(command) | |
| print command | |
| case command | |
| when "kitchen_on" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Hash | |
| alias :working_brackets :[] | |
| def [] key | |
| if rand(10) % 5 == 0 | |
| do_evil | |
| else | |
| working_brackets key | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| foo = [] | |
| foo << foo | |
| foo == foo.first #=> true | |
| foo #=> [[...]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |