Skip to content

Instantly share code, notes, and snippets.

@jlapier
jlapier / inflections.rb
Created January 29, 2013 19:15
there are no words in English that end in 's' as singular but 'ss' as plural
# config/initializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
inflect.singular(/^(.*ss)$/i, '\1')
end
@jlapier
jlapier / gist:3981563
Created October 30, 2012 17:05
using ruby-mp3info to fix artist names in mp3 tags
# I always manage to end up with different capitalizations on artist names,
# which causes some mp3 players to see them as different artists.
# So I use ruby-mp3info to rename them
# gem install ruby-mp3info
require 'rubygems'
require 'ruby-mp3info'
# in the directory of the artist, with albums as subdirectories (change as needed)
files = Dir['*/*.mp3']
files.each do |f|
@jlapier
jlapier / grep_for_double_words.sh
Created September 24, 2011 18:19
grep for double words in text
# I use this to find double words in a text file
# for example, "Give it to the kid." gets typoed as "Give it the the kid."
# this regex will find "the the" and help me track down those double word typos
egrep '(\b\w+)\s\1\b' *.txt --color -n
@jlapier
jlapier / object_sort.js
Created September 21, 2011 16:41
sort objects with mixed alpha and numerical strings so that "A 10" follows "A 9"
// a simpler version in javascript that actually zero-pads numbers in
// the strings so we can sort properly
// this one uses underscore.js, but you get the picture
// in this example, we have a bunch of text_document objects to sort
sorted = _(text_documents).sortBy(
// the zero padding is to make "Chap 9" come before "Chap 10"
function(td) { return [td.name.replace(/\d+/, function(m) { return zeroPad(m, 99) } )]; }
);
# get rid of weird characters from pasting from Word and stuff
def cleanup(text)
if text
text.
gsub(/&/, '&').
gsub(/&[lr]?quot;/, '"').
gsub(/'/, "'").
gsub(/'/, "'").
gsub(/>/, '>').
gsub(/&lt;/, '<').