Skip to content

Instantly share code, notes, and snippets.

View jakeonrails's full-sized avatar

Jake Moffatt jakeonrails

View GitHub Profile
@jakeonrails
jakeonrails / json_api_dsl.rb
Created August 13, 2013 03:24
JSON API test DSL
describe 'POST api/v1/sessions' do
def self.request(options)
let(:api_response) {
send(
options[:method].downcase,
options[:path],
options[:json],
)
last_response
}
@jakeonrails
jakeonrails / fix_newrelic_pow.md
Created April 11, 2013 21:12
Newrelic developer mode returns "no route matches" when you hit /newrelic and you happen to be running pow.
@jakeonrails
jakeonrails / migrating.md
Last active May 28, 2019 21:38
Migrating from Postgres 9.0/Postgis 1.5 to Postgres 9.2/Postgis 2.0 on Heroku

Migrating from Postgres 9.0/Postgis 1.5 to Postgres 9.2/Postgis 2.0 on Heroku

This may not be relevant to many, but it's a process that I just had to go through and it was a bit tricky to figure a smooth way to make it work.

The gist of it is that you must do the following:

  • Export your production database from heroku to your local machine
  • Create a new, blank database with Postgres 9.2 and PostGIS 2.0
  • Import your heroku database into the new local database running 9.2/2.0
  • Dump the new database and upload it to S3
@jakeonrails
jakeonrails / ping_pong.rb
Created February 27, 2013 20:08
PING PONG ENUMERATOR!
pinger = Enumerator.new do |yielder|
loop
yielder << "PING"
end
end
pinger.each do |ping|
puts ping
puts "PONG"
end
# Assuming all the methods called here also return true/false,
# use the logical composition operators to create a final result
# which can short-circuit if one of the methods fails:
def composed_method
frobulate_widgets and refrobulate_widgets and confribulate_frobulations
end
@jakeonrails
jakeonrails / Ruby Notepad Bookmarklet
Created January 29, 2013 18:08
This bookmarklet gives you a code editor in your browser with a single click.
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>
describe '#game_won?' do
winning = [
<<-BOARD
.x...
ox...
oxo..
oxo..
BOARD
]
@jakeonrails
jakeonrails / benchmark.rb
Created November 6, 2012 23:15 — forked from panthomakos/benchmark.rb
Benchmark Your Bundle
#!/usr/bin/env ruby
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]
@jakeonrails
jakeonrails / robot_user_agents.rb
Created October 15, 2012 21:37 — forked from Sjors/robot_user_agents.rb
Recognize search engines and spammers using user-agents.org
require 'net/http'
require 'xmlsimple'
url = "http://www.user-agents.org/allagents.xml"
xml_data = Net::HTTP.get_response(URI.parse(url)).body
data = XmlSimple.xml_in(xml_data)
agents = data['user-agent'].select{|agent| type = agent["Type"].first; type.include?("R") || type.include?("S")}
agent_names = agents.collect {|agent| agent["String"].first}
@jakeonrails
jakeonrails / gist:3895690
Created October 15, 2012 21:34
Postgres table and index sizes
SELECT CASE WHEN total IS NULL THEN '' ELSE name END AS table,
index,
pg_size_pretty(size) AS size,
CASE WHEN total IS NULL THEN '' ELSE pg_size_pretty(total) END AS total
FROM
(SELECT name,
index,
size,
total
FROM