Skip to content

Instantly share code, notes, and snippets.

View cdmwebs's full-sized avatar
🦕

Chris Moore cdmwebs

🦕
View GitHub Profile
@cdmwebs
cdmwebs / download.rake
Created December 18, 2010 03:47
Download with rake
require 'uri'
require 'net/http'
desc "Download some files"
task :download do
uri = URI.parse('http://www.google.com')
# shell to curl
system %Q{curl -o google.html #{uri}}
@cdmwebs
cdmwebs / database.rake
Created December 20, 2010 10:22
Pull a copy of the latest backup via ssh and restore to dev
require 'net/scp'
namespace :db do
desc 'pull the latest backup & restore locally'
task :restore do
Rake::Task['db:download'].invoke
Rake::Task['db:replace'].invoke
end
desc 'pull down the lastest backup from production'
@cdmwebs
cdmwebs / mount.scpt
Created January 8, 2011 07:01
Mount and unmount a drive with AppleScripts. I use these to spin down my second internal HDD. Taken from: MacRumors (http://forums.macrumors.com/showpost.php?p=9596575&postcount=5)
do shell script "diskutil mountDisk `disktool -l | grep Backup | awk '{ print substr($0,20,7) }'`"
@cdmwebs
cdmwebs / payment.rb
Created May 11, 2011 21:30
Square'd up.
class Payment
FEE_RATE = 0.029 # 2.9%
TRANSACTION_FEE = 0.15
attr_reader :amount
def initialize(amount)
@amount = amount
end
~/src/chef-repo $ knife cookbook site vendor mysql -d
WARNING: No knife configuration file found
Installing mysql to /var/chef/cookbooks
ERROR: The cookbook repo path /var/chef/cookbooks does not exist or is not a directory
ps aux | grep -E -i "[j]ruby.*(rails s|rake)" | awk '{print $2}' | xargs kill -9
@cdmwebs
cdmwebs / losangeles.craigslist.org.js
Created August 25, 2011 22:26 — forked from ajsharp/losangeles.craigslist.org.js
Craigslist live filtering
// Adds a live filter box to the results screen on craigslist
// that filters the results that are currently on the page by
// the search term. Like Cmd-F, but better.
// NOTE: Requires dotjs.
if (window.location.pathname.match(/\/search\//) && !$('body').html().match(/Nothing found for that search/)) {
var searchHash = window.location.hash,
searchString = searchHash.split("/")[1],
filterResults = {},
@cdmwebs
cdmwebs / friendly_urls.markdown
Created September 11, 2011 15:50 — forked from jcasimir/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

{
"_id": "2643f4d1de6a4d880678fa0f720efd76",
"_rev": "2-8070abd82658a3c390053c8b3b184df9",
"type": "camera",
"location": "I-275 at Colerain Ave.",
"href": "http://www.artimis.org/camera/camera112.php",
"latitude": null,
"longitude": null,
"imageURL": "http://cmhimg01.dot.state.oh.us/images/artimis/CCTV112.jpg"
}

Ruby Global Setup

  1. Install homebrew.
  2. brew install rbenv ruby-build
  3. echo 'eval "$(rbenv init -)"' >> $HOME/.bash_profile
  4. rbenv install 1.9.2-p290
  5. rbenv global 1.9.2-p290
  6. rbenv rehash
  7. gem install bundler rails