This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
exec('git diff --name-only --diff-filter=ACM --cached', $files); | |
$status = 0; | |
foreach ($files as $file) { | |
if (pathinfo($file, PATHINFO_EXTENSION) != 'php') continue; | |
$file = escapeshellarg($file); | |
$message = array(); | |
exec("git show :$file | php -l 2>&1", $message, $code); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ip -6 -o addr | grep -P -o 2001:0:[^/]+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sleep ${1:-25}m | |
notify-send -i clock 'Time is up' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function byte2($bytes) { | |
$size = array('B','KB','MB','GB','TB'); | |
$factor = floor(log($bytes, 1024)); | |
$format = $factor > 2 ? '%.1F %s' : '%u %s'; | |
return sprintf($format, $bytes / pow(1024, $factor), $size[$factor]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function similar_text_shingles($texts, $shingle_len = 10, $algo = 'md5') { | |
$c = count($texts); | |
$total = 0; | |
for ($i = 0; $i < $c; $i++) { | |
preg_match_all('#\w{4,}#u', mb_strtolower($texts[$i], 'utf-8'), $matches); | |
$words = $matches[0]; | |
$cc = count($words) - $shingle_len; | |
for ($j = 0; $j < $cc; $j++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FSStorage { | |
protected $dir; | |
public function __construct($dir) { | |
$this->dir = $dir; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
$argv += [1 => 'localhost', 2 => 11211]; | |
$memcached = new Memcached; | |
$memcached->addServer($argv[1], $argv[2]); | |
$result = []; | |
foreach($memcached->getAllKeys() as $k) $result[$k] = $memcached->get($k); | |
var_export($result); | |
echo ";\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$server = stream_socket_server('tcp://127.0.0.1:8000'); | |
while (true) { | |
$client = stream_socket_accept($server, -1); | |
if (pcntl_fork() === 0) { | |
stream_copy_to_stream($client, $client); | |
die; | |
} | |
fclose($client); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
$data = file_get_contents('php://stdin'); | |
preg_match('#^To:(.*)#i', $data, $matches); | |
$filename = tempnam('/tmp', trim($matches[1]) . '_'); | |
file_put_contents($filename, $data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Runner { | |
public function __construct() { | |
pcntl_signal(SIGCHLD, SIG_IGN); | |
} | |
public function go() { | |
if (pcntl_fork()) return; |