Skip to content

Instantly share code, notes, and snippets.

View jakeonrails's full-sized avatar

Jake Moffatt jakeonrails

View GitHub Profile
@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>
@jakeonrails
jakeonrails / .change-tab-color-pwd
Created September 24, 2015 01:23
How to have change the tab color in iTerm2 based on what folder or directory you are in
#!/usr/bin/env python
"""
Set terminal tab / decoration color by the server name.
Get a random colour which matches the server name and use it for the tab colour:
the benefit is that each server gets a distinct color which you do not need
to configure beforehand.
"""
@jakeonrails
jakeonrails / prepare-commit-message
Last active October 4, 2023 06:57
prepare-commit-message that requires a JIRA ID and adds it if the branch name contains one
#!/usr/bin/env ruby
# Git Prepare Commit Message Hook Script
#
# Location: <repository>/.git/hooks/prepare-commit-msg
#
# This script will automatically add the correct
# JIRA ISSUE ID to the end of each commit message
# When the branch ID starts with the JIRA ISSUE ID.
# It can be overridden if specified in the message.
@jakeonrails
jakeonrails / .set_tab_color
Created July 20, 2016 19:28
Set Tab Color for ZSH + iTerm2
#!/usr/bin/env ruby
# Change tab color based on pwd.
#
# If a directory contains a .tabcolor file, it will use the lines of that file
# as RGB values. It should look like:
#
# 255
# 128
# 96
@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
def count_sql_creates
counts = Hash.new(0)
logger = -> (event, start, finish, id, payload) do
if (table = payload[:sql][/INSERT INTO "(.+?)"/, 1])
counts[table] += 1
end
end
subscription = ActiveSupport::Notifications.subscribe('sql.active_record', logger)
yield
ActiveSupport::Notifications.unsubscribe(subscription)
#!/usr/bin/env ruby
# Usage:
# $ ruby code-challenge.rb <github.com repo>
repo = ARGV[0]
# Clear previous challenge
puts "Removing previous directories"
`rm -rf coding-challenge-source`
`rm -rf coding-challenge`
require 'awesome_print'
# Put this file into your spec/support directory in order to have RSpec automatically report
# on the total number of database records created during a run of your test suite.
class ActiveRecordInsertCountReport
include Singleton
def subscribe_to_notifications
ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
name, start, ending, transaction_id, payload = args
table_name = payload[:sql][/insert into "(.+?)"/i, 1]
class RingBuffer
def initialize(redis=nil, list_key=nil)
@redis = redis
end
def next
JSON(@redis.rpoplpush(@list_key, @list_key))[0]
end
def add(item)
@jakeonrails
jakeonrails / database_url.rb
Created May 22, 2012 07:01
Parse heroku DATABASE_URL
<%
require 'cgi'
require 'uri'
begin
uri = URI.parse(ENV["DATABASE_URL"])
rescue URI::InvalidURIError
raise "Invalid DATABASE_URL"
end