Skip to content

Instantly share code, notes, and snippets.

View chendo's full-sized avatar

chendo chendo

View GitHub Profile
@chendo
chendo / throw_exception_matcher.rb
Created December 20, 2011 04:36
A matcher based on RaiseException that also prints the backtrace of the original exception
# Copied from the rspec 1.3.2 RaiseException matcher
# Behaves exactly the same, except it also prints the backtrace of the original exception
module Spec
module Matchers
class ThrowException #:nodoc:
def initialize(expected_exception_or_message=Exception, expected_message=nil, &block)
@block = block
@actual_exception = nil
case expected_exception_or_message
class SiriProxy::Plugin::Twitter < SiriProxy::Plugin
# this watches when in the default context
listen_for /tweet (.*)/ do |data, tweetText|
show_rich_snippet do
image 'http://cl.ly/1l040J1A392n0M1n1g35/content' # this just makes things looks nice, but is obviously specific to my username
text tweetText
end
# this locks out other plugins until a confirmation or deny
confirm do
confirmed do
class SiriProxy::Plugin::Twitter < SiriProxy::Plugin
# this watches when in the default context
listen_for /tweet (.*)/ do |data, tweetText|
show_rich_snippet do
image 'http://cl.ly/1l040J1A392n0M1n1g35/content' # this just makes things looks nice, but is obviously specific to my username
text tweetText
end
# this locks out other plugins until a confirmation or deny
confirm do
class MelbourneMetroTrains < SiriProxy::Plugin
trigger /when is my next train/ do |data|
respond_with_next_train data
end
contextual_trigger :map_show, /map/ do |data|
show_map Map.new(@train_details.station.coordinates) # Automatic bounding box
available_transitions.clear
end
Have you ever left your terminal logged in, only to find when you came
back to it that a (supposed) friend had typed "rm -rf ~/*" and was
hovering over the keyboard with threats along the lines of "lend me a
fiver 'til Thursday, or I hit return"? Undoubtedly the person in
question would not have had the nerve to inflict such a trauma upon
you, and was doing it in jest. So you've probably never experienced the
worst of such disasters....
It was a quiet Wednesday afternoon. Wednesday, 1st October, 15:15
BST, to be precise, when Peter, an office-mate of mine, leaned away
class Car < ActiveRecord::Base
validates_length_of :name, :range => 2..10
validates_precense_of :name
has_many :purchases
has_many :owners, :through => :purchases
def normal_method
"blah blah blah"
end
A prescription calls for 50 g of a 10 % ointment. The pharmacist only
has a 5 % ointment and the pure ingredient available. How much of
the 5 % ointment and the pure ingredient are needed to compound
the prescription?
Let x be the amount of 5% ointment
Let y be the amount of 100% ointment
x * 5% ointment + y * 100% ointment = 50g of 10% ointment
# Run with this:
# $ curl "https://gist.github.com/raw/748530/5e74315dc6b6fe572f8a457536ad7eb17ad3f1e4/a.rb" > a.rb; while true; do clear; ruby a.rb | tee b.rb; sleep 0.3; mv -f b.rb a.rb; done
# Source: http://mamememo.blogspot.com/2010/09/qlobe.html
v=0000;eval$s=%q~d=%!^Lcf<LK8, _@7gj*LJ=c5nM)Tp1g0%Xv.,S[<>YoP
4ZojjV)O>qIH1/n[|2yE[>:ieC "%.#% :::##" 97N-A&Kj_K_><wS5rtWk@*a+Y5
yH?b[F^e7C/56j|pmRe+:)B "##% ::##########" O98(Zh)'Iof*nm.,$C5Nyt=
PPu01Avw^<IiQ=5$'D-y? "##: ###############" g6`YT+qLw9k^ch|K'),tc
6ygIL8xI#LNz3v}T=4W "# #. .####:#######" lL27FZ0ij)7TQCI)P7u
}RT5-iJbbG5P-DHB<. " ##### # :############" R,YvZ_rnv6ky-G+4U'
# Counts CSS selectors for a file
File.read('public/stylesheets/ranger2.css').gsub(%r{/\*.*?\*/}m, '').split(/\{.*?\}/m).map { |s| s.strip.split(/,/) }.flatten.size
# Daft Golf
# by chendo
# 484 bytes
s=%w(after better do ever faster harder hour is it make makes more never our over stronger than us work)
m="chavnohzy3a7uvnb4iw21ogt3xwazyiw6gqsoaihdjw36q8encnd1oxfpy2eomjfxfr9"
n="5vjlr1vcd8f7rdjb3c3zfk0kh6cjxc2l8dzvzk2hhfrwkg2n2ln04mpli1tq5gnfu7nvxc6dbk8yq9uxnfboimh5902mqtggizhhaakr2nk2xsh4qar5b8aypdocmeakqelscg11evw57i3ttep2ott0pqteclmae5sckhc"
def d(e,a)
t=e.to_i(36).to_s(2)
t[0]=''
t.scan(/.{5}/).map{|b|a[b.to_i(2)]}