Skip to content

Instantly share code, notes, and snippets.

@ircmaxell
ircmaxell / gist:1963999
Created March 3, 2012 02:54
Scalar type hint/casting patch 2
Index: Zend/zend.h
===================================================================
--- Zend/zend.h (revision 323850)
+++ Zend/zend.h (working copy)
@@ -575,6 +575,15 @@
#define IS_CONSTANT_ARRAY 9
#define IS_CALLABLE 10
+/* Data type casts, hacked to be different from data type constants */
+#define IS_NULL_CAST 0x010
@ircmaxell
ircmaxell / gist:1966809
Created March 3, 2012 16:03
Scalar Casting Patch, Version 3
Index: Zend/zend.h
===================================================================
--- Zend/zend.h (revision 323850)
+++ Zend/zend.h (working copy)
@@ -486,6 +486,10 @@
union _zend_function *__call;
union _zend_function *__callstatic;
union _zend_function *__tostring;
+ union _zend_function *__toint;
+ union _zend_function *__tofloat;
@ircmaxell
ircmaxell / gist:2004623
Created March 9, 2012 02:13
Scalar Type Hint Patch, Version 3
Index: Zend/zend.h
===================================================================
--- Zend/zend.h (revision 323850)
+++ Zend/zend.h (working copy)
@@ -575,6 +575,9 @@
#define IS_CONSTANT_ARRAY 9
#define IS_CALLABLE 10
+/* Ugly hack to keep track of string hints vs class names */
+#define IS_STRING_HINT 0x026
@ircmaxell
ircmaxell / gist:2004650
Created March 9, 2012 02:23
Scalar Type Hint Patch, Version 3 - no generated files
Index: Zend/zend.h
===================================================================
--- Zend/zend.h (revision 323850)
+++ Zend/zend.h (working copy)
@@ -575,6 +575,9 @@
#define IS_CONSTANT_ARRAY 9
#define IS_CALLABLE 10
+/* Ugly hack to keep track of string hints vs class names */
+#define IS_STRING_HINT 0x026
@ircmaxell
ircmaxell / dumpToJSON.php
Created April 8, 2012 04:51
PHP JSON dump
<?php
function dumpToJson($var, $encode = true, array $recursionCache = array()) {
$tmp = serialize($var);
if (isset($recursionCache[$tmp])) {
return 'recursion';
}
$recursionCache[$tmp] = true;
$result = array();
$result['type'] = gettype($var);
@ircmaxell
ircmaxell / sanity.py
Created June 11, 2012 03:26
Sanity Test - Try to listen for more than 1 hour without going crazy
import random, time, winsound
timebias = 0.2
pitchbias = 0.7
changebias = 0.75
current = [(4.,1.),(5.,1.),(7.,3.),(None,1.), (4.,1.),(5.,1.),(7.,3.),(None,1.),(4.,1.),(7.,1.),(12.,2.),(11.,2.),(9.,2.),(9.,2.),(7.,1.),(None,1.),(2.,1.),(4.,1.),(5.,3.),(None,1.),(2.,1.),(4.,1.),(5.,3.),(None,1.),(2.,1.),(5.,1.),(11.,1.),(9.,1.),(7.,2.),(11.,2.),(12.,4.)]
timeshift = 1;
while 1:
@ircmaxell
ircmaxell / password.php
Created June 18, 2012 16:53
Password API Example
<?php
define('PASSWORD_SHA256', '$5$');
define('PASSWORD_SHA512', '$6$');
define('PASSWORD_BCRYPT', '$2y$');
define('PASSWORD_SCRYPT', '$7$'); // made up here
$password_algos = array();
function password_register_algo($prefix, Callable $create, Callable $validate) {
@ircmaxell
ircmaxell / password_needs_rehash.c
Created July 5, 2012 19:56
password needs rehash problem
PHP_FUNCTION(password_needs_rehash)
{
int hash_len, newAlgo, algo = 0;
char *hash;
HashTable *options = 0;
zval **option_buffer;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|H", &hash, &hash_len, &newAlgo, &options) == FAILURE) {
RETURN_NULL();
}
@ircmaxell
ircmaxell / php-build.sh
Created July 8, 2012 16:58
PHP Build Script
#!/bin/bash
function checkError {
if [ $1 -ne 0 ]; then
echo -e "Error in build step\n"
exit
fi
}
VERSION=$1
@ircmaxell
ircmaxell / php.sh
Created July 8, 2012 17:15
PHP Run Script
#!/bin/bash
BIN=""
if [ "$PHP" == "/usr/local/bin/php" ]
then
PHP=""
fi
BIN="/usr/local/php/$1/bin/php"