Skip to content

Instantly share code, notes, and snippets.

View jpauli's full-sized avatar
🐍

jpauli jpauli

🐍
View GitHub Profile
@jpauli
jpauli / gist:5466273
Created April 26, 2013 10:13
ZEND_MM_TRUE_SIZE expanded on my platform , needs 123 steps
((size<(((((((((sizeof(zend_mm_block)) + 8 - 1) & ~(8-1)) + sizeof(unsigned int)) + 8 - 1) & ~(8-1))>(((sizeof(zend_mm_small_free_block)) + 8 - 1) & ~(8-1))?((((((sizeof(zend_mm_block)) + 8 - 1) & ~(8-1)) + sizeof(unsigned int)) + 8 - 1) & ~(8-1)):(((sizeof(zend_mm_small_free_block)) + 8 - 1) & ~(8-1)))>((((sizeof(zend_mm_block)) + 8 - 1) & ~(8-1))+sizeof(unsigned int)))?((((((((sizeof(zend_mm_block)) + 8 - 1) & ~(8-1)) + sizeof(unsigned int)) + 8 - 1) & ~(8-1))>(((sizeof(zend_mm_small_free_block)) + 8 - 1) & ~(8-1))?((((((sizeof(zend_mm_block)) + 8 - 1) & ~(8-1)) + sizeof(unsigned int)) + 8 - 1) & ~(8-1)):(((sizeof(zend_mm_small_free_block)) + 8 - 1) & ~(8-1)))-((((sizeof(zend_mm_block)) + 8 - 1) & ~(8-1))+sizeof(unsigned int))):0))?((((((((sizeof(zend_mm_block)) + 8 - 1) & ~(8-1)) + sizeof(unsigned int)) + 8 - 1) & ~(8-1))>(((sizeof(zend_mm_small_free_block)) + 8 - 1) & ~(8-1))?((((((sizeof(zend_mm_block)) + 8 - 1) & ~(8-1)) + sizeof(unsigned int)) + 8 - 1) & ~(8-1)):(((sizeof(zend_mm_small_free_block)) + 8
@jpauli
jpauli / gist:6230757
Last active December 21, 2015 01:49
libpcap embedding into PHP
<?php
$r = phpcap_create('eth0', PHPCAP_DEV_PROMISC);
phpcap_dispatch($r, function($packet) {
$unpack = unpack('H12macdest/H12macsrc/H4ethtype/H24/a4ipsrc/a4ipdest',$packet);
printf("Got a packet, from %s(%s) to %s(%s)\n",
inet_ntop($unpack['ipsrc']),
$unpack['macsrc'],
$o1 = new stdclass($a=8);
var_dump($a); // Notice: Undefined variable: a
$o2 = new Datetime($b='now');
var_dump($b); // string "now"
<?php
$s = (new PDO("sqlite::memory:"))->query("SELECT 1");
$s->setFetchMode(PDO::FETCH_INTO, $o);
$s->fetch();
/* General error: object must be an object */
@jpauli
jpauli / optimized libc memcpy()
Created January 29, 2014 10:56
memcpy() with a sizeof(void *) size just nicely uses mov
160 char *str1 = "mystring";
7ffff6240c71: lea 0xf2(%rip),%rax # 0x7ffff6240d6a
7ffff6240c78: mov %rax,-0x8(%rbp)
161 char *str2 = NULL;
7ffff6240c7c: movq $0x0,-0x10(%rbp)
165 memcpy(&str2, &str1, sizeof(char *));
7ffff6240c84: mov -0x8(%rbp),%rax
7ffff6240c88: mov %rax,-0x10(%rbp)
@jpauli
jpauli / gist:85211102df1a17f22de5
Created March 17, 2016 21:54
Objects as Generators
<?php
class Foo
{
public function __invoke($arg)
{
yield $arg;
}
}
==6700== 36 bytes in 1 blocks are still reachable in loss record 14 of 39
==6700== at 0x4C28C20: malloc (vg_replace_malloc.c:296)
==6700== by 0x9FC2DE: Balloc (zend_strtod.c:600)
==6700== by 0x9FC7EC: mult (zend_strtod.c:879)
==6700== by 0x9FCA7F: pow5mult (zend_strtod.c:1007)
==6700== by 0xA00836: zend_dtoa (zend_strtod.c:4178)
==6700== by 0x942CD1: __cvt (snprintf.c:96)
==6700== by 0x942E66: php_fcvt (snprintf.c:138)
==6700== by 0x943389: php_conv_fp (snprintf.c:389)
==6700== by 0x944DD3: format_converter (snprintf.c:1036)
@jpauli
jpauli / gist:0d339973c244fc83248f67dc3b8f9d2f
Last active April 6, 2018 09:24
Update bind zones on public IP DHCP renew
#!/home/doc/php/bin/php
<?php
$exit = 0;
$exit_signal = 0;
function fork()
{
$pid = pcntl_fork();
if ($pid < 0) {
@jpauli
jpauli / PHP useful valgrind suppressions
Created June 12, 2017 12:06
PHP useful valgrind suppressions
{
<insert_a_suppression_name_here>
Memcheck:Leak
fun:malloc
fun:init_op_array
fun:compile_file
obj:*
...
fun:zend_execute_scripts
fun:php_execute_script