Skip to content

Instantly share code, notes, and snippets.

View jamiew's full-sized avatar

Jamie Dubs jamiew

View GitHub Profile
Deploying a Rails App with EC2 + S3 + Ubuntu
============================================
Create EC2 Instance
-------------------
create new instance ami-bf5eb9d6 [http://alestic.com/](http://alestic.com/)
create new elastic ip
attach elastic ip to instance
point dns to elastic ip
// instantly implement a konami code easter-egg!!!!
// from http://static.jquery.com/files/rocker/scripts/custom.js
// where it's labeled "hehe" and would open up a javascript guitar hero (!)
if ( window.addEventListener ) {
var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
window.addEventListener("keydown", function(e){
kkeys.push( e.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 ) {
// get your konami on
// window.location = "http://ejohn.org/apps/hero/";
ffmpeg -hq -ss 00:00:00 -t 00:45:00 -i <movie.avi> -target svcd ./m1.mpg
ffmpeg -hq -ss 00:45:00 -t 00:45:00 -i <movie.avi> -target svcd ./m2.mpg
ffmpeg -hq -ss 01:30:00 -t 00:25:29 -i <movie.avi> -target svcd ./m3.mpg
CREATE TABLE `audits` (
`id` int(11) NOT NULL auto_increment,
`auditable_id` int(11) default NULL,
`auditable_type` varchar(255) default NULL,
`auditable_user_id` int(11) default NULL,
`user_id` int(11) default NULL,
`user_type` varchar(255) default NULL,
`username` varchar(255) default NULL,
`action` varchar(255) default NULL,
`changes` text,
@jamiew
jamiew / Munin Passenger Phusion Memory Stats.rb
Created October 31, 2008 18:55
munin plugin to monitor Passenger Phusion memory stats
#!/usr/bin/env ruby
# put in /etc/munin/plugins and restart munin-node
# by Dan Manges, http://www.dcmanges.com/blog/rails-application-visualization-with-munin
# NOTE: you might need to add munin to allow passwordless sudo for passenger-memory-stats
def output_config
puts <<-END
graph_category App
graph_title Passenger memory stats
graph_vlabel count
@jamiew
jamiew / passenger_status.rb
Created October 31, 2008 15:27 — forked from dan-manges/passenger_status.rb
munin plugin for Passenger Phusion process stats
#!/usr/bin/env ruby
# put in /etc/munin/plugins and restart munin-node
# by Dan Manges, http://www.dcmanges.com/blog/rails-application-visualization-with-munin
# NOTE: you might need to add munin to allow passwordless sudo for passenger-memory-stats
def output_config
puts <<-END
graph_category App
graph_title passenger status
graph_vlabel count
def sync_changesets
return unless ENABLE_SUBVERSION
begin
latest_changeset = changesets.find(:first, :select => 'revision', :order => 'revised_at DESC')
start = latest_changeset ? latest_changeset.revision.to_i + 1: 1
stop = latest_revision
return if start > stop
Changeset.transaction do
def delete_dups_for(model, collect_by)
keep_array = Hash.new { |h,k| h[k] = [] }
delete_array = []
model_name = model.name
all_objects = model.all.reverse #so we add newest first, sort of
pbar = ProgressBar.new(model_name.pluralize, all_objects.count)
all_objects.each do |obj|
if detect_dup((keep_array[obj.send(collect_by)]), obj).nil?
keep_array[obj.send(collect_by)] << obj
else
## from railscasts: http://railscasts.com/episodes/124-subdomains
# models/invitation.rb
belongs_to :sender, :class_name => 'User'
has_one :recipient, :class_name => 'User'
validates_presence_of :recipient_email
validate :recipient_is_not_registered
validate :sender_has_invitations, :if => :sender
# never render the full layout if it's an XmlHttpRequest
class ApplicationController < ActionController::Base
def render(*args)
args.first[:layout] = false if request.xhr? and args.first[:layout].nil?
super
end
end