Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am gary-rafferty on github.
  • I am garyrafferty (https://keybase.io/garyrafferty) on keybase.
  • I have a public key ASC_lZnNF4jt_GkZfKkoNxF4zDHiDF1Yy-Tp4moKzwf9Owo

To claim this, I am signing this object:

def zerosum(arr,size=4)
arr.permutation(size).to_a.each do |a|
if a.inject(:+) == 0
p a.inspect
break
end
end
end
zerosum([2,3,5,6,7,8,9,1,2,3,-1,-11,44,-1,0,1,1],5)
@gary-rafferty
gary-rafferty / when_available.js
Created January 7, 2013 09:48
Javascript function that waits for an object to be available, and then invokes with callback
function whenAvailable(name, callback) {
var interval = 10;
window.setTimeout(function() {
if(window[name]) {
callback(window[name]);
} else {
setTimeout(arguments.callee, interval);
}
}, interval);
}
require 'exceptional'
require 'yaml'
Exceptional::Config.load("config/exceptional.yml")
@hash = {}
1.upto(50000) do |i|
@hash[i] = "email#{i}@domain.com"
end
@gary-rafferty
gary-rafferty / app.rb
Created May 9, 2012 20:05
Airbrake test
require 'sinatra/base'
require 'airbrake'
Airbrake.configure do |config|
config.api_key = 'YOUR-API-KEY-HERE'
config.host = 'api.airbrake.io'
end
class MyApp < Sinatra::Base
use Airbrake::Rack
@gary-rafferty
gary-rafferty / eyebrowser.jquery.js
Created January 27, 2012 13:15
Quick jquery plugin to check navigator.userAgent string
(function($){
function getInternetExplorerVersion() {
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer') {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
@gary-rafferty
gary-rafferty / gist:1646779
Created January 20, 2012 11:20
Dirty dart screen scrape
BASE_URL = "http://www.irishrail.ie/your_journey/ajax/ajaxRefreshResults.asp?station="
trains = []
station = URI.escape(params[:station])
doc = Nokogiri::HTML(open("#{BASE_URL}#{station}"))
doc.search('tr').each {|t| trains << t if t.content =~ /DART/}
@gary-rafferty
gary-rafferty / Rakefile.rb
Created January 9, 2012 19:56
Rake task to show my Sinatra routes (probably not reusable)
require './application'
namespace :routes do
task :show do
endpoints = {}
if Sinatra::Application.descendants.any?
#Classic application structure
applications = Sinatra::Application.descendants
applications.each do |app|
module Devise
module Orm
module MongoMapper
module Hook
def devise_modules_hook!
extend Schema
include Compatibility
yield
return unless Devise.apply_schema
devise_modules.each { |m| send(m) if respond_to?(m, true) }