Skip to content

Instantly share code, notes, and snippets.

@will0
will0 / example-usage.php
Created October 1, 2012 16:20
Testables
function asserteq($lhs, $rhs) {
if($lhs != $rhs)
exit "$lhs != $rhs";
}
if(LOCAL)
$foo = new foo_direct(getenv('FOO_DB_STUFF'));
else
$foo = new foo_http(getenv('FOO_ENDPOINT'));
@will0
will0 / linkedlist.php
Last active December 10, 2015 22:38
coding for interviews 2013 01 03, PHP solution
<?php
class Slist {
var $data = NULL;
var $next = NULL;
function __construct($data, $next) {
$this->data = $data;
$this->next = $next;
}
@will0
will0 / gist:4601560
Last active December 11, 2015 12:38
CFI 2013 Jan 22 - Tries and a system to recommend completions for words Prefix tries don't seem to come up much for me, but its nice to play with them. The biggest advantage I see to tries is the structural sharing aspect - you can represent a set of string-like data without having to repeat the shared pieces, so if your data plays nicely and ha…
class Node:
def __init__(self):
self.terminal = False
self.suffixes = {}
def update(node, suffix):
for c in suffix:
if c not in node.suffixes:
node.suffixes[c] = Node()
node = node.suffixes[c]
@will0
will0 / mm.php
Created March 12, 2013 16:11
PHP Functions with "hooks" to add before, after, and around actions/fixers/filters/exception handlers/listeners/whatevers
<?php
/**
* MegaMethods
* ===========
*
* They do stuff, on steroids
**/
namespace MM;
@will0
will0 / pipeall.js
Created March 15, 2013 05:15
these must be those fibers people are talking about
function pipeall(array) {
var chain = [];
var next;
var next_val = 0;
var tramp = function(result) {
var stage = chain[--next];
var fn;
if(next) {
fn = function() {
stage(result, tramp);
@will0
will0 / acf-cache-workaround.php
Created April 8, 2014 02:57
acf cache workaround
<?php
call_user_func(function(){
$purge = function ($post_id) {
if ('acf' === get_post_type($post_id) && !wp_is_post_revision($post_id)) {
wp_cache_delete('field_groups', 'acf');
}
return $post_id;
};