Skip to content

Instantly share code, notes, and snippets.

View timwhitlock's full-sized avatar

Tim Whitlock timwhitlock

View GitHub Profile
@timwhitlock
timwhitlock / guzzle-model-arrays.php
Created February 11, 2014 16:25
Testing ways to wrap guzzle models in a typed array
<?php
use Guzzle\Http\Message\Response;
use Guzzle\Plugin\Mock\MockPlugin;
use Guzzle\Service\Client;
use Guzzle\Service\Description\ServiceDescription;
use Guzzle\Service\Resource\Model;
use Guzzle\Tests\GuzzleTestCase;
/**
@timwhitlock
timwhitlock / AssetManager.php
Created August 19, 2014 20:34
Exposes source maps to dynamic Assetic routes in debug mode
<?php
namespace my\TestBundle\Assetic;
use Assetic\Factory\LazyAssetManager;
/**
* Overridden asset manager that exposes source maps referenced in CSS and JS
*/
class AssetManager extends LazyAssetManager {
@timwhitlock
timwhitlock / example.php
Created October 22, 2014 10:25
Warn that deprecated WPLANG constant will be ignored
<?php
/**
* display warning in Wordpress admin that WPLANG constant will be ignored
*/
is_admin() and add_action( 'admin_notices', function(){
if( defined('WPLANG') && WPLANG && 3 < (int) $GLOBALS['wp_version'] ){
echo '<div class="error"><p><strong>Warning</strong> <code>WPLANG</code> is deprecated and should be removed from wp-config.php</p></div>';
}
} );
@timwhitlock
timwhitlock / iterator-quirks.php
Created May 22, 2015 08:34
Shows the behaviour of array pointer functions called on custom Iterator objects
<?php
/**
* A warning to myself that custom iterators cannot entirely masquerade as native arrays for legacy code compatibility:
*
* - Custom classes implementing the Iterator interface work with `foreach`, but not with native array pointer functions.
* - Built-in iterators do work with `current`, `key` and `next` but the iterator methods cannot be overridden in subclasses.
*/
/**
@timwhitlock
timwhitlock / dos2unix.sh
Created August 4, 2015 06:04
Simple dos2unix script
#!/bin/bash
# Actually just strips carriage returns
cp -p "$1" "$1.dos"
tr -d '\r' < "$1.dos" > "$1"
rm -f "$1.dos"
var undefined = true;
/**
* Reverse a string
* @param String original string
* @return String new string
*/
function stringReverse( s ){
var r = '';
while( s ){
r += s.substr(-1,1);
s = s.slice(0,-1);
/**
* Reverse a string
* @param String original string
* @return String new string
*/
function stringReverse( s ){
var r = '', i = 0, n = - s.length;
while( i > n ){
r += s.substr(--i,1);
}
/**
* String reverse bench test script.
* Runs in javascript shell, see print() function
*/
/** make a 1MB string */
function bigString(){
var s = '';
curl http://api.foursquare.com/v1/venue.json?vid=154655 \
| php -r "var_dump(json_decode(file_get_contents('php://stdin')));" \
| less;