Skip to content

Instantly share code, notes, and snippets.

Verifying that "omnicolor.id" is my Blockstack ID. https://explorer.blockstack.org/name/omnicolor.id
@omnicolor
omnicolor / headers.php
Created February 23, 2015 21:16
Unit testing headers with PHPUnit
<?php
/**
* Class that tries to send a header.
*/
class SendsHeaders {
/**
* Send a header to the user's browser.
*/
public function sendHeader() {
header('This is a header', true, 400);
@omnicolor
omnicolor / keybase.md
Created March 23, 2014 16:30
Keybase verification

Keybase proof

I hereby claim:

  • I am omnicolor on github.
  • I am omnicolor (https://keybase.io/omnicolor) on keybase.
  • I have a public key whose fingerprint is EF78 5682 8AE3 D8FD B624 313B 3689 111F 424A 292A

To claim this, I am signing this object:

<?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;
}
@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);
}
@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.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 / 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 <omni@digitaldarkness.com>
*/
/**
@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 <omni@digitaldarkness.com>
@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 <omni@digitaldarkness.com>
*/
/**
* Path to the awk binary.