Skip to content

Instantly share code, notes, and snippets.

View brentkirby's full-sized avatar

Brent Kirby brentkirby

View GitHub Profile
require 'spec_helper'
describe Product do
it{ should belong_to :designer }
it{ should have_many :taggings }
it{ should have_many(:tags).through(:taggings) }
it{ should have_many :images }
it{ should have_many :product_properties }
it{ should have_many(:available_properties).through(:product_properties) }
@brentkirby
brentkirby / lame.rb
Created March 5, 2012 20:54
naming fix for active model
def self.model_name
name = "Entry"
name.instance_eval do
def plural; pluralize; end
def singular; singularize; end
def i18n_key; singularize; end
def human(*args); singularize; end
end
return name
end
@brentkirby
brentkirby / sm.rb
Created March 5, 2012 03:32
state_machine rails 3.2.2
module EntryUtils
module StateMachine
extend ActiveSupport::Concern
included do
before_validation :ensure_default_state, :on => :create
state_machine :initial => :created do
before_transition any => [:published,:approved] do |entry, transition|
if entry.content_empty?
@brentkirby
brentkirby / stack.sh
Created January 31, 2012 22:18
Linode nginx, php, mysql stackscript
#!/bin/bash
#
# Ruby 1.9.2 with options for database, and nginx install. Adds option to install RVM system-wide.
# Outputs to /root/stackscript.log
#
# <UDF name="deploy_user" Label="Name of deployment user." />
# <UDF name="deploy_password" Label="Password for deployment user." />
# <UDF name="deploy_sshkey" Label="Deployment user public ssh key." />
# <UDF name="ssh_port" Label="SSH Port" />
# <UDF name="new_hostname" Label="Server's hostname." />
@brentkirby
brentkirby / Guardfile
Created January 25, 2012 17:07
Guardfile rspec
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
rspec_opts = {
cli: '--colour --format documentation --fail-fast',
version: 2,
all_after_pass: false,
all_on_start: false,
notify: true,
keep_failed: false
@brentkirby
brentkirby / crap.sh
Created August 26, 2011 03:27
bs mdadm partition fixes when ubuntu jacks up drive letters
# Re-find partitions
partprobe
# Possibly reboot here
# double check real quick drives are back, if not partprobe again
blkid
# Re-mount
mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1
@brentkirby
brentkirby / asset_handler.rb
Created August 13, 2011 01:29
sprockets circular dependency demo
class AssetHandler < Sprockets::Environment
def initialize
Sprockets.register_engine '.scss', Tipsy::Sass::Template
super(Tipsy.root) do |env|
env.static_root = Tipsy.options.asset_path
end
Tipsy.sprockets = self
configure_paths!
configure_compass!
@brentkirby
brentkirby / mb_tiles.rb
Created August 10, 2011 23:03
Serve .mbtiles with Rack
require File.expand_path('../../../config/application', __FILE__)
require 'rack'
require 'sqlite3'
module Rack
class MbTiles
attr_reader :app
def initialize(app)
@brentkirby
brentkirby / support.js
Created July 20, 2011 18:12
quick html5 feature detect for jquery
(function(jQuery, undefined){
//
// Check an element for support of a particular attribute
function supports_attribute( attr, element, type ){
element = document.createElement( element );
exists = ( attr in element );
if( typeof type == 'undefined' || exists === false ){ return exists; }
return jQuery.type( element[attr] ) === type;
}
@brentkirby
brentkirby / vhost.rb
Created July 20, 2011 03:06
Command line vhost switcher for apache and nginx. (vhost folder -rails = symlink nginx root to "folder/public")
#!/usr/bin/env ruby
require 'optparse'
require 'ostruct'
require 'date'
class Vhost
VERSION = '0.0.1'
attr_reader :options