Skip to content

Instantly share code, notes, and snippets.

View andrewmackrodt's full-sized avatar
😴

Andrew Mackrodt andrewmackrodt

😴
View GitHub Profile
@andrewmackrodt
andrewmackrodt / gdiff.php
Last active August 29, 2015 14:03
Produces a coloured git diff with options to exclude paths and output to html
#!/usr/bin/env php
<?php
function ansi2html($text) {
return preg_replace('/\x1B\[m/', '', preg_replace_callback('/\x1B\[(\d+)m(.*?)\x1B\[m/m', function ($match) {
switch ($match[1]) {
case 31: $rgb = array(170, 0, 0); break;
case 32: $rgb = array(0, 170, 0); break;
case 36: $rgb = array(0, 170, 170); break;
default: $rgb = array(0, 0, 0);
}
<?php
$shm = shm_attach(ftok(__FILE__, 'p'), 1024, 0640);
shm_put_var($shm, 0, '');
$sem = sem_get(ftok(__FILE__, 'p'), 1, 0640, 1);
for ($i = 0; $i < 10; $i++) {
if (0 === ($pid = pcntl_fork())) {
$pid = posix_getpid();
<?php
function format_array(array $array, $cols = 4, $maxCols = 120, $itemPadCols = 4, $indentCols = 4) {
if (empty($array)) {
return null;
}
$itemMaxCols = floor(($maxCols - ($cols * $itemPadCols) - $indentCols) / $cols);
$lines = array('');
<?php
/**
* @param object $source The source object to retrieve references from
* @param mixed $target [Optional]
* <table>
* <tr><td> object </td><td> The destination object to copy references to </td></tr>
* <tr><td> string </td><td> The scope to access $source properties,
* e.g. a parent class to get private properties </td></tr>
* <tr><td> array </td><td> See $map </td></tr>
class Command {
private static $descriptorSpec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w'));
private static $shellCache = array();
private $command;
private $shell;
#!/usr/bin/env php
<?php if (PHP_SAPI !== 'cli') die('cli access only');
$host = '127.0.0.1';
$port = mt_rand(31000, 60000);
$dir = locate_webroot();
if (!$dir) {
echo "Error: Could not locate the web root\n";
echo sprintf("Usage: php %s /var/www/html\n", __FILE__);
$build_array_text = function (array $array, $indent = 4, $space = " ", $depth = 0) use (&$build_array_text) {
$string = "array(\n";
$keys = array_keys($array);
$assoc = array_keys(array_fill(0, count($array), null)) !== $keys;
$lastK = $keys[count($array) - 1];
foreach ($array as $k => $v) {
$string .= str_repeat($space, $indent * ($depth + 1)) . ($assoc ? "'$k' => " : "") .
(is_array($v) ? $build_array_text($v, $indent, $space, $depth + 1) :
(is_bool($v) ? ($v ? "true" : "false") :
(is_numeric($v) ? $v : "'" . addslashes($v) . "'"))
<?php return trigger_error('UOPZ IDE helper should not be loaded', E_USER_WARNING);
// The following opcodes are defined as constants by uopz:
/**
* Invoked by exit() and die(), recieves no arguments. Return boolean TRUE to exit, FALSE to continue
*/
define('ZEND_EXIT', 79);
/**
SELECT
c.*,
fk.fk_table_schema,
fk.fk_table_name,
fk.fk_column_name,
fk.constraint_name fk_constraint_name
FROM (
SELECT
table_catalog,
table_schema,
#!/usr/bin/env php
<?php
/**
* Generates a naturally sortable UUID in a distributed environment.
* UUID's are 120-bit represented in base62 as 20 in length and are composed of:
* - a time stamp in microseconds (from 1970-01-01 until 3180-01-01; ~1,200 years if using a custom epoch)
* - the machine's MAC address
* - the running process' id
*/
class UniqueId {