Skip to content

Instantly share code, notes, and snippets.

@tjmcewan
tjmcewan / destroyer.rb
Created April 10, 2015 14:05
nation builder tag cleaner
require "spec_helper"
NATION = "my-nation"
EMAIL = "[email protected]"
PASSWORD = "Password1"
TAG_PATTERNS_TO_DELETE = [
/^mass_tag_/,
/^valuable_member_/,
]
@tjmcewan
tjmcewan / thing.sh
Created February 19, 2015 09:14
find the 10 longest git commit **messages** (not changesets) in a repo
git log --pretty=oneline --abbrev-commit | awk '{print length() "\t" $1 }' | sort -rn | head -n 10
@tjmcewan
tjmcewan / js_equality.html
Created December 17, 2014 11:21
javascript table of equality
<html><head></head><body></body>
<script type="text/javascript">
// italics for objects
(function (values) {
function toString(x) {
var v = x;
v = (v || v === "") ? JSON.stringify(v) : String(v);
if (typeof x === 'object') v = v.italics();
return v;
}
@tjmcewan
tjmcewan / wtf.rb
Created July 21, 2014 06:15
putting alias_method above module_function allows the alias to be called
~$ ruby -v *[master]
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
~$ irb *[master]
irb(main):001:0> module I18nHelper
irb(main):002:1> def custom_translate
irb(main):003:2> "boo"
irb(main):004:2> end
irb(main):005:1>
irb(main):006:1* module_function :custom_translate
irb(main):007:1> alias_method :ct, :custom_translate
@tjmcewan
tjmcewan / shoulda_or_shoulda_not?.rb
Created July 15, 2014 04:53
shoulda spec examples
it { is_expected.to have_many(:appointments).through(:outlets) }
it { is_expected.to validate_presence_of(:outlet_id) }
it { is_expected.to belong_to(:outlet) }
# http://stackoverflow.com/a/19323467/320438
def plusone(x)
x + 1
end
[1,2,3].map(&:plusone)
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"
done
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"
done
@tjmcewan
tjmcewan / jquerify.js
Created April 2, 2014 00:25
protocol independent jquerify
javascript:(function()%7Bvar el%3Ddocument.createElement("div"),b%3Ddocument.getElementsByTagName("body")%5B0%5D,otherlib%3D!1,msg%3D""%3Bel.style.position%3D"fixed",el.style.height%3D"32px",el.style.width%3D"220px",el.style.marginLeft%3D"-110px",el.style.top%3D"0",el.style.left%3D"50%25",el.style.padding%3D"5px 10px",el.style.zIndex%3D1001,el.style.fontSize%3D"12px",el.style.color%3D"%23222",el.style.backgroundColor%3D"%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
@tjmcewan
tjmcewan / snakify.rb
Last active August 29, 2015 13:57 — forked from puyo/encamel.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
tjmcewan / email.md
Last active August 29, 2015 13:57
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.