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
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 / 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]
@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 / 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: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 / 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 %>
$(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
{
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
@djgraham
djgraham / battery_info.sh
Created December 5, 2011 13:45
Bash script for linux to show you how worn your battery is
#!/bin/bash
bats=`ls /proc/acpi/battery/`;
for bat in $bats;do
remain=`cat /proc/acpi/battery/$bat/{info,state}|grep remaining|grep -o "[0-9]\+"`
full=`cat /proc/acpi/battery/$bat/{info,state}|grep full |grep -o "[0-9]\+"`
descap=`cat /proc/acpi/battery/$bat/{info,state}|grep "design capacity:" |grep -o "[0-9]\+"`
rate=`cat /proc/acpi/battery/$bat/{info,state}|grep "present rate:" |grep -o "[0-9]\+"`
state=`cat /proc/acpi/battery/$bat/{info,state}|grep "charging state:" |grep -o "[a-z]\+$"`
echo $state;
lostcap=$((((descap-full)*100)/descap));
@djgraham
djgraham / payment.rb
Created January 10, 2012 13:45
payment.rb
# the wrong way..
class Payment < ActiveRecord::Base
belongs_to :booking
after_save :update_booking
def update_booking