Skip to content

Instantly share code, notes, and snippets.

View djgraham's full-sized avatar
:shipit:
Oh hello!

David Graham djgraham

:shipit:
Oh hello!
View GitHub Profile
1.upto(100) do |i|
string = ""
string+= "Fizz" if i % 3 == 0
string+= "Buzz" if i % 5 == 0
string+= i.to_s if string.empty?
puts string
end
$(document).ready(function(){
//$('form input[type="text"]:first').attr("tabindex", 1);
var first_field = ($('form input[type="text"]:first').attr('name'));
var form = ($('form:first').attr('id'));
//alert (form + "- " + first_field);
if (first_field == "task[due_date]") {
$('form textarea:first').focus();
}
else
{
@djgraham
djgraham / application.html.erb
Created March 4, 2011 10:47
Shove a quick black banner at the top of your page when you're on a server other than production...
<% if Rails.env != "production" %>
<div id="staging-server" style="background: #000; text-align: center; color: #FFF; font-size: 16px; font-weight: bold; text-transform: none; padding: 10px 0;">You are currently using the <%= Rails.env.capitalize %> server</div>
<% end %>
@djgraham
djgraham / gist:831959
Created February 17, 2011 15:50
Going from vanilla Ubuntu server to (almost) full install of vanilla ruby 1.9.2, gem, rails, passenger, nginx, mysql, git, etc.
login as root or sudo -s..
1) apt-get update
2) apt-get upgrade
(probably need a reboot after this)
3) apt-get install gcc bison zlibc build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev libcurl4-openssl-dev git-core mysql-server libmysqlclient-dev
4) wget ruby source to local directory
5) tar -zxvf downloaded file
6) cd newly_created_ruby_directory
7) ./configure
@djgraham
djgraham / gist:831763
Created February 17, 2011 13:57
/etc/apache2/conf.d/php-fastcgi
<IfModule mod_fcgid.c>
AddHandler fcgid-script .php
DefaultMaxClassProcessCount 4
DefaultInitEnv PHP_FCGI_MAX_REQUESTS 0
DefaultInitEnv PHP_FCGI_CHILDREN 0
FCGIWrapper /usr/bin/php-cgi .php
<Files *.php>
Options +ExecCGI
</Files>
</IfModule>
@djgraham
djgraham / gist:802296
Created January 29, 2011 23:01
square software engineer spec example
class Payment
attr_accessor :amount
def initialize (x)
self.amount = amount
end
def fee_amount
(((2.9 * (self.amount * 100)) / 100) + 15).round.to_f/100
end
@djgraham
djgraham / smartctl_output.txt
Created January 17, 2011 17:32
SMART output of borked Seagate 1Tb SATA disc :(
[root@dora video]# smartctl -a /dev/sdd
smartctl version 5.37 [i686-redhat-linux-gnu] Copyright (C) 2002-6 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF INFORMATION SECTION ===
Device Model: ST31000528AS
Serial Number: 5XXXXXXX
Firmware Version: CC44
User Capacity: 1,000,204,886,016 bytes
Device is: Not in smartctl database [for details use: -P showall]
class MyModel < ActiveRecord::Base
def self.columns
@columns ||= []
end
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default,
sql_type.to_s, null)
end
@djgraham
djgraham / email.rb
Created June 24, 2010 13:24
Parsing multipart message bodies with Tmail in ruby
# the usual disclaimers apply, this may or may not work for you, and it's rather hacky, but works for me(tm) :)
# first parse the mail
mail = TMail::Mail.parse(params[:email])
# parse the mail (as below)
email.body = Email.get_multipart_body(mail)
# in your model...
CACHE = MemCache.new(:namespace => "cheese")
CACHE.servers = '127.0.0.1:11211'