Skip to content

Instantly share code, notes, and snippets.

View kornypoet's full-sized avatar

Travis Dempsey kornypoet

View GitHub Profile
require 'rspec'
require './search_scraper'
require 'em-synchrony'
def tmp_dir() File.join(File.dirname(__FILE__), 'tmp') ; end
def ripd_dir() File.join(tmp_dir, 'social.network.twitter') ; end
def cfg_hash
{
:namespace => "social.network.twitter",
@kornypoet
kornypoet / gist:1689638
Created January 27, 2012 16:31
Rspec #initialize behavior
# Arbitrary class illustrating desired implementation of init options for a class
# How do I spec this behavior? especially if there are many attrs and conditions?
class Foo
attr_accessor :bar
def initialize(bar)
# call an exiting method unless some condition is met by the variable passed in. Foo is an outward-facing class
log_and_fail unless bar
@kornypoet
kornypoet / gist:2346656
Created April 9, 2012 21:26
ElasticsearchStorage() examples
--
-- If your data looks like this:
--
-- {"foo":1,"bar":1}
-- {"foo":2,"bar":2}
-- {"foo":3,"bar":3}
--
-- Then write your store function this way; it will respect nested hashes and arrays if they are JSONed properly
--
register wonderdog-1.0-SNAPSHOT.jar;
# The way a wukong script is written regularly:
require 'wukong'
class WukongToFlume < Wukong::Streamer::LineStreamer
def process(body, *args)
# take input, do some processing
processed = body.to_s.reverse
yield [processed]
@kornypoet
kornypoet / rspec_examples.rb
Created June 22, 2012 18:24
RSpec Examples
#run me with `rspec -fd --color rspec_examples.rb`
require 'rspec'
# The class we want to test
class YoMama
attr_accessor :makeup
def fat?() true ; end
require 'gorillib/model'
class Joke
include Gorillib::Model
field :is_so_fat, String, :default => "When she sits around the house, she sits *AROUND* the house"
field :wears, String
end
@kornypoet
kornypoet / translator.rb
Created September 21, 2012 15:53
Sample Wukong flow
Wukong.processor(:ogify) do
def process(record)
emit(record.gsub(/(a\w|e\w|i\w|o\w|u\w)/, 'og'))
end
end
Wukong.processor(:poify) do
@kornypoet
kornypoet / field_usage.rb
Last active December 15, 2015 10:38
Gorillib::Model #field usage
require 'gorillib/model'
# In this first example, we have a User that will have a first and last name, and a synthetic secret_id.
# The secret_id could be provided, but if it is not, we want to supply a default based on the names.
# We need access to the other fields being received, so we used a delayed default:
class User
include Gorillib::Model
field :first_name, String
field :last_name, String
@kornypoet
kornypoet / S3Spout.java
Last active December 19, 2015 15:48
Suggested setup for an S3 trident spout
class S3Spout {
class S3Client { // Travis will write
// Make using S3 easy like a boss
}
private S3Client _client; // Travis will write
@kornypoet
kornypoet / diff.rb
Last active August 29, 2015 13:56
Dumb attribute diff
#!/usr/bin/env ruby
require 'json'
class DiffOMatic
attr_reader :info
def name(*_) ; end
def description(*_) ; end