Skip to content

Instantly share code, notes, and snippets.

# http://stackoverflow.com/a/19323467/320438
def plusone(x)
x + 1
end
[1,2,3].map(&:plusone)
@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) }
@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 / 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 / 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 / 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 / keybase.md
Created April 28, 2015 23:50
keybase proof

Keybase proof

I hereby claim:

  • I am tjmcewan on github.
  • I am tjmcewan (https://keybase.io/tjmcewan) on keybase.
  • I have a public key whose fingerprint is 77AB E45C 44A2 6B7E C691 2F1F C16A 1AC7 7FAF 79D6

To claim this, I am signing this object:

@tjmcewan
tjmcewan / aws_route53_cleaner_instructions.md
Last active August 29, 2015 14:27
Want to delete a lot of old hosted zones on Route53? This should take the pain away.

AWS Route53 Hosted Zone Cleaner

Why?

My org buys lots of domains and configure lots of records on AWS. Removing them is a pain though; you have to remove each record set before you can remove the hosted zone. This makes it much more straightforward.

Feel free to use this; but you're on your own. I am not responsible if you break something.

Setup

You'll need ruby/ruby-gems and your AWS API credentials.

@tjmcewan
tjmcewan / awsm.json
Created October 27, 2015 01:07
Excerpt from awsm.json that shows CORS setup for an API Gateway endpoint.
"default": {
"statusCode": "200",
"headers": {
"Access-Control-Allow-Origin": {
"type": "string"
}
},
"responseParameters": {
"method.response.header.Access-Control-Allow-Origin": "'http://CORSdomain.com'"
},
@tjmcewan
tjmcewan / localtunnel
Last active October 12, 2016 03:13
localtunnel restarter. all props to @michaelkeenan. slightly modified to be run as a executable & to remove ordinal numbers. original here: https://github.com/localtunnel/localtunnel/issues/81#issuecomment-218320442
#!/usr/bin/env ruby
require 'optparse'
options = {:subdomain => 'defaultdomain', :port => 3000}
parser = OptionParser.new do|opts|
opts.banner = "Usage: localtunnel [options]"
opts.on('-s', '--subdomain subdomain', 'Subdomain') do |subdomain|
options[:subdomain] = subdomain;