Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / ticket.rb
Created April 26, 2012 19:46
Amiando ticket script.rb
# Script to automate reserving tickets from amiando.
# Polls the site using chromedriver, automatically selecting 1 ticket
# and moving to the next step.
#
# Please use responsibly.
#
require 'rubygems'
require "selenium/webdriver"
@jamesu
jamesu / dtmf_generate.c
Created August 8, 2012 17:17
Generate DTMF tones
//
// Generate DTMF tones
//
#include <stdio.h>
#include <math.h>
float OutData[44100];
typedef struct ToneInfo {
@jamesu
jamesu / TSFunctionsVsVariables.cs
Created September 17, 2012 14:09
TorqueScript: Function Parameters vs Variables
//
// TorqueScript: Function Parameters vs Variables
//
// This simple demonstration illustrates the speed difference in
// passing function parameters as variables vs using the string stack, in a simple function
// which adds two numbers together.
//
// scriptTest1 technically incurs a penalty of converting the input variables to strings, while
// scriptTest2 instead looks up and assigns global variables.
// scriptTest3 which re-assigns variables in the function call is included to gauge
@jamesu
jamesu / perl5_benchmark.pl
Created September 21, 2012 09:41
TorqueScript Benchmarking Reference Code
#!/usr/bin/perl
use Time::HiRes qw ( time );
my $PR = 0;
my $P0 = 0;
my $P1 = 0;
print "ENTRY\n";
@jamesu
jamesu / example_engineapi.cpp
Created September 25, 2012 08:46
Using the EngineAPI in Torque3D
// Note you will need to create a "getFunctionAddress" function in EngineFunctionInfo unless you use
// getProcAddress() & getBindingName() on the function exports.
void *getFunctionAddress() { return mAddress; }
//
// This example demonstrates the following:
// * calling "generateUUID" which is exported as a global function in the API.
// * constructing an instance of ColorI and setting its exposed fields.
//