Skip to content

Instantly share code, notes, and snippets.

View dan-watson's full-sized avatar
🏠
Working from home

Daniel Watson dan-watson

🏠
Working from home
  • MASSOLIT
  • London
  • 14:26 (UTC)
View GitHub Profile
@dan-watson
dan-watson / For Mike
Created January 31, 2012 10:59
Node Server Setup
#Nginx
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/$(uname -m)/epel-release-5-3.noarch.rpm
yum install nginx
▪ Default config file: /etc/nginx/nginx.conf
▪ Default SSL config file: /etc/nginx/conf.d/ssl.conf
▪ Default virtual hosting config file: /etc/nginx/conf.d/virtual.conf
▪ Default documentroot: /usr/share/nginx/html
@dan-watson
dan-watson / gist:1391566
Created November 24, 2011 15:19
Stopping the abstract class being saved. ActiveRecord STI
class Node < ActiveRecord::Base
before_save :abstract_class?
col :title, :length => 100
col :description, :as => :text
col :assumptions, :as => :text
col :type, :length => 20
col :project, :as => :belongs_to, :index => true
timestamps
@dan-watson
dan-watson / gist:1391079
Created November 24, 2011 10:47
Active Enum Is AWESOM-O
class TimeUnit < ActiveEnum::Base
value :id => 1, :name => 'Days'
value :id => 2, :name => 'Weeks'
value :id => 3, :name => 'Months'
value :id => 4, :name => 'Quaters'
value :id => 5, :name => 'Years'
end
class Project < ActiveRecord::Base
col :name, :limit => 100
@dan-watson
dan-watson / gist:1388651
Created November 23, 2011 13:25
Key value store for application settings with type casting
class Application < ActiveRecord::Base
set_table_name "application_settings"
col :key, :limit => 50
col :value, :limit => 100
def self.method_missing(method, *args, &block)
return self.send method, *args, &block if self.respond_to? method
if method.to_s =~ /=/
@dan-watson
dan-watson / Rakefile
Created November 18, 2011 16:41
Bulk migration for mini_record
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
namespace :db do
desc "Auto migration of database"
task :migrate do
Dir["app/models/*.rb"].each do |file_path|
basename = File.basename(file_path, File.extname(file_path))
clazz = basename.camelize.constantize
clazz.auto_upgrade!
@dan-watson
dan-watson / gist:1312013
Created October 25, 2011 09:25
Fixing Filenames With Spaces
has_attached_file :file, :styles => lambda { |media_file| media_file.instance.media_type == 'image' ? IMAGE_VERSIONS : {} },
:storage => :s3,
:path => ":storage_path",
:bucket => lambda{ |media_file| media_file.instance.bucket_name },
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:url => ":s3_eu_url"
before_save :normalize_file_file_name
# == Filename helper