Skip to content

Instantly share code, notes, and snippets.

View cadwallion's full-sized avatar
⚒️
Building all the things

Andrew Nordman cadwallion

⚒️
Building all the things
View GitHub Profile
require 'work_queue'
wq = WorkQueue.new(5)
i = 1
%w{foo bar baz bun}.each do |file|
i2 = i
wq.enqueue_b do
#move file to another directory
ImportFile.new(file, i2).run
end
@cadwallion
cadwallion / gist:2320542
Created April 6, 2012 14:52
Querystring.stringify problem with nested datas.
var Querystring = require('querystring');
var data = {
person: {
first_name: 'Test',
last_name: 'Person'
}
}
// returns 'person='
@cadwallion
cadwallion / array.rb
Created April 6, 2012 04:13
My solution to Array() shenanigans
class Array
def self.i_want_a_goddamn_array thing
if thing.kind_of? Hash
[thing]
else
Array(thing)
end
end
end
@cadwallion
cadwallion / gist:2316695
Created April 6, 2012 03:55
Array() shenanigans...
>> Array([])
=> []
>> Array(nil)
=> []
>> Array([{foo: 'bar'}])
=> [{:foo=>"bar"}]
>> Array([{foo: 'bar'}, {bar: 'baz'}])
=> [{:foo=>"bar"}, {:bar=>"baz"}]
>> Array({foo: 'bar'})
=> [[:foo, "bar"]]
@cadwallion
cadwallion / tree_solver.rb
Created March 28, 2012 21:47
Programmatic Double-Elimination Bracket Generation
# This takes a bracket size and generates the loser's bracket side of a double-elimination tournament
class TreeSolver
attr_reader :size
def initialize options = {}
@size = options[:size] || 32
@levels = 0
calculate_levels
@starting_point = options[:starting_point] || 2
end
@cadwallion
cadwallion / output.rb
Created March 22, 2012 14:54
What kind of price is 0.0800000
>> recipe = Brewscribe::Recipe.new File.read './spec/support/recipe.bsmx' ; nil
=> nil
>> recipe.parse_ingredients ; nil
=> nil
>> recipe.ingredients.grains[0]
=> #<Brewscribe::Grain:0x007fcacb859ba0 @original_data={:last_modified=>"1978-12-31", :name=>"Pale Malt (2 Row) US", :origin=>"US", :supplier=>nil, :type=>"0", :in_recipe=>"1", :inventory=>"0.0000000", :amount=>"32.0000000", :color=>"2.0000000", :yield=>"79.0000000", :late_extract=>"0.0000000", :percent=>"12.1212121", :order=>"1", :coarse_fine_diff=>"1.5000000", :moisture=>"4.0000000", :diastatic_power=>"140.0000000", :protein=>"12.3000000", :ibu_gal_per_lb=>"0.0000000", :add_after_boil=>"0", :recommend_mash=>"1", :max_in_batch=>"100.0000000", :notes=>"Base malt for all beer styles", :boil_time=>"60.0000000", :price=>"0.0800000", :convert_grain=>"Pale Liquid Extract"}, @last_modified="1978-12-31", @name="Pale Malt (2 Row) US", @origin="US", @supplier=nil, @type="0", @in_recipe="1", @inventory="0.0000000", @amount="32.0000000", @color="2.0000000", @yiel
@cadwallion
cadwallion / gist:2051865
Created March 16, 2012 19:02
Nokogiri::XML to Object properties
require 'ostruct'
require 'nokogiri'
module Brewscribe
class Recipe
attr_reader :raw_data, :hash
def initialize raw_data
@raw_data = raw_data
parse_raw_data
@cadwallion
cadwallion / gist:2041073
Created March 15, 2012 01:38
YARDoc *args option documentation
# Rank an array of members in the leaderboard.
#
# @overload rank_members([[member, score], ...])
# Rank an array of members in the leaderboard.
# @param [String] member the member to score
# @param [Fixnum] score the score of member
def rank_members(*members_and_scores)
rank_members_in(@leaderboard_name, *members_and_scores)
end
@cadwallion
cadwallion / client.rb
Created March 13, 2012 20:02
Bidirectional Ruby DNode
require 'dnode'
Client = {
temp: ->(cb) {
tempC = (20.0 + rand() * 10 - 5).round
cb.call(tempC)
}
}
DNode.new(Client).connect(8188) do |remote, conn|
remote.f2 ->(degF) {
class SeqAct_TMTSetCoinsNeeded extends SequenceAction;
var() int NumCoins;
DefaultProperties
{
ObjName="Set Coins Needed"
ObjCategory="Tomato"
HandlerName="SetCoinsNeeded"
NumCoins=0