Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-10 of 24 total  RSS 

Rails Date Formats

// cribbed from http://wiki.rubyonrails.org/rails/pages/HowToDefineYourOwnDateFormat

my_formats = {
  :my_format_1 => '%l %p, %b %d, %Y',
  :my_format_2  => '%l:%M %p, %B %d, %Y'
}

ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(my_formats)
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(my_formats)

MySQL Database Size

mysql -uroot -D sfcnet_development -e "show table status\G"| egrep "(Index|Data)_length" | awk 'BEGIN { rsum = 0 } { rsum += $2 } END { print rsum }'

Optimize Aperture database

sqlite3 Pictures/Aperture\ Library.aplibrary/Aperture.aplib/Library.apdb vacuum

String#to_range

// convert a string like "1-10" to a range 1..10

class String; def to_range; Range.new(*self.split("-").map{|i|i.to_i}); end; end

get all local variables

>> local_variables
# => ["_"]  

>> a = "Kevin"
# => "Kevin"  

>> local_variables
# => ["_", "a"]  

Mount SSH using MacFUSE

This will also list the voume in the Finder, thanks to the volname option (I think)

mkdir -p ~/mnts/formandfx
sshfs kmarsh@formandfx.com: ~/mnts/formandfx -oping_diskarb,volname=formandfx

Building curb under Mac OS X

Had a bit of a problem getting curb to work in OS X, but if you have the curl port installed, its easy:

sudo port install curl
cd src
curl -O http://rubyforge.iasi.roedu.net/files/curb/curb-0.1.0.tar.gz
tar -zxvf curb-0.1.0.tar.gz
cd curb-0.1.0.tar.gz
ruby extconf.rb --with-curl-lib=/opt/local/lib/ --with-curl-include=/opt/local/include/
ruby tests/alltests.rb
sudo make install

Freeze Rails to Edge RC2 via SVN Externals

So you've already frozen to RC1, but need to upgrade to RC2?

cd ~/Sites/railsapp
svn propedit svn:externals vendor
# An editor will pop up, change RC1 to RC2 and save
svn up
svn ci -m "* Upgrade to RC2"


<3 SVN Externals

Bonus tip: I'm a habitual 'svn stat'er, and this helped speed up the process:

svn --ignore-externals stat

Get Frontmost Window

tell application "System Events"
	set frontmostApplication to name of the first process whose frontmost is true
end tell

Freeze Rails to Edge RC1 via SVN Externals

cd vendor
svn propset svn:externals "rails http://dev.rubyonrails.org/svn/rails/tags/rel_1-2-0_RC1/" .
svn ci
svn up
« Newer Snippets
Older Snippets »
Showing 1-10 of 24 total  RSS