Skip to content

Instantly share code, notes, and snippets.

@jamesu
jamesu / deploy_www_script.sh
Created April 9, 2012 11:42
Deploy script intended to be run as a post-receive git hook
#!/bin/bash
# [app name] [old revision] [new revision]
#
GIT_REPO="/srv/app_data/repository/$1.git"
TMP_GIT_CLONE="/tmp/_deploy_$1_clone"
PUBLIC_WWW="/srv/app_data/apps/$1"
OLD_REVISION=$2
NEW_REVISION=$3
IS_RAILSAPP=false
@jamesu
jamesu / NSGoatString.h
Created March 31, 2012 20:30
NSGoatString
/*
NSGoatString
NSGoatString - a "goat" (randomly substituted) string generator.
Copyright (C) 2009 James S Urquhart
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
@jamesu
jamesu / Example.hx
Created March 19, 2012 13:43
Javascript Byte IO for haXe using ArrayBuffers
// Example usage
class Example
{
public static function test()
{
var bytes = new JSByteIO(new ArrayBuffer(128));
// Writing and reading a line
@jamesu
jamesu / redis_test.rb
Created February 19, 2012 20:27
Redis Pubsub test
# Simple redis client to test pubsub
# All clients will send the current time to 'chan'
# and print out any messages they receive.
require 'rubygems'
require 'em-hiredis'
EventMachine.run do
# Make $rl to listen
$rl = EM::Hiredis.connect
$rl.on(:message) do |channel, msg|
@jamesu
jamesu / read_tribes1dts.rb
Created February 13, 2012 23:19
Reading Tribes 1 dts files
#!/usr/bin/ruby
# Basic attempt at reading Tribes 1 .dts files
# Appears to be some sort of nested IFF-like block format
File.open(ARGV[0]) do |f|
pos = 0
while !f.eof
f.seek pos
magic = f.read(4).unpack("L<")[0]
@jamesu
jamesu / nginx_consolidate.rb
Created February 4, 2012 15:32
Consolidate nginx server logs
#!/usr/bin/ruby
# usage: nginx_consolidate.rb /var/log/nginx/*log*
#
require 'zlib'
ARGV.sort.each do |file|
if File.extname(file) == ".gz"
Zlib::GzipReader.open(file) { |f| STDOUT.write f.read }
else
@jamesu
jamesu / remove_duplicates.sh
Created February 1, 2012 15:37
Remove duplicate emails from an mbox
#!/bin/sh
formail -D 100000000 idcache < $1 -s > $1_new
@jamesu
jamesu / countbits.rb
Created January 29, 2012 14:44
Counting bits without testing every bit
# Counts bits without testing every single bit, using a simple lookup table.
# Assumes a maximum size of 32bits.
$blookup = (0..255).map do |i|
count = 0
(0..7).each { |j| count += 1 if (i>>j) & 0x1 != 0 }
count
end
# Count
@jamesu
jamesu / tiddly_to_notational.rb
Created October 8, 2011 22:07
Convert a TiddlyWiki to Notational Velocity notes
#!/usr/bin/env ruby
# Converts tiddlywki tiddlers into files which can be imported into Notational Velocity
require 'fileutils'
require 'rexml/document'
require 'time'
require 'date'
tiddlywiki_location = ARGV[0]
if tiddlywiki_location.nil?
puts "Please specify the location of your Tiddliwki"
@jamesu
jamesu / mkatlas.rb
Created September 14, 2011 21:54
Atlas generator
#!/usr/bin/env ruby
# Author: Matthias Hoechsmann, gamedrs.com
# Ported to Ruby by James Urquhart, github.com/jamesu
# Artefact Removal using Edge Copy by Patrick Wolowicz, subzero.eu
# This source code an be used freely and is provided "AS IS" without any warranties.
# Go and visit www.zombiesmash.gamedrs.com. Thank you :)
# README
# mkatlas.rb is a ruby script for generating an atlas image from individual images and a C header file with image coordinates.