Skip to content

Instantly share code, notes, and snippets.

View cbandy's full-sized avatar

Chris Bandy cbandy

View GitHub Profile
<?php
/**
* Kohana_Sniffs_Classes_OpeningBraceBsdAllmanSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
@cbandy
cbandy / array_references.php
Created January 26, 2011 20:29
Demo copying references within array
<?php
error_reporting(E_ALL | E_STRICT);
$array = array();
$var = 5;
$array[0] =& $var;
// visible reference
@cbandy
cbandy / curl.php
Created March 10, 2011 20:57
cURL wrapper object
<?php
/**
* Wrapper around PHP's procedural API
*/
class Kohana_cURL
{
public static function factory(string $url = NULL)
{
// Raises E_WARNING upon error
@cbandy
cbandy / git-revert-whitespace.sh
Created March 16, 2011 17:07
Undo trailing whitespace changes in working copy
#!/bin/sh
#
patch=$( mktemp .tmp.git.XXXXXX )
git diff --ignore-space-at-eol $@ > $patch
if [ $? -eq 0 ]; then
# detect EOF change
@cbandy
cbandy / cbandy.php
Created March 29, 2011 14:24
Undefined constant E_NOTICE fails a test
<?php
class Cbandy_Test extends PHPUnit_Framework_TestCase
{
public function test_case()
{
// PHPUnit 3.4.13, 1 error
UNDEF_CONST;
}
}
@cbandy
cbandy / code_coverage.php
Created June 7, 2011 16:45
line 6: EXT_STMT + NOP shows as executable
<?php
xdebug_start_code_coverage(XDEBUG_CC_UNUSED);
class MyClass
{
}
print_r(xdebug_get_code_coverage());
@cbandy
cbandy / code_coverage.php
Created June 8, 2011 16:04
line 7: bool_not, free
<?php
xdebug_start_code_coverage(XDEBUG_CC_UNUSED);
! (0 === 1)
;
print_r(xdebug_get_code_coverage());
@cbandy
cbandy / gist:1047753
Created June 26, 2011 16:43
SQL merge/upsert
-- CREATE TABLE kohana_test_table (id integer PRIMARY KEY, value integer)
-- MS SQL Server, PostgreSQL, SQLite: conditional insert
INSERT INTO kohana_test_table (id, value)
SELECT 10, 100
WHERE NOT EXISTS
(SELECT 1 FROM kohana_test_table WHERE id = 10)
-- MySQL: conditional insert
INSERT INTO kohana_test_table (id, value)
@cbandy
cbandy / memory.php
Created June 27, 2011 04:18
For per-request caching, #4065
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Non-persistent, in-memory implementation of [Kohana Cache](api/Kohana_Cache).
*
* @package Kohana/Cache
* @category Base
* @author Kohana Team
* @copyright (c) 2011 Kohana Team
* @license http://kohanaphp.com/license
@cbandy
cbandy / code_coverage.php
Created July 1, 2011 06:07
line 7: zend_isset_isempty_var
<?php
xdebug_start_code_coverage(XDEBUG_CC_UNUSED);
class c { function f() {} function __construct() {
$this->f(
empty($var)
? 1
: 2
);