Skip to content

Instantly share code, notes, and snippets.

View uppfinnarjohnny's full-sized avatar

Johnny Karhinen uppfinnarjohnny

View GitHub Profile
<?php
nth($what = 2, $loop = 'default') {
static $loops = array();
return ($loops[$loop] % $what == 0);
}
@uppfinnarjohnny
uppfinnarjohnny / mod_querystring.php
Created January 21, 2010 19:04
mod_querystring()
<?php
function mod_querystring($name, $value = NULL) {
$vars = $_GET;
$vars[$name] = $value;
return http_build_query($name);
}
print http_build_query(array('hej'=>'tjo', 'hepp'=>'happ','haha' => NULL));
@uppfinnarjohnny
uppfinnarjohnny / split_chunks.php
Created December 17, 2009 16:02
split_chunks
<?php
function split_chunks($input) {
$offset = 0;
foreach(array_slice(func_get_args(), 1) as $length) {
$out[] = substr($input, $offset, $length);
$offset += $length;
}
return $out;
}
<?php
class MobWrite {
protected $user = 0;
protected $file = NULL;
protected $datastore;
protected $diffengine;
public function __construct($datastore, $diffengine) {
$this->datastore = $datastore;
$this->diffengine = $diffengine;
@uppfinnarjohnny
uppfinnarjohnny / MobWritePatcher.php
Created December 5, 2009 19:20
MobWritePatcher
<?php
function MobWritePatcher($text, $patch) {
$pointer = 0;
foreach(explode("\t", $patch) as $step) {
$modifier = substr($step, 0, 1);
$argument = substr($step, 1);
switch($modifier) {
case '=':
<?php
function array_flatten(Array $array, Array $out = array()) {
foreach($array as $value)
is_array($value) ? $out = array_flatten($value, $out) : $out[] = $value;
return $out;
}