Skip to content

Instantly share code, notes, and snippets.

View trobrock's full-sized avatar

Trae Robrock trobrock

View GitHub Profile
@trobrock
trobrock / rebuild_server.sh
Created December 24, 2010 21:28
simple script that helps when working on a chef recipe using rackspace
NODE=$1;
SERVER=$2;
knife cookbook upload -a;
ID=`knife rackspace server list | grep $SERVER | awk '{print $1}'`;
knife rackspace server delete $ID;
knife node delete -y $NODE;
knife client delete -y $NODE;
describe CardsController, "for a logged in user" do
before(:each) do
@cardset = Factory(:cardset)
profile = @cardset.profile
controller.stubs(:require_user).returns(true)
controller.stubs(:current_user).returns(profile)
end
context "and created card" do
before(:each) do
@trobrock
trobrock / node.rb
Created June 15, 2010 14:27
Check to see if a node is part of a binary search tree
class Node
attr_accessor :left, :right, :value
def is_bst?(min = -1.0/0, max = 1.0/0)
# exit if the siblings are not of the Node type or Nil and have valid value
return false unless is_valid?
return false unless left.nil? or left.is_bst?(min, value)
return false unless right.nil? or right.is_bst?(value, max)
value > min and value < max
@trobrock
trobrock / rails-word_cloud-helper.rb
Created May 31, 2010 20:07
A helper for rails to create a tag cloud out a string of words (space delimited). Adapted the idea from here: http://snippets.dzone.com/posts/show/6027
def word_cloud(words)
wordcount = {}
words.split(/\s/).each do |word|
word.downcase!
if word.strip.size > 0
wordcount[word.strip] = (wordcount.key?(word.strip)) ? (wordcount[word.strip] + 1) : 0
end
end
s = []
@trobrock
trobrock / SMS_Short_Code_Process.php
Created May 17, 2010 13:52
Will parse the Twitter firehose for a hash tag, and then emulate the process of an sms short code voting system using Twitter as the backend. Built overnight at the Twitter Chirp conference
<?php
require('phirehose_0.2.4/lib/Phirehose.php');
class SmsShortCode extends Phirehose {
/**
* Enqueue each status
*
* @param string $status
@trobrock
trobrock / Periodical Problems
Created July 7, 2009 19:30
Trouble getting the MooTools periodical function working, now working
// I am getting the error:
// 'this.clock = this.iterateClock(current, future).periodical(1000, this); is undefined'
// After it display the days left once, it throws the error
//
// This is now the working version
var Main = new Class({
Implements : [Options],
options : {