Skip to content

Instantly share code, notes, and snippets.

@fwolf
fwolf / lifetime-compute.php
Last active August 29, 2015 14:16
With given timestamp start date, compute same length base36 encoded string can be start from or end to which date.
<?php
/**
* Compute of lifetime range for base36 encoded timestamp string
*
* Notice: Need to run in 64-bit environment
*
* @see http://3v4l.org/qDkDE
*/
$lengthOfSecond = 6;
@fwolf
fwolf / find-best-start-date.php
Last active August 29, 2015 14:16
Given length of second and microsecond, use base36, from current time, which start date will fill the full length ?
<?php
// @see http://3v4l.org/YPTHo
$lengthOfSecond = 6;
$lengthOfMicroSecond = 4;
$length = $lengthOfSecond + $lengthOfMicroSecond;
// From start date to now, the encoded value need fill length
$minTimestamp36 = '1' . str_repeat('0', $length - 1);
$minTimestamp10 = base_convert($minTimestamp36, 36, 10);
@fwolf
fwolf / base36-timestamp-trimmed.php
Created March 5, 2015 16:14
Compute if trim timestamp to start from not 1970, the max year same length base 36 zzz... can present to.
<?php
// Compute if trim timestamp to start from not 1970, the max year same length
// base 36 zzz... can present to.
$startYear = 2000;
$currentYear = date('Y');
$currentTimestamp = time();
for ($year = $startYear; $year <= $currentYear; $year ++) {
$startDate = "$year-01-01";
@fwolf
fwolf / highcharts-example.html
Created February 28, 2015 05:18
Stuff when learning HighCharts, 2012
<?php
$s_title = 'Highcharts JS Example';
echo<<<EOF
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
@fwolf
fwolf / flotr2-example.html
Created February 28, 2015 05:17
Stuff when learning flotr2
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="utf-8" />
<meta name="Author" content="Fwolf &lt;fwolf.aide+fwolflib.class.flotr2@gmail.com&gt;, http://www.fwolf.com/" />
<link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen, print" />
@fwolf
fwolf / MockContainer.php
Created February 27, 2015 10:52
MockContainer, not used, system function mock need create in per test case.
<?php
namespace Fwlib\Test;
use Fwlib\Base\AbstractServiceContainer;
use malkusch\phpmock\Mock;
/**
* Container of system function mocks
*
* @copyright Copyright 2015 Fwolf
@fwolf
fwolf / export
Last active August 29, 2015 14:15
Swarm Simulator save
MS4wLjE4|Q2hlYXRlciA6KAoKN4IglgJiBcIG4AYB0AmEAaEALApgQwCcAXAI3yIEkpZFUBaAawHsA7AcwJzbyJ2l0KlyGEAFcWYIkQCeABxwBnGKDAs4YBWBIAbHFh4BjXAWkwQARhEBbYbACsqOwBYAzAhR2UCBC4AcTnABqFAA2EW1CODwzXz8PB3MAdl8ATl9fBCdEu1TMkQMmAtYzBBFeAgJJJhMzcyQ/d0SnFHN3JySXFCcndyCWkRwWHAI2U1hfO2QUlxmRTgV5AwBRIZGxkFLMIYAPUSVYNEwrUSI8NkGSkVlOY9PzlkvMPAUDQc1i2E2QADNOHAAlRSLMxOEQQAisHBmFBIOwhLpOEKpFx2ZLOLIpELmPouEQAR1EOAusHMEycOQmSJQoXccKcKSQYS2iiI0MSiQQKXa5hCiRSdgZqURoMwHHIwwJRIeB0SXRyyBCuMwWDAcChJNJspEKrVkuJGwGVmuin2Bsw1yYslwrM+IjYTAgEBNjxAsjwLCIuA+Ztd7s9OFYaFt5r9XpYuODvo9YdBkbd0YDLDsLqYaoIVlU1B9qeGGZYECD2bTeYgEaLuczsfL6czycjOZr+bCkYUAHdCFZtKo2GYckieSkRAoiN3hrV0gg7J4h7JIGPYOSUnyUL5rEwFASqiDUYlFYcQNpCnsbSBeS4Um05kw8EYQa4kaiUiu7WA/Qs5wQQRymq5Ol9Xh6YDyE6tTmDM1JdCI7YLCCIQIBMYI4HATCiJwn4kvCmKWKKTDeokIgSGwWCkKIPaRlYTCei6JA8C6tyhoYxjrF89EejRJ4sScfoGIeQx0VxHpth27YELI/GnB6BB7Fg4l+vgt7kQJRC/DgeKyR6Ox7Oppzpsx1hKTYtG2gAvpgEA8OqoDDoIOBZl45h2HQ7h0C0AAqCCJNArjQOYdQuHBABacwsjZdkIA5TkoC55juZ53m+fUgVDngaphRFzkoC47koNA3i5U4SDTAgQWYJwYDfGAtnQuFjkZVl7i5Qg+VIHyTgl
@fwolf
fwolf / gb2312-utf8-convert.js
Created February 10, 2015 17:28
Convert between gb2312 and utf8 using javascript
http://freecode-freecode.blogspot.com/2008/11/how-to-gbkgb2312-and-utf-8-encoding.html
GB2312UTF8 = {
Dig2Dec : function(s){
var retV = 0;
if(s.length == 4){
for(var i = 0; i < 4; i ++){
retV += eval(s.charAt(i)) * Math.pow(2, 3 - i);
}
return retV;
@fwolf
fwolf / Choose betwen PHP ORM
Last active August 29, 2015 14:14
Choose betwen PHP ORM
Propel
http://propelorm.org/
第一印象感觉不错
Propel2 需要 PHP 5.4
CRUD 正合我意
Relationships 也不错,就是 useXxx() 和 endUse() 缩进有点奇怪,IDE 那儿也许会有点小问题
缺点:初始化比较复杂
Doctrine
主要是觉得笨重,另外不喜欢它的特殊注释
@fwolf
fwolf / btc38-okcoin-price-compare.php
Last active January 2, 2016 09:29
Compare price on btc38 and okcoin
#! /usr/bin/php
<?php
/**
* btc38-okcoin-price-compare.php
*
* Copyright 2014 Fwolf <fwolf.aide+gist@gmail.com>
* All rights reserved.
*
* Distributed under the MIT License.
* http://opensource.org/licenses/mit-license