Skip to content

Instantly share code, notes, and snippets.

View andrewmackrodt's full-sized avatar
😴

Andrew Mackrodt andrewmackrodt

😴
View GitHub Profile
@andrewmackrodt
andrewmackrodt / gist:5848583
Created June 24, 2013 08:33
Terminal Commands
# delete archived log files
sudo find . -type f -regextype posix-extended -iregex '.+\.(bz2|[gx7]z|old|zip|[0-9])' -delete
@andrewmackrodt
andrewmackrodt / proxy.bat
Created August 19, 2013 10:35
Launch Google Chrome on Windows using a Socks 5 Proxy Connection
@echo off
echo.
:: set the local (dynamic) port for the Socks5 proxy
set lport=3128
:: ssh details
set rport=22
set username=andrew
set hostname=myproxy.tld
@andrewmackrodt
andrewmackrodt / pstormup
Last active March 3, 2020 17:28
Download, extract and symlink the latest version of PhpStorm on Linux.
#!/usr/bin/env php
<?php
/**
* $extractPath must be writable by the user account used to launch this script
*/
$extractPath = '/opt/.phpstorm';
$versionPage = 'https://data.services.jetbrains.com/products/releases?code=PS&latest=true&type=release&_=' . time();
#region Functions
@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('');
#!/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 {
<?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>
#!/usr/bin/env php
<?php
// strip shebang for html requests
if (ob_get_level()) ob_end_clean();
if (PHP_SAPI === 'cli') {
$host = '127.0.0.1';
$port = mt_rand(31000, 60000);
$ffAllowPopup = true;
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;