Skip to content

Instantly share code, notes, and snippets.

@omnicolor
omnicolor / build.xml
Created February 1, 2012 15:43
Closure unit testing build target
<target name="test-js">
<echo message="Running javascript unit tests" />
<concat destfile="tests-concat.js">
<fileset dir="tests" includes="*Test.js" />
</concat>
<exec executable="${library}/bin/calcdeps.py">
<arg value="--compiler_flag=--compilation_level=WHITESPACE_ONLY" />
<arg value="--compiler_jar=${compiler}" />
<arg value="--input=scripts/foo.js" />
<arg value="--input=tests-concat.js" />
@omnicolor
omnicolor / testRunner.js
Created February 1, 2012 15:46
Test runner for Closure unit tests
/**
* @fileoverview Test runner for running unit tests from the command line.
*
* Copyright 2012 Digital Darkness
*/
goog.require('goog.testing.jsunit');
/**
* Success or failure indications.
@omnicolor
omnicolor / UnitTestsOnCheckin.php
Created February 6, 2012 16:19
Pre-commit SVN script to run unit tests
#!/usr/local/bin/php
<?php
/**
* Pre-commit Subversion script that runs unit tests.
* @author Omni Adams <[email protected]>
* @copyright 2010 Digital Darkness
*/
/**
@omnicolor
omnicolor / SvnConflictCatcher.php
Created February 6, 2012 16:23
SVN pre-commit hook that catches conflict markers
#!/usr/local/bin/php
<?php
/**
* Pre-commit Subversion script.
* @author Omni Adams <[email protected]>
*/
/**
* Path to the awk binary.
@omnicolor
omnicolor / RB-precommit.php
Last active July 26, 2023 14:42
SVN pre-commit intergration with Review Board
#!/usr/local/bin/php
<?php
/**
* Pre-commit Subversion script.
*
* Forces the commit message to have a line like
* review: 42
* and checks that the review has received a Ship It! from
* a peer.
* @author Omni Adams <[email protected]>
@omnicolor
omnicolor / svn-lint.php
Last active August 4, 2021 19:57
Pre-commit SVN hook that runs lint
#!/usr/local/bin/php
<?php
/**
* Pre-commit Subversion script.
*
* @author Omni Adams <[email protected]>
*/
/**
@omnicolor
omnicolor / static.php
Created March 11, 2012 14:51
Static class example
/**
* Static calculator class.
*
* There's no way to dependency inject this for
* mocking it out while testing.
*/
class Calculator {
private function __construct() {}
public static function add($a, $b) {
@omnicolor
omnicolor / static-user.php
Created March 11, 2012 15:04
Class that uses static code.
class Foo {
public function addAndSquare($bar, $baz) {
$tmp = Calculator::add($bar, $baz);
return Calculator::multiply($tmp, $tmp);
}
}
@omnicolor
omnicolor / static-mockable.php
Created March 11, 2012 15:15
Refactoring static usage
class Foo {
public function addAndSquare($bar, $baz) {
$tmp = $this->add($bar, $baz);
return $this->multiply($tmp, $tmp);
}
protected function add($foo, $bar) {
return Calculator::add($foo, $bar);
}
<?php
define('RUN_ITERATIONS', 100000);
function avg($array) {
return array_sum($array) / count($array);
}
function ifseta($arr, $k, $default = null) {
return isset($arr[$k]) ? $arr[$k] : $default;
}