Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'rubygems'
require 'growl'
require 'zendesk-api'
require 'tinder'
@z = Zendesk::Main.new("", "", "", :format => "json")
def count_for_rule(rule)
ticket_count = 0
@toothrot
toothrot / weird.rb
Created June 15, 2010 22:53
if it's seen by the compiler, it's not a NameError
hey = nil
yo = "foo"
baz = 3 if false
puts hey.inspect
puts yo.inspect
puts baz.inspect # Nil!!
puts spaz.inspect # Name Error
# via jaknowlden:
irb(main):001:0> (k, v), *rest = [[1,2], [3,4], [5,6]]
=> [[1, 2], [3, 4], [5, 6]]
irb(main):002:0> k
=> 1
irb(main):003:0> v
=> 2
irb(main):004:0> rest
=> [[3, 4], [5, 6]]
@toothrot
toothrot / what_is_self.rb
Created July 2, 2010 17:09
blocks are funky.
outside = "foo"
classy = Class.new do
define_method(:get_thing) do
outside
end
def get_thing_with_def
outside
end
@toothrot
toothrot / eigenclass_your_face.rb
Created July 9, 2010 21:44
a modular way to smack up eigenclass
module Farts
def farts
"pfft"
end
end
hey = "yo"
hey.farts # NoMethodError: undefined method `farts' for "yo":String
@toothrot
toothrot / output.txt
Created July 9, 2010 21:45
how setups get run in Riot
context setups
+ asserts should only run the setup once
+ asserts even with multiple assertions
context setups that are nested
+ asserts gets run again
+ asserts only once per nesting, even with multiple assertions
4 passes, 0 failures, 0 errors in 0.000148 seconds
require 'rubygems'
require 'riot'
context "Something" do
setup do
D = 8
end
asserts("something") { 8==D }
asserts("something else") { 8===D }
@toothrot
toothrot / riot_example.rb
Created July 20, 2010 21:19 — forked from gus/riot_example.rb
dick jokes
require 'rubygems'
require 'riot'
context "Something" do
setup do
D = 8
end
asserts("big") { 8==D }
asserts("bigger") { 8===D }
@toothrot
toothrot / ruby_shuffle.c
Created July 21, 2010 03:19
shuffling arrays for 1.8.6
static VALUE
rb_ary_shuffle_bang(ary)
VALUE ary;
{
long i = RARRAY(ary)->len;
rb_ary_modify(ary);
while (i) {
long j = rb_genrand_real()*i;
VALUE tmp = RARRAY(ary)->ptr[--i];
@toothrot
toothrot / does_sort_preserve_order.rb
Created July 22, 2010 17:20
does_sort_preserve_order
ary = [
{:sort_me => 1, :expected_order => 1},
{:sort_me => 2, :expected_order => 7},
{:sort_me => 2, :expected_order => 8},
{:sort_me => 1, :expected_order => 2},
{:sort_me => 1, :expected_order => 3},
{:sort_me => 1, :expected_order => 4},
{:sort_me => 1, :expected_order => 5},
{:sort_me => 1, :expected_order => 6},
].sort! { |a,b| a[:sort_me] <=> b[:sort_me] }