Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am rwtnorton on github.
  • I am rwtnorton (https://keybase.io/rwtnorton) on keybase.
  • I have a public key whose fingerprint is F865 C3B6 48B5 DCD9 96E7 A6AA 09A8 F41D 2A1E 5EE9

To claim this, I am signing this object:

# bash function
defcomp () {
local name="$1" && shift
local functionName="$( echo "${name}_completion" | tr - _ )"
source <(cat <<EOM
$functionName () {
local cur
_get_comp_words_by_ref -n =: cur
COMPREPLY=( \$(compgen -W "\$( $@ )" -- "\$cur") )
}
#!/bin/bash
##
## Updates all environment.rb files on your box to use your
## email address. Prevents spamming everyone on test@shops.com.
##
## *** Just remember to not commit the edit to master!!! ***
##
##
## INSTALL
#!/usr/bin/env ruby
# Changes hashrockets (i.e., `:foo => 1`) to 1.9 syntax (i.e., `foo: 1`).
while line = gets do
line.chomp if line
line.gsub!(/:(\w+)\s*=>\s*/, "#{$1}: ")
puts line
end
# cat|ruby -ple '$_.gsub!(/:(\w+)\s*=>\s*/, "#{$1}: ")'
#!/bin/sh
# Changes hashrockets (i.e., `:foo => 1`) to 1.9 syntax (i.e., `foo: 1`).
cat |ruby -ple '$_.gsub!(/:(\w+)\s*=>\s*/, "#{$1}: ")'
@rwtnorton
rwtnorton / unrocketify
Created January 10, 2013 17:25
Reads strings of Ruby from stdin and writes to stdout the same string but with hashrockets transformed into the Ruby 1.9 syntax. Note that this is a fairly naive utility; it cannot distinguish, for example, whether a hashrocket is really embedded in a string or comment or whatever. Caveat haxor.
#!/bin/sh
# Changes hashrockets (i.e., `:foo => 1`) to 1.9 syntax (i.e., `foo: 1`).
cat |perl -ple 's/:(\w+)\s*=>\s*/$1: /g'
@rwtnorton
rwtnorton / chuck-norris.rb
Created November 9, 2012 15:12
chuck-norris
#!/usr/bin/env ruby
require 'json'
require 'open-uri'
open('http://api.icndb.com/jokes/random') do |f|
f.each_line do |s|
json = JSON.load(s)
if json && json['value'] && json['value']['joke']
puts json['value']['joke']
end
end
@rwtnorton
rwtnorton / empty-resque-notifications.sh
Created June 8, 2012 14:53
Bash script to empty your resque notification queue.
#!/bin/bash
queue="resque:queue:notifications"
# Replace with location pertinent to your setup.
cd ~/src/digistore_new/administrators
had=`redis-cli llen $queue |sed 's/\([0-9]\+\)/$1/'`
# TODO: There must be a way to do this in one operation.
@rwtnorton
rwtnorton / in-vs-include.irb
Created May 18, 2012 20:36
ruby: include? vs in?
1.9.3p0 :001 > class Object; def in?(enum); enum.respond_to?(:include?) ? enum.include?(self) : false; end; end
=> nil
1.9.3p0 :002 > 1.in? ['a', 2, Time.now]
=> false
1.9.3p0 :003 > 1.in? ['a', 2, Time.now, nil, 1]
=> true
1.9.3p0 :004 > ['a', 2, Time.now].include? 1
=> false
1.9.3p0 :005 > ['a', 2, Time.now, nil, 1].include? 1
=> true
@rwtnorton
rwtnorton / gist:1453568
Created December 9, 2011 22:19
parse out q query param from url
#!/usr/bin/env ruby
require 'uri'
require 'cgi'
url = 'http://www.google.com/url?sa=t&rct=j&q=beef%20jerky%20recipe&source=web&cd=4&ved=0CIIBEBYwAw&url=http%3A%2F%2Fbeefjerkyrecipes.com%2F&ei=xYDiTvDfF6jw0gHRxrnyBQ&usg=AFQjCNG08v5ya0pv7pZ1ChlFUF7DZAF3Jg'
uri = URI.parse url
params = CGI.parse uri.query