Skip to content

Instantly share code, notes, and snippets.

@zither
zither / c.js
Created September 16, 2017 14:52
phantomjs
// Usage: phantomjs c.js
var page = require('webpage').create();
var url = 'c.html';
page.open(url, function(status){
window.setTimeout(function () {
var height = page.evaluate(function(){
return document.body.scrollHeight;
@zither
zither / meituan.php
Created April 6, 2017 15:17
meituan
<?php
class Meituan
{
protected $testApiURL = 'http://test.waimaiopen.meituan.com/api/v1/';
protected $apiURL = 'http://waimaiopen.meituan.com/api/v1/';
protected $appid;
protected $secretKey;
public function __construct($appid, $secret)
@zither
zither / gist:3cfbc08a1da07731e8c605146773f4cc
Last active November 17, 2016 06:57
reference rebinding test
<?php
$a = "111";
$b = &$a;
$f = "????";
function test_global_ref()
{
$c = "2222";
global $b; // 这个 $b 与之前函数外的 $b 不是同一个,位于不同的 scope, 它是对函数外那个 $b 引用,此时值为 "111"
$b = &$c; // 重新绑定后这个 $b 变成了 $c 的引用, 修改的只是函数 scope 内的 $b
@zither
zither / test1.php
Last active September 17, 2015 04:06
Doku_LexerStateStack_Tests
<?php
define("DOKU_INC", __DIR__ . "/");
require DOKU_INC . "inc/parser/lexer.php";
$startTimeIndex = xdebug_time_index();
//$startMemoryUsage = xdebug_memory_usage();
$stack = new Doku_LexerStateStack("base");
for ($i = 0; $i < 1000000; $i++) {
$stack->enter("test_mode_name");
@zither
zither / test.php
Last active August 29, 2015 14:27
PDO Test
<?php
$databaseUsername = "username";
$databasePassword = "password";
$databaseName = "pdo_bug_test";
// 打印 PDO 版本
$ext = new ReflectionExtension('pdo');
echo "PDO 版本:" . $ext->getVersion() . PHP_EOL;
// Mysql 测试数据
@zither
zither / terminal.php
Created March 18, 2015 11:04
terminal
#!/usr/bin/env php
<?php
$terminal = new Terminal();
$terminal->saveTTY();
$terminal->initTTY();
$player = new Player($terminal, array("x" =>10, "y" => 27));
$valid = false;
@zither
zither / fread.php
Last active August 29, 2015 14:17
Read a single character of input from the TTY without waiting for the enter in PHP CLI
#!/usr/bin/env php
<?php
// 保存当前 tty 设置
$term = shell_exec("stty -g");
// 关闭 tty 规范输入模式
// link http://www.faqs.org/docs/Linux-HOWTO/Serial-Programming-HOWTO.html#AEN92
system("stty -icanon");
while ($c = fread(STDIN, 1)) {
@zither
zither / Cipher.php
Last active August 29, 2015 14:15
Simple Shadowsocks Client
<?php
class Cipher
{
public function __construct($key, $method, $iv, $op, $keyAsBytes = 0, $d = null, $salt = null, $i = 1, $padding = 1)
{
$this->key = $key;
$this->method = $method;
$this->op = $op;
$this->iv = $iv;