Skip to content

Instantly share code, notes, and snippets.

View code_that_apparently_should_work.rb
def plusone(x)
x + 1
exclude_patterns() {
exclude="-false" # need to start the list somewhere so we have the right number of "-or"
for exclude_folder in .git .bundle tmp log; do
exclude="$exclude -or -name $exclude_folder -prune"
for exclude_file in Gemfile.lock structure.sql '*.gif' '*.jpg' '*.png' '*jquery*' '*.doc' '*.pdf' '*.zip' '*.ico' '*.swf' '*.sqlite' '*.ttf'; do
exclude="$exclude -or -iname $exclude_file"
tjmcewan / jquerify.js
Created Apr 2, 2014
protocol independent jquerify
View jquerify.js
javascript:(function()%7Bvar el%3Ddocument.createElement("div"),b%3Ddocument.getElementsByTagName("body")%5B0%5D,otherlib%3D!1,msg%3D"""fixed","32px","220px","-110px","0","50%25","5px 10px",,"12px","%23222","%23f99"%3Bfunction showMsg()%7Bvar txt%3Ddocument.createTextNode(msg)%3Bel.appendChild(txt),b.appendChild(el),window.setTimeout(function()%7Btxt%3Dnull,typeof jQuery%3D%3D"undefined"%3Fb.removeChild(el):(jQuery(el).fadeOut("slow",function()%7BjQuery(this).remove()%7D),otherlib%26%26(window.%24jq%3DjQuery.noConflict()))%7D,2500)%7Dif(typeof jQuery!%3D"undefined")return msg%3D"This page already using jQuery v"%2BjQuery.fn.jquery,showMsg()%3Btypeof %24%3D%3D"function"%26%26(otherlib%3D!0)%3Bfunction getScript(url,success)%7Bvar script%3Ddocument.createElement("script")%3Bscript.src%3Durl%3Bvar he
View snakify.rb
#!/usr/bin/env ruby
gem 'activesupport'
require 'active_support/core_ext/string/inflections'
camel = ARGV.first
snake = camel.underscore
system %{git grep -l #{camel} | xargs ruby -p -i -e '$_.gsub! /#{camel}/, "#{snake}"'}
tjmcewan /
Last active Aug 29, 2015
email for Rails Girls organisers to forward to their networks

Hi there,

If you're interested in taking your web journey to the next level and would love to contribute to the open source community, consider applying for a paid scholarship for this year's Rails Girls Summer of Code.

It will run from July to September 2014, and will see you contribute to an open source project of your choice. You'll be increasing your coding skills, with help from a coach or two, and will be making a significant contribution to the community.

Applications close May 2nd, but there's a fair bit to do before then, so don't delay. :) Read more on what's required in the application guide.

If you're curious and want to know more first, you can check out the FAQ.

tjmcewan /
Created Nov 26, 2013
inside the heroku beast
~/projects$ h run bash
Running `bash` attached to terminal... up, run.2192
~ $ uname -a
Linux 7fa29fb1-2e9c-4510-a0a7-df92cfaff4c8 3.8.11-ec2 #1 SMP Fri May 3 09:11:15 UTC 2013 x86_64 GNU/Linux
~ $ free -m
total used free shared buffers cached
Mem: 34302 29994 4307 0 1927 8232
-/+ buffers/cache: 19835 14466
Swap: 34815 732 34083
tjmcewan /
Last active Dec 26, 2015
Ninefold db updates

This is a quick way to Push or Pull your app database between your local machine and your Ninefold app server. "Pushing" is useful in the early stages of app development when you need to update seed data. "Pulling" is eternally useful for debugging.

  1. setup public key authentication (the SSH username is "user"). NB ensure you don't remove the existing SSH key - it's needed by the Ninefold Portal.

  2. obtain your database password from the "database" tab in the Ninefold portal.

  3. put the password where Postgres can find it (on the database server): echo "localhost:*:*:app:<PASSWORD>" > ~/.pgpass then chmod 0600 .pgpass more info on password files

tjmcewan / database.yml
Last active Dec 24, 2015
app-agnostic, feature branch supporting, drop-in database.yml(based on
View database.yml
app_name = Dir.getwd.split('/')[-1]
branch = `git symbolic-ref --short HEAD 2>/dev/null`.chomp.gsub(/\W/, '_')
db_name = branch.match(/feature/) ? "#{app_name}_#{branch}" : "#{app_name}_master"
puts "DATABASE: #{db_name}"
mysql2: &mysql2
adapter: mysql2
socket: /tmp/mysql.sock
tjmcewan /
Last active Oct 31, 2017
some options & shortcuts to make git branch management simple and sane

Run these once to setup git options:

git config --global push.default current
git config --global merge.defaultToUpstream true
git config --global branch.autosetupmerge true
git config --global branch.autosetuprebase remote
git config --global alias.cb 'checkout -b'
git config --global 'push -u'
git config --global '!git fetch -p && git rebase'

Use them like this:

tjmcewan / git-rebase-todo
Last active Dec 19, 2015
multi-stage deploy using git rebase -i
View git-rebase-todo
# x (or exec) will run anything on the same line as a shell command.
# we need to checkout a temporary branch because git won't push detached HEADs.
# after deploy, the "checkout -" means checkout the previously checked out thing,
# which will go back to our detached head and we clean up the temporary branch so
# that we don't need to worry about merging.
# if your branch is already based on the same point as your rebase command, then
# the 'pick' stage is essentially the same as a fast-forward merge; no new commits
# are created.