Skip to content

Instantly share code, notes, and snippets.

@jordelver
jordelver / input.txt
Last active September 29, 2015 19:17
pear
d
c
b
a
banana
c
a
b
apple
@jordelver
jordelver / spinner.rb
Created April 21, 2012 22:24
Command line progress spinner
# Command line progress spinner
# As seen here: http://www.youtube.com/watch?v=W-4vEZp67b0
require 'thread'
require 'open-uri'
Thread.abort_on_exception = true
class Spinner
GLYPHS = ['|', '/', '-', '\\', '|', '/', '-', '\\']
@jordelver
jordelver / gist:2590504
Created May 3, 2012 23:50
Custom must_be_json minitest assertion / expectation for use with rack-test
module MiniTest::Assertions
def assert_content_type_is_json(response)
content_type = response.headers['Content-Type']
assert_equal 'application/json;charset=utf-8', content_type
end
end
module MiniTest::Expectations
infect_an_assertion :assert_content_type_is_json, :must_be_json, :unary
end
@jordelver
jordelver / a.rb
Created May 10, 2012 07:22 — forked from ahoward/a.rb
style is the only thing.
# shitty
attributes[:name] = options[:name] unless options[:name].blank?
attributes[:first_name] = options[:first_name] unless options[:first_name].blank?
attributes[:last_name] = options[:last_name] unless options[:last_name].blank?
attributes[:linkedin_id] = options[:linkedin_id] unless options[:linkedin_id].blank?
attributes[:company] = options[:company] unless options[:company].blank?
attributes[:company_id] = options[:company_id] unless options[:company_id].blank?
attributes[:linkedin_picture_url] = options[:linkedin_picture_url] unless options[:linkedin_picture_url].blank?
@jordelver
jordelver / domains.txt
Created June 1, 2012 15:16
Quick 'n' dirty bulk domain add to Heroku
example.com
example.org
example.net
@jordelver
jordelver / gist:2852899
Created June 1, 2012 15:18
Export mongo collection as a CSV file
mongoexport -d <database> -c <collection> -f field1,field2,field3 --csv > out.csv
@jordelver
jordelver / gist:2882852
Created June 6, 2012 15:52
Lookup Tables With Lambdas
# Adapted from Lookup Tables With Lambdas
# http://www.naildrivin5.com/blog/2012/05/16/lookup-tables-with-lambdas.html
# Lookup with lambdas so we can do a database call or something
CARD_TYPE_COUNTRIES = {
'discover' => lambda { ['US'] },
'maestro' => lambda { ['UK'] },
'amex' => lambda { Array.new(1, 'NOWHERE!') }, # Hit database
'default' => lambda { ['US','UK','ZA'] }
@jordelver
jordelver / gist:2889547
Created June 7, 2012 15:44
Calculate the last day of the month
# From http://rubyquicktips.com/post/350625885/calculate-the-last-day-of-the-month
>> Date.civil(2010, 02, -1)
=> Sun, 28 Feb 2010
>> Date.civil(2010, -1, -5)
=> Mon, 27 Dec 2010
@jordelver
jordelver / colortest
Created June 7, 2012 22:21
Output all 256 possible terminal colours
#!/usr/bin/perl
# by entheon, do whatever the hell you want with this file
print "\n";
print "**************************\n";
print "*XTERM 256Color Test Chart\n";
print "**************************\n";
print "* 16 = black\n";
print "* 255 = white\n";
@jordelver
jordelver / gist:2896488
Created June 8, 2012 16:09
Ignore join, quit and part messages in irssi
/ignore * joins quits parts