Skip to content

Instantly share code, notes, and snippets.

View hynkle's full-sized avatar

Jonathan Hinkle hynkle

View GitHub Profile
@hynkle
hynkle / gist:1174010
Created August 26, 2011 18:08
string range replacement
s = "Hello world!"
# => "Hello world!"
s[6..-2] = "pukeface"
# => "pukeface"
s
# => "Hello pukeface!"
@hynkle
hynkle / gist:1230021
Created September 20, 2011 19:12
ruby consecutive strings
# Today I discovered what was to me a new Ruby syntax feature.
# I can't even blame my ignorance on the relative newness of
# Ruby 1.9 — works just fine in 1.8 as well.
def print_args(*args)
puts args.inspect
end
print_args "foo", "bar"
# => ["foo", "bar"]
@hynkle
hynkle / .rvmrc
Created November 4, 2011 23:15
.rvmrc to broker peace in the .rvmrc-in-repo war
# The best little rvmrc to solve those annoying debates about whether or not
# .rvmrc should be checked in.
# Check this file in as .rvmrc. Any project member who desires different
# settings simply creates a .rvmrc_override file, which will be used if present.
# You'll want to add .rvmrc_override to your .gitignore.
local DEFAULT='rvm 1.9.2@gemset_name --verbose --create'
[ -f .rvmrc_override ] && source .rvmrc_override || $DEFAULT
@hynkle
hynkle / gist:2512637
Created April 27, 2012 20:23
currency input validation
# Managing potentially messy input from a free-form text input that's supposed to represent currency.
#
# Acceptable:
# 1
# 12
# 123
# 1234
# 1234.56
# $1
# $12
@hynkle
hynkle / ppjson.sh
Created October 1, 2012 20:25
pretty-print JSON using node
function ppjson {
node -e "
require('fs').readFile(
'$1',
function(err,data) {
if (err) {
console.error(err);
process.exit(1);
}
console.log(
@hynkle
hynkle / ppjsonurl.sh
Created October 4, 2012 18:53
pp json from url with gratuitous obfuscation
curl http://www.example.com/resource.json | node -e 'ε="";θ=process;β=θ.stdin;γ=JSON;β.on("data",function(τ){ε+=τ}),β.on("end",function(){θ.stdout.write(γ.stringify(γ.parse(ε),γ.χ,2))}),β.resume();' > pretty_printed_resource.json
error: refusing to create funny ref 'refs/master' remotely
@hynkle
hynkle / raise_as.rb
Created October 31, 2012 14:07
Raise As
# for those times you want to bubble an exception up, but want to put it in a different exception class
module Kernel
def raise_as(exception_class)
raise if $!.nil?
raise exception_class, $!.message, $!.backtrace
end
end
@hynkle
hynkle / ppjson.js
Created December 13, 2012 19:41
Reads JSON from stdin; pretty prints it to stdout.
#!/usr/bin/env node
var flatJSON = '';
process.stdin.on('data', function(data) {
flatJSON = flatJSON + data;
});
process.stdin.on('end', function() {
prettyJSON = JSON.stringify( JSON.parse(flatJSON), null, 2 )
console.log(prettyJSON);
@hynkle
hynkle / twitter_regex.js
Created December 14, 2012 15:33
Sweet regex found in Twitter's javascript.
/^[a-z0-9_À-ÖØ-öø-ÿĀ-ɏɓ-ɔɖ-ɗəɛɣɨɯɲʉʋʻ̀-ͯḀ-ỿЀ-ӿԀ-ԧⷠ-ⷿꙀ-֑ꚟ-ֿׁ-ׂׄ-ׇׅא-תװ-״﬒-ﬨשׁ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﭏؐ-ؚؠ-ٟٮ-ۓە-ۜ۞-۪ۨ-ۯۺ-ۼۿݐ-ݿࢠࢢ-ࢬࣤ-ࣾﭐ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼ‌ก-ฺเ-๎ᄀ-ᇿ㄰-ㆅꥠ-꥿가-힯ힰ-퟿ᄀ-ᅵァ-ヺー-ヾヲ-゚ー0-9A-Za-zぁ-ゖ゙-ゞ㐀-䶿一-鿿꜀-뜿띀-렟-﨟〃々〻]*[a-z_À-ÖØ-öø-ÿĀ-ɏɓ-ɔɖ-ɗəɛɣɨɯɲʉʋʻ̀-ͯḀ-ỿЀ-ӿԀ-ԧⷠ-ⷿꙀ-֑ꚟ-ֿׁ-ׂׄ-ׇׅא-תװ-״﬒-ﬨשׁ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﭏؐ-ؚؠ-ٟٮ-ۓە-ۜ۞-۪ۨ-ۯۺ-ۼۿݐ-ݿࢠࢢ-ࢬࣤ-ࣾﭐ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼ‌ก-ฺเ-๎ᄀ-ᇿ㄰-ㆅꥠ-꥿가-힯ힰ-퟿ᄀ-ᅵァ-ヺー-ヾヲ-゚ー0-9A-Za-zぁ-ゖ゙-ゞ㐀-䶿一-鿿꜀-뜿띀-렟-﨟〃々〻][a-z0-9_À-ÖØ-öø-ÿĀ-ɏɓ-ɔɖ-ɗəɛɣɨɯɲʉʋʻ̀-ͯḀ-ỿЀ-ӿԀ-ԧⷠ-ⷿꙀ-֑ꚟ-ֿׁ-ׂׄ-ׇׅא-תװ-״﬒-ﬨשׁ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﭏؐ-ؚؠ-ٟٮ-ۓە-ۜ۞-۪ۨ-ۯۺ-ۼۿݐ-ݿࢠࢢ-ࢬࣤ-ࣾﭐ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼ‌ก-ฺเ-๎ᄀ-ᇿ㄰-ㆅꥠ-꥿가-힯ힰ-퟿ᄀ-ᅵァ-ヺー-ヾヲ-゚ー0-9A-Za-zぁ-ゖ゙-ゞ㐀-䶿一-鿿꜀-뜿띀-렟-﨟〃々〻]+$/