Skip to content

Instantly share code, notes, and snippets.

@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.

@tjmcewan
tjmcewan / inside.sh
Created November 26, 2013 13:11
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
tjmcewan / instructions.md
Last active December 26, 2015 11:59
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