Skip to content

Instantly share code, notes, and snippets.

<?php
class CallThing
{
protected $count = 0;
public function __invoke() {
$this->count++;
}
  • Streams: PHP streams have some major issues - notifications not finished, the horrid http layer (can we PLEASE use a library?), object/class integration, filters and the filter api make people cry, horrific error handling - noise for noise sake and no way to retrieve useful errors and warnings, no curl wrapper anymore, internal api for the implementation is sad
  • Extensions: some pecl <-> php swaps, all internal extensions MUST have ACTIVE maintainers or get punted, some OO apis for older extensions and killing some non useful (looking at you odbc) functionality, better test coverage of extensions
  • Enums: either in spl or in core, an enum object for C style enums (or enums as a zval type, either works for me) - this is highly difficult to implement in userland, in ext/core you can make it act like an int with Moar features
  • Unicode: a unicode string class - yes yes ugly in some ways, but could hold a wchar_t and char * cached of utf8, always act in utf8 when used a string in the majority of PHP cases, an
@mgdm
mgdm / subclassing.md
Last active August 29, 2015 14:12
Mosquitto\Client subclassing

Subclassing Mosquitto\Client

The Client class in the Mosquitto extension is a heavy user of callbacks. As the class is currently implemented, you need to individually assign the various callbacks manually. For example:

function messageHandler($message) {
  var_dump($message);
}

$client = new Mosquitto\Client();
@mgdm
mgdm / a.rb
Created January 12, 2015 16:25
Merging target public/assets/build/sites/stv/styles/legacy-style-1.min.css
fatal: ambiguous argument 'public/assets/newlocal/img/icons/arrow-right-white.png': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
fatal: ambiguous argument 'public/assets/newlocal/img/logos/itison-pin.png': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
fatal: ambiguous argument 'public/assets/newlocal/img/timeline-head-glasgow.jpg': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
fatal: ambiguous argument 'public/assets/newlocal/img/timeline-head-edinburgh.jpg': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
fatal: ambiguous argument 'public/assets/newlocal/img/timeline-head-aberdeen.jpg': unknown revision or path not in the working tree.
@mgdm
mgdm / -
Created January 28, 2015 15:15
diff --git a/redis_array_impl.c b/redis_array_impl.c
index 2fcf18e..9590cc7 100644
--- a/redis_array_impl.c
+++ b/redis_array_impl.c
@@ -32,7 +32,7 @@ extern zend_class_entry *redis_ce;
RedisArray*
ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval, zend_bool b_lazy_connect TSRMLS_DC)
{
- int i, host_len, id;
+ int i = 0, host_len, id;
diff --git a/config.m4 b/config.m4
index 36be8ff..654979b 100644
--- a/config.m4
+++ b/config.m4
@@ -32,11 +32,12 @@ if test "$PHP_JITFU" != "no"; then
PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
[
PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $JITFU_DIR/lib, JITFU_SHARED_LIBADD)
+ PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $JITFU_DIR/lib/x86_64, JITFU_SHARED_LIBADD)
AC_DEFINE(HAVE_JITLIB,1,[ ])
@mgdm
mgdm / mandelbrot.php
Last active August 29, 2015 14:15
Mandelbrot renderer
<?php
ini_set('memory_limit', -1);
define('MAX_ITERATIONS', 4096);
function mandel($xMin, $xMax, $yMin, $yMax, $xPx, $yPx) {
$dx = ($xMax - $xMin) / $xPx;
$dy = ($yMax - $yMin) / $yPx;
$rows = [];
/* Compile with:
* gcc -O3 -o basic-mandelbrot basic-mandelbrot.c -lpng
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <png.h>
@mgdm
mgdm / gol.py
Last active August 29, 2015 14:16
Game of Life in Python
import numpy as np
import os, sys, time
from random import randrange
def make_board(width, height):
board = np.zeros((width, height))
for y in xrange(0, height):
for x in xrange(0, width):
if randrange(10) > 8:
@mgdm
mgdm / win32.diff
Created April 5, 2015 20:37
Fix compile on Linux
diff --git a/Zend/zend.c b/Zend/zend.c
index abaa0d2..99e560a 100644
--- a/Zend/zend.c
+++ b/Zend/zend.c
@@ -399,6 +399,7 @@ static void zend_set_default_compile_time_values(void) /* {{{ */
}
/* }}} */
+#ifdef ZEND_WIN32
static void zend_get_windows_version_info(OSVERSIONINFOEX *osvi) /* {{{ */