Skip to content

Instantly share code, notes, and snippets.

View jpauli's full-sized avatar
🐍

jpauli jpauli

🐍
View GitHub Profile
@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
==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:85211102df1a17f22de5
Created March 17, 2016 21:54
Objects as Generators
<?php
class Foo
{
public function __invoke($arg)
{
yield $arg;
}
}
#! /usr/bin/env php
<?php
if ($argc != 2) {
exit(sprintf("Usage : %s <pid>\n", $argv[0]));
}
if (!file_exists("/proc/1/status")) {
exit("/proc/1/status does not exist, what OS are you running ?\n");
@jpauli
jpauli / gist:69ff64a8425e8fd2e24b
Created July 1, 2014 16:36
PHP fast-cgi pool balancer management script
#!/bin/bash
pool1=pool_1
pool2=pool_2
port1=8031
port2=8032
nbport1=0
nbport2=0
@jpauli
jpauli / gist:8afec7c4fc2b38f8ff27
Created June 13, 2014 14:17
fallocate VS ftruncate demo
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
if (argc != 3) {
printf("Usage: allocate <1:ftruncate, 2:fallocate> <size> \n");
@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)
<?php
$s = (new PDO("sqlite::memory:"))->query("SELECT 1");
$s->setFetchMode(PDO::FETCH_INTO, $o);
$s->fetch();
/* General error: object must be an object */
$o1 = new stdclass($a=8);
var_dump($a); // Notice: Undefined variable: a
$o2 = new Datetime($b='now');
var_dump($b); // string "now"