Skip to content

Instantly share code, notes, and snippets.

View jeffgca's full-sized avatar

Jeff Griffiths jeffgca

View GitHub Profile
@jeffgca
jeffgca / is_assoc.php
Created March 1, 2011 22:59
handy function to test the associative-ness of an array in PHP.
<?php
function is_assoc($arr) {
return array_keys($arr) !== range(0, count($arr) - 1);
}
@jeffgca
jeffgca / run_script_bash_build.xml
Created March 9, 2011 18:49
A snippet for how to run a shell script via bash in ant. This can be helpful in adding environment variables to your ant build when executed in a strange environment like a Jenkins build.
<target name="phpunit">
<exec dir="${basedir}" executable="bash" newenvironment="false" failonerror="true">
<arg value="somescript.sh"/>
</exec>
</target>
@jeffgca
jeffgca / phpunit.sh
Created March 9, 2011 18:50
Shell script to run via ant to actually run the PHPUnit tests run and avoid segfaults caused by code coverage issues with gc and xdebug.
#!/bin/bash
# this mitigates this issue with Xdebug, PHPUnit, code coverage and Rediska:
# http://bugs.xdebug.org/view.php?id=670
export USE_ZEND_ALLOC=0
/usr/bin/phpunit --configuration tests/phpunit.xml --log-junit build/logs/junit.xml --coverage-clover build/logs/clover.xml tests
@jeffgca
jeffgca / node-install.sh
Created April 6, 2011 20:26
Gets the latest node installed into ~/local.
#!/bin/bash
NODE=`which node`
if [ -z "$NODE" ]; then
echo "no node on path?"
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
fi
function webGLStart() {
cJ = document.getElementById("game-canvas");
!cD(cJ) || (cK = document.getElementById("ctrl-canvas"), cL = cK.getContext("2d"), cP(null, !0), cN.showStartScreen(cL), cE.init($("#shadersFrame").contents().find("#phong-fs"), $("#shadersFrame").contents().find("#phong-vs")), window.onresize = cP, $("#fpsui").text("FPS: 0"), cl("models/bikePlayer2.json", "inlined", "bike", ck), cl("models/lifeWheel.json", "indexed", "life", ck), cb.explode = {
ring: {}
}, Y(cb.explode), bY(), WebGLUtils.requestAnimationFrame(cJ, cA), setInterval(cB, 1e3))
}
function cP(a, b) {
var c = 20;
drawDiv = document.getElementById("canvas-container");
var d = Math.round(drawDiv.offsetWidth / c) * c;
@jeffgca
jeffgca / sha1.cs
Created April 12, 2011 17:23
static method that behaves just like PHP, etc.
/// <summary>
/// plain string -> sha1 string implementation, behaves identically to php's sha1() function.
/// </summary>
/// <param name="input">
/// A <see cref="System.String"/>
/// </param>
/// <returns>
/// A <see cref="System.String"/>
/// </returns>
public static string sha1(string input) {
@jeffgca
jeffgca / s3.py
Created April 18, 2011 20:40
Slightly altered S3.py library, now it doesn't whine about hashlib > sha. Originally from http://aws.amazon.com/code/134?_encoding=UTF8&jiveRedirect=1
#!/usr/bin/env python
# This software code is made available "AS IS" without warranties of any
# kind. You may copy, display, modify and redistribute the software
# code either by itself or as incorporated into your code; provided that
# you do not remove any proprietary notices. Your use of this software
# code is at your own risk and you waive any claim against Amazon
# Digital Services, Inc. or its affiliates with respect to your use of
# this software code. (c) 2006-2007 Amazon Digital Services, Inc. or its
# affiliates.
@jeffgca
jeffgca / scriptdir.sh
Created May 6, 2011 22:19
Get the current script's directory
SCRIPTDIR=$(cd `dirname $0` && pwd)
@jeffgca
jeffgca / fib.py
Created May 12, 2011 04:16
Fibonacci sequence generator
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-c",
"--count",
dest="count",
help="how many?.",
default=10
)
(options, args) = parser.parse_args()
@jeffgca
jeffgca / xor.js
Created May 20, 2011 18:09
cheesy string xor'ing
var sys = require('sys');
var L = function(str) {console.log(str)}
function xor_str(subject, key) {
var the_res = "";
for (i = 0; i < subject.length; i++) {
var cur = key.charCodeAt((i % key.length));
var c = String.fromCharCode(cur ^ subject.charCodeAt(i));
the_res += c;
}