Instantly share code, notes, and snippets.

View array_key_map.php
<?php
/**
* Array map, but maps values to new keys instead of new values
* @return array same arrays with keys mapped
*/
function array_map_key($callback,$array)
{
$out=array_reduce($array, function ($carry,$val) use ($array,$callback){
$key=call_user_func($callback,$val);
$carry[$key]=$val;
View docker-php.sh
#!/bin/sh
if [[ $# -lt 1 ]]; then
echo "Usage: $0 NAME [PORT]";
exit 1
fi
NAME=$1
PORT=${2:-80}
if [ "${PWD##*/}" != "${NAME}" ]; then
mkdir -p "${NAME}"
cd "${NAME}"
View latency.txt
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
View honeypot_ls.sh
#!/bin/bash
LOGFILE="/tmp/lslog"
ORIGINAL_LS="/bin/LS"
#chmod 777 "${LOGFILE}"
WHOAMI=$(whoami)
TTY=$(tty)
CWD="$(pwd)"
PARENT_COMMAND="$(ps -o comm= $PPID)"
View stdlib.php
<?php
function grep_r($str,$find)
{
return substr($str,$r=strpos($str,$find)+strlen($find),strpos($str,PHP_EOL,$r)-1-$r);
}
function curl($url,$postparams=[],$headers=[],$additional_opts=[])
{
$opts=[
CURLOPT_COOKIEJAR => 'stdlib.cookie',
CURLOPT_COOKIEFILE => 'stdlib.cookie',
View typed_php.php
<?php
class TypedPHPException extends Exception {
function __construct($msg,$file,$line)
{
parent::__construct($msg);
$this->file=$file;
$this->line=$line;
}
}
View zval_id.phpx
ZEND_BEGIN_ARG_INFO_EX(phpx_byref_arginfo,
1 /*pass_rest_by_reference*/,
0/*return_reference*/,
1/*required_num_args*/)
ZEND_ARG_PASS_INFO(1/*by_ref*/)
ZEND_END_ARG_INFO();
PHP_FUNCTION(zval_id)
{
//computes the address of first zval sent to it,
View is_ref.phpx
ZEND_BEGIN_ARG_INFO_EX(phpx_byref_arginfo,
1 /*pass_rest_by_reference*/,
0/*return_reference*/,
1/*required_num_args*/)
ZEND_ARG_PASS_INFO(1/*by_ref*/)
ZEND_END_ARG_INFO();
PHP_FUNCTION(is_ref)
{
zval *z;
View is_ref.php
<?php
/**
* This is a hacky is_ref function.
* Determines whether a variable is a reference or not
* by using var_dump on its symbol table and
* checking whether it has '&' before its value or not.
* @param array $defined_vars should send get_defined_vars() to this. enforced.
* @param mixed $var any variable, should be a variable and not a expression
* @return boolean
*/
View zval_id.php
<?php
/**
* This is a hacky zval_id implementation.
* It tries to be as fast as possible,
* and can only detect unique arrays, leaving them
* modified
* When in doubt, assumes it's a new zval!
* @param mixed &$zval
* @return integer
*/