Skip to content

Instantly share code, notes, and snippets.

@rsky
rsky / RIFF.php
Created February 5, 2011 14:07
RIFF/WebP struct class for PHP
<?php
class RIFFException extends RuntimeException {}
/**
* Base class of RIFF chunks
*/
abstract class RIFFChunk
{
protected $id;
protected $size;
@rsky
rsky / cb.c
Created February 6, 2011 16:46
zend_fcall_info_init(), zend_fcall_info_call() のサンプル
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <php.h>
#include <ext/standard/info.h>
#include <Zend/zend_extensions.h>
static PHP_MINFO_FUNCTION(cb)
{
php_write("hi!\n", 4 TSRMLS_CC);
@rsky
rsky / gist:813761
Created February 6, 2011 22:02
posix_isatty()でファイルディスクリプタが端末か判定する
% php -r 'var_dump(posix_isatty(2));'
bool(true)
% php -r 'var_dump(posix_isatty(2));' 2>/dev/null
bool(false)
@rsky
rsky / zend_operators.c.diff
Created February 11, 2011 04:47
PHP 5.3で演算子オーバーロード
--- php-5.3.5/Zend/zend_operators.c.orig 2010-06-27 02:14:33.000000000 +0900
+++ php-5.3.5/Zend/zend_operators.c 2011-02-11 13:45:33.000000000 +0900
@@ -45,6 +45,77 @@
#define TYPE_PAIR(t1,t2) (((t1) << 4) | (t2))
+static int operator_overload(zval *op1, zval *op2, const char *function_name, zval **retval_ptr_ptr TSRMLS_DC) /* {{{ */
+{
+ zval callable;
+ zval *retval, *op2_copy;
@rsky
rsky / autocolordiff.py
Created May 13, 2011 06:04
~/.subversion/config の diff-cmd に指定して Git の [color] ui=auto 風に
#!/usr/bin/env python
import sys, subprocess
class AutoColorDiff:
diff = 'diff'
colordiff = 'colordiff'
def run(self, args,
stdin = None, stdout = None, stderr = None,
@rsky
rsky / mac-no-hibernatemode.sh
Created May 14, 2011 17:13
Mac OS Xのハイバネートを無効にし、sleepimageを削除する
#!/bin/sh
pmset -a hibernatemode 0
rm -fv /var/vm/sleepimage
@rsky
rsky / gist:1102568
Created July 24, 2011 12:26
STDOUTにstream_filter_append
<?php
$stream1 = fopen('php://output', 'wb');
stream_filter_append($stream1, 'string.rot13');
fwrite($stream1, "hoge\n");
fwrite(STDOUT, "hoge\n");
echo "hoge\n";
echo "-\n";
$stream2 = fopen('php://stdout', 'wb');
@rsky
rsky / gyazo-script.diff
Created November 11, 2011 16:59
Make Gyazo configurable
--- Gyazo.app/Contents/Resources/script
+++ Zyazo.app/Contents/Resources/script
@@ -2,6 +2,15 @@
require 'net/http'
+def gyazo_read_defaults(name, alternative, namespace = 'com.gyazo.Gyazo')
+ value = `defaults read '#{namespace}' '#{name}' 2>/dev/null`
+ if $? == 0
+ value.chomp
@rsky
rsky / PackageFileBuilder.php
Created November 26, 2011 06:19
PEAR\PackageFileBuilder - Utility for PEAR_PackageFileManager2.
<?php
// The latest version can be found at https://github.com/rsky/PEAR_PackageFileBuilder
/**
* Utility for PEAR_PackageFileManager2.
*
* @package PEAR_PackageFileBuilder
* @author Ryusuke SEKIYAMA <rsky0711@gmail.com>
* @copyright Copyright (c) 2011 Ryusuke SEKIYAMA
* @license http://www.opensource.org/licenses/mit-license.php MIT License
@rsky
rsky / Zend-API-Headers.diff
Created December 17, 2011 14:13
diff -ur php-5.3.8/Zend php-5.4.0RC2/Zend
Only in php-5.3.8/Zend: acconfig.h
diff -ur php-5.3.8/Zend/zend.h php-5.4.0RC2/Zend/zend.h
--- php-5.3.8/Zend/zend.h 2011-12-13 14:10:07.000000000 +0900
+++ php-5.4.0RC2/Zend/zend.h 2011-12-13 14:10:09.000000000 +0900
@@ -22,7 +22,7 @@
#ifndef ZEND_H
#define ZEND_H
-#define ZEND_VERSION "2.3.0"
+#define ZEND_VERSION "2.4.0"