Skip to content

Instantly share code, notes, and snippets.

View jamiew's full-sized avatar

Jamie Dubs jamiew

View GitHub Profile
--- controller ---
def index
load_videos = lambda do
@videos = Video.find(...)
end
end
--- view ---
cache("...") do
load_videos
# a simple ActiveRecord->HTML table of attributes default (why isn't this builtin?)
# in the case of arrays, just do many tables
# TODO: move to a plugin or somesuch?
module ToHTML
def to_html
# FIXME TODO: things we don't want to show...
@private_attributes ||= [:id, :video_id, :user_id, :cached_tag_list, :points, :identified, :identified_at, :created_at, :service_id]
NOOOOOOOOOOOOOOOOOOOOOOO!!!!!
.-.
|_:_|
/(_Y_)\
( \/M\/ )
'. _.'-/'-'\-'._
': _/.--'[[[[]'--.\_
': /_' : |::"| : '.\
': // ./ |oUU| \.' :\
desc "Raises an error if there are pending migrations"
task :abort_if_pending_migrations => :environment do
if defined? ActiveRecord
pending_migrations = ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations
if pending_migrations.any?
puts "You have #{pending_migrations.size} pending migrations:"
pending_migrations.each do |pending_migration|
puts ' %4d %s' % [pending_migration.version, pending_migration.name]
end
#!/usr/bin/env ruby
#
# quickly lookup # of google search results for a given term
# usage: ~/bin/searchresults.rb "internet memes"
# by Jamie Wilkinson <http://jamiedubs.com>
# Free Art & Technology Lab <http://fffff.at>
require 'rubygems'
require 'mechanize'
#!/usr/bin/env ruby
# quick Google PageRank lookup
# usage: ~/bin/pagerank jamiedubs.com
# => 6
#
# by Vsevolod S. Balashov <vsevolod @ balashovREMOVETHIS.name>
# hacks/binify by Jamie Dubs <http://jamiedubs.com>
# based on 3rd party code snippets (see comments)
# TODO: make into a gem... the existing googlePR one is broken!
SELECT count(*) TABLES,
concat(round(sum(table_rows)/1000000,2),'M') rows,
concat(round(sum(data_length)/(1024*1024*1024),2),'G') DATA,
concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
FROM information_schema.TABLES;
# setting up an R&D slice
# 1st things first, copy over our bash & screen config...
# TODO:
# bootstrap
apt-get update -y && apt-get upgrade -y
apt-get install -y build-essential git-core
apt-get install -y apache2 apache2-prefork-dev postfix imagemagick
#!/usr/bin/env ruby
# sup luke; jdubs here
# - put the docs and helper scripts inline for syntax highlighting joy
# - added another crontab example -- I like to file once/day.
# plays nice with treating the Desktop like a daily scratchpad
# - added a 'Yesterday' link in addition to Today
# - minor tweaks around town
## config
HOME_DIRECTORY = "~" # this will
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