Skip to content

Instantly share code, notes, and snippets.

View Aupajo's full-sized avatar

Pete Nicholls Aupajo

  • Christchurch, New Zealand
View GitHub Profile
@Aupajo
Aupajo / gist:73669
Created March 4, 2009 02:16
config.ru for drewolson
$:.unshift File.dirname(__FILE__)
require 'sinatra'
require 'site.rb'
ENV['RACK_ENV'] = 'production'
run Sinatra::Application
@Aupajo
Aupajo / application.js
Created March 16, 2009 22:29
jQuery HTTP DELETE links
$(document).ready(function() {
$('.delete').click(function() {
if(confirm('Are you sure?')) {
var f = document.createElement('form');
$(this).after($(f).attr({
method: 'post',
action: $(this).attr('href')
}).append('<input type="hidden" name="_method" value="DELETE" />'));
$(f).submit();
}
@Aupajo
Aupajo / method.rb
Created March 19, 2009 01:30
Random find record in DataMapper
# Picks a random record from a DataMapper resource. If no records are present, it returns nil.
def self.random
all.length > 0 ? (get(rand(all.length) + 1) || random) : nil
end
@Aupajo
Aupajo / self-esteem-bot.rb
Created April 1, 2009 01:50
IRC bot to make me feel better about myself
require 'isaac'
configure do |c|
c.nick = "BotFace"
c.server = "irc.freenode.net"
c.port = 6667
end
sayings = [
'Pete is awesome.',
$ dig sinatrarb.com
; <<>> DiG 9.4.2-P2 <<>> sinatrarb.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44991
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;sinatrarb.com. IN A
@Aupajo
Aupajo / twat.rb
Created April 6, 2009 01:40 — forked from fauxparse/twat.rb
#!/usr/bin/env ruby
# Find common Twitter friends
# Usage: ./twat.rb user1 user2 ...
lists = ARGV.inject({}) do |hash, username|
page = 0
while !(output = `curl -s http://twitter.com/statuses/friends/#{username}.xml?page=#{page += 1} | grep "<screen_name>"`.gsub(%r{</?screen_name>}, '').split).empty?
hash[username] = ((hash[username] || []) + output).sort
end
hash
require 'rubygems'
require 'sinatra'
require 'dm-core'
require 'user.rb'
enable :sessions
configure :development do
DataObjects::Sqlite3.logger = DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/development.sqlite3")
@Aupajo
Aupajo / Graphviz.php
Created April 26, 2009 10:02
Graphviz MediaWiki hack for anti-aliased dot with the help of ImageMagick's convert.
<?php
# CoffMan (http://www.wickle.com) code adapted from timeline extension.
# Timeline extension
# To use, include this file from your LocalSettings.php
# To configure, set members of $wgGraphVizSettings after the inclusion
class GraphVizSettings {
var $dotCommand;
};
@Aupajo
Aupajo / coda.sh
Created April 26, 2009 10:59
Coda from the command line
#!/bin/bash
# Open/create a file in Coda, open a folder, or just open Coda.
if [ -n "$1" ]; then
if [ ! -f $1 ]; then
touch $1
fi
fi
open $1 -a /Applications/Coda.app
@Aupajo
Aupajo / trash.sh
Created April 26, 2009 11:01
Use Mac OS X Trash instead of rm
#!/bin/bash
mv $1 ~/.Trash