Skip to content

Instantly share code, notes, and snippets.

View grahamg's full-sized avatar

Graham Greenfield grahamg

View GitHub Profile
import urllib, urllib2
def getsource(pagereq):
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
header = {'User-Agent': user_agent}
req = urllib2.Request(pagereq, None, header)
response = urllib2.urlopen(req)
page = response.read()
return page
(function (a) {
a.browserTest = function (e, g) {
var f = "unknown",
d = "X",
b = function (k, j) {
for (var c = 0; c < j.length; c = c + 1) {
k = k.replace(j[c][0], j[c][1])
}
return k
},
/* begin table creation */
create table department
(dept_id smallint unsigned not null auto_increment,
name varchar(20) not null,
constraint pk_department primary key (dept_id)
);
create table branch
(branch_id smallint unsigned not null auto_increment,
@grahamg
grahamg / lisp.rb
Created September 4, 2010 20:30 — forked from dahlia/lisp.rb
# 30 minutes Lisp in Ruby
# Hong MinHee <http://dahlia.kr/>
#
# This Lisp implementation does not provide a s-expression reader.
# Instead, it uses Ruby syntax like following code:
#
# [:def, :factorial,
# [:lambda, [:n],
# [:if, [:"=", :n, 1],
# 1,
#include <stdio.h>
/* BEGIN HACKERY */
typedef struct field {
enum {
TABLE_NAME,
TABLE_FIELD,
TABLE_TERMINATOR
} tag;
@grahamg
grahamg / gist:825365
Created February 14, 2011 01:16
Rsync Backup Script
#!/bin/bash
# Destination host machine name
DEST="beta.grahamg.org"
# User that rsync will connect as
# Are you sure that you want to run as root, though?
USER="remote_backup"
# Directory to copy from on the source machine.
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Backbone example</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="underscore.js"></script>
<script type="text/javascript" src="backbone.js"></script>
@grahamg
grahamg / CoffeePot.rb
Created March 17, 2011 09:09
CoffeePot example class in Ruby complete with Test::Unit tests.
#!/usr/bin/env ruby
=begin
1) When I create a "CoffeePot" object, it should be empty and I will know this because it returns true when I ask it "coffee_pot.is_empty?", and it tells me 0 when I ask it "coffee_pot.cups_left"
2) When I call the "coffee_pot.fill" method it should change state to have 10 cups left in it, so when I call the "coffee_pot.cups_left" method it returns 10. If I ask "coffee_pot.is_empty?", it should return false.
3) every time I call the "coffee_pot.pour_cup" method, there should be one less cup remaining.
4) if I call "coffee_pot.pour_cup" when the pot is empty, it should raise an exception.
@grahamg
grahamg / Linux Command Reference
Created April 3, 2011 02:53
A List that I often refer to for useful commands for debugging Linux systems.
Plesk port: 8443
R1Soft CDP port: 1167
cPanel port: WHM over SSL = 2087
cPanel over SSL = 2083
regular WHM = 2086
regular cPanel = 2082
feedback loop information:
http://www.eliteemail.com/features/email-delivery/feedback-loops/
@grahamg
grahamg / ftp_backup.sh
Created April 13, 2011 01:54
Backup some selected .tar.gz files to a remote ftp server
#!/bin/bash
FTPU="user" # ftp login name
FTPP="passwd" # ftp password
FTPS="ftp.server.com" # remote ftp server
FTPF="/home/backup/" # remote ftp server directory for $FTPU & $FTPP
LOCALD="backup.$(date +%d.%m.%y).tgz"
ncftpput -m -u $FTPU -p $FTPP $FTPS $FTPF $LOCALD