Skip to content

Instantly share code, notes, and snippets.

View Narnach's full-sized avatar

Wes Oldenbeuving Narnach

View GitHub Profile
@Narnach
Narnach / get_mcc_mnc.rb
Last active August 29, 2015 14:26 — forked from choonkeat/get_mcc_mnc.rb
mcc mnc data from wikipedia
#!/usr/bin/env ruby
# Based on https://gist.github.com/choonkeat/4277277
#
# Not sure what the deal was with all that SSL stuff in there, but it was the cause content fetching did not work.
# Replaced it with plain old open-uri and it just works.
require 'net/https'
require 'open-uri'
require 'nokogiri'
require 'json'
@Narnach
Narnach / deploy.rb
Created December 13, 2012 16:20 — forked from anonymous/deploy.rb
desc "precompile assets (only if needed)"
task :precompile_assets do
puts "Diffing assets to check if we need to precompile"
precompile = true
# Only do this if we have a previous release
# Do a normal precompile on a force precompile
if previous_release && latest_release && !ENV['FORCE_PRECOMPILE']
puts "Comparing asset sources of #{previous_release} and #{latest_release}."
@Narnach
Narnach / excuse.rb
Created March 12, 2009 08:45 — forked from FiXato/excuse.rb
#!/usr/bin/env ruby
# Your random BOFH excuse calendar.
# Based upon the The Bastard Operator From Hell Stories written by Simon Paul Travaglia.
# And the list compiled by Jeff Ballard, http://jeffballard.us/
#
# Automatically downloads the excuses from http://pages.cs.wisc.edu/~ballard/bofh/excuses
# and stores them as ~/.excuses.txt for reuse.
require 'open-uri'
class Array
#!/bin/sh
# Usage: s2b.sh branchname
# Easily switch between branches and their databases for Rails projects.
# Checks out given branch and copies the branch's database.yml to the active database.yml
# Outputs a small list of databases being used.
# Make sure you have set up your branch's database.yml in #{RAILS_ROOT}/config/database.#{branchname}.yml
git checkout $1 && cp config/database.$1.yml config/database.yml
databases=`grep --colour=auto database config/database.yml | grep -v ^# | sed s/database\:// | tr -d '\012' | sed -E s/^\ +\|\ +$// | sed -E s/\ +/,\ /g`
echo "Using databases: $databases"
#!/usr/bin/env ruby
require 'rubygems'
require 'active_support'
class John
end
j_c = John.class_eval do
def hi
'hi'
@Narnach
Narnach / gist:37544
Created December 18, 2008 16:04 — forked from samaaron/gist:37541
# Ruby 1.8.6p111 (from source) vs ruby1.9.1-preview1_0 (macports) vs jruby (nicksieger's github version cc5d6648b27890c25aa50b3ebb8fb10d30b1df1f)
narnach@narnachbook ~/Development $ ruby speed.rb && ruby1.9 speed.rb && jruby speed.rb
user system total real
define_method :one 0.970000 0.000000 0.970000 ( 0.994811)
define_method :two 0.990000 0.010000 1.000000 ( 1.000196)
def three 0.420000 0.000000 0.420000 ( 0.434437)
user system total real
define_method :one 0.300000 0.000000 0.300000 ( 0.298044)
define_method :two 0.290000 0.000000 0.290000 ( 0.295531)
@Narnach
Narnach / gist:37538
Created December 18, 2008 15:51 — forked from samaaron/gist:37529
narnach@narnachbook ~/Development $ jruby speed.rb && ruby speed.rb
user system total real
define_method :one 0.107740 0.003617 0.111357 ( 0.156973)
define_method :two 0.075185 0.001356 0.076541 ( 0.098557)
def three 0.033372 0.000635 0.034007 ( 0.042528)
user system total real
define_method :one 0.100000 0.000000 0.100000 ( 0.130217)
define_method :two 0.100000 0.000000 0.100000 ( 0.106536)
def three 0.050000 0.000000 0.050000 ( 0.045840)
@Narnach
Narnach / gist:37062
Created December 17, 2008 14:28 — forked from samaaron/gist:37031
module A
def hi(*list)
singleton = class << self; self; end
list.each do |l|
singleton.send(:define_method, l) do
puts l
end
end
end
end