Skip to content

Instantly share code, notes, and snippets.

View jakeonrails's full-sized avatar

Jake Moffatt jakeonrails

View GitHub Profile
describe '#game_won?' do
winning = [
<<-BOARD
.x...
ox...
oxo..
oxo..
BOARD
]
@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>
# 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 / 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
@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 / 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 / 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 / parser_spec.rb
Created January 25, 2014 00:38
Reverse Polish Notation parser
require 'spec_helper'
class Parser
def parse(string)
stack = []
tokens = string.split(' ')
tokens.each do |token|
if token =~ /\d/
value = token.to_i
@jakeonrails
jakeonrails / gist:c2f302bce7b1e4707faa
Created April 11, 2015 01:20
Circle CI Failure Bookmarklet
$(window.open().document.body).html(
"<style>textarea { font-size: large; font-family: monospace;}</style>" +
"<h4>Cucumber failures</h4><textarea style='height: 25%;width: 100%'>cucumber " +
$.makeArray($.unique(
$('span.red').filter(function() {
return (this.textContent).match(/cucumber .+:\d+/)
}).map(function() {
return $(this).text().match(/cucumber (.+)/)[1]
})
).sort()).join(' ') +
@jakeonrails
jakeonrails / find_each_by_column.rb
Last active August 29, 2015 14:19
find each by column
class ActiveRecord::Base
def self.find_each_by(column, options={}, &block)
return enum_for(:find_each_by_column) unless block_given?
last_value = last_id = nil
order = options.fetch(:order, :asc)
batch_size = options.fetch(:batch_size, 1000)
operator = order == :asc ? '>=' : '<='
loop do