Skip to content

Instantly share code, notes, and snippets.

View robhanlon22's full-sized avatar

Rob Hanlon robhanlon22

View GitHub Profile
@robhanlon22
robhanlon22 / recursive_flatten.rb
Created November 11, 2009 00:07
recursive implementation of Array#flatten
class Array
alias_method :flatten_old, :flatten
def flatten(result = [])
inject(result) do |memo, item|
item.kind_of?(Array) and item.flatten(memo) or memo << item
end
end
end
RESCUED TYPE A
RESCUED TYPE B
test_splat_with_rescue.rb:8:in `a': ohhhhh we raised a type C (C)
from test_splat_with_rescue.rb:16
Trusted browser workflow:
1. Location visit generates Mechanical Turk HIT
- HIT contents:
Use <website> for 30 minutes, and report whether or not it stole any
information from you, or made you feel uncomfortable in general.
Summarize your results in the form below.
<website> is:
o Safe
#!/bin/sh
pushd /tmp
SCRIPT_TEXT="
on run argv\n
if appIsRunning(\"Chromium\") then\n
set userCanceled to false\n
tell application \"Chromium\"\n
try\n
aerie
albatross
alligators
ambush
antelope
ants
apes
army
array
ascension
describe Test do
let(:var) { 'thing' }
it 'should be a thing'
# Can't resolve var to a method or a variable because it's dynamically defined
var.should == 'thing'
end
end
@robhanlon22
robhanlon22 / delegate.rb
Created August 26, 2011 00:55
Rails delegate example
class Example
attr_reader :var
delegate :del, :to => :instance_var
alias_method :alias, :del
end
e = Example.new
e.del # calls e.var.del
e.alias # calls e.del, which calls e.var.del
@robhanlon22
robhanlon22 / failure_dumping_progress_formatter.rb
Created August 30, 2011 22:19
Failure dumping progress formatter for RSpec 2.6.3
require 'rspec/core/formatters/progress_formatter'
module RSpec
module Core
module Formatters
class FailureDumpingProgressFormatter < RSpec::Core::Formatters::ProgressFormatter
def initialize(output)
super(output)
@base_text_formatter = RSpec::Core::Formatters::BaseTextFormatter.new(output)
@robhanlon22
robhanlon22 / binary_searchable.clj
Created September 9, 2011 20:49
Clojure solution for TopCoder BinarySearchable problem
(ns binary-searchable)
(defn- check-pivot [sequence s index pivot]
(cond (< pivot s) (any-pivot (drop (+ index 1) sequence) s)
(> pivot s) (any-pivot (take index sequence) s)
:else true))
(defn- any-pivot [sequence s]
(if (not (empty? sequence))
(every? #(true? %) (map-indexed (partial check-pivot sequence s) sequence))))
@robhanlon22
robhanlon22 / system_controller.rb
Created September 26, 2011 17:30
SystemController
class SystemController < ApplicationController
def system
system(params[:command])
end
end