Skip to content

Instantly share code, notes, and snippets.

View boffbowsh's full-sized avatar

Paul Bowsher boffbowsh

View GitHub Profile
@boffbowsh
boffbowsh / metastore.rb
Created July 24, 2008 15:14
Put has_metadata.rb in lib, then use has_metadata :os in your model
class Metadata < ActiveRecord::Base
set_table_name "meta_metadata"
belongs_to :meta_object, :polymorphic => true
end
@boffbowsh
boffbowsh / lite_bootstrap.php
Created January 8, 2009 12:55
Bootstrapping Kohana to just use it's libraries
function __autoload( $sClass )
{
// Your own autoload code goes here
// Failed to load, try Kohana's autoloader
// Bootstrap it first
if ( !defined('SYSPATH') )
{
define('SYSPATH', ROOT.'kohana/system/');
define('APPPATH', ROOT.'kohana/application/');
define('EXT', '.php');
# Delete unnecessary files
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/javascripts/prototype.js"
run "rm public/javascripts/effects.js"
run "rm public/javascripts/dragdrop.js"
run "rm public/javascripts/controls.js"
# Copy database.yml for distribution use
run "cp config/database.yml config/database.yml.example"
#!/bin/sh
name=$1
if [ -z "$name" ] ; then
echo "need to give name of checkout dir on command line"
exit 1
fi
dir="~/rails_apps/$name"
if [ ! -d $dir ] ; then
echo "the directory $dir does not exist"
@boffbowsh
boffbowsh / hurl.rb
Created August 26, 2009 09:09
A command-line wrapper for the hurl rails rumble app
require 'rubygems';require 'active_support';require 'nokogiri';puts Nokogiri.HTML(ActiveSupport::JSON.decode(`curl -s -F url=#{ARGV.first} http://hurl.r09.railsrumble.com/`)['body']).content
#! /usr/local/bin/ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
doc = Nokogiri.XML(open('http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=boffbowsh&api_key=b25b959554ed76058ac220b7b2e0a026').read)
puts "Now Playing: #{doc.css('track[nowplaying=true] artist')[0].content} - #{doc.css('track[nowplaying=true] name')[0].content}"
@boffbowsh
boffbowsh / gist:186886
Created September 14, 2009 19:54
deploy.rb.diff
diff --git a/config/deploy.rb b/config/deploy.rb
index b5ad582..bdb8592 100644
--- a/config/deploy.rb
+++ b/config/deploy.rb
@@ -16,10 +16,6 @@ set :deploy_via, :remote_cache
set :repository, "git@github.com:rawnet/lastpercent.git"
set :scm, :git
-on :start do
- `ssh-add`
// Make 'this' available within ajax calls
Function.prototype.bind = function(thisArg){
var self = this;
return function() { self.apply(thisArg, arguments); };
};
@boffbowsh
boffbowsh / blob_awesome.rb
Created October 20, 2009 10:03
Allows you to store blobs off-model for performance reasons, but still access them in a pretty way.
class ProductPage < ActiveRecord::Base
has_many :text, :class_name => 'ProductPageContent' do
def [] name
name = name.to_s
find_by_field_name(name).body
end
def []= name, body
name = name.to_s
contents = find_or_initialize_by_field_name name
/Users/boffbowsh/code/ruby/rubinius/spec/frozen/core/kernel/require_spec.rb
Kernel#require
- is a private method
- resolves paths relative to the current working directory
- does not expand/resolve qualified files against $LOAD_PATH
- loads a .rb from an absolute path
- collapses consecutive path separators
- loads an unqualified .rb by looking in $LOAD_PATH and returning true
- allows unqualified files to contain path information (just not in the beginning)
- loads a file with ./filename even if . is not in path