Skip to content

Instantly share code, notes, and snippets.

@fwolf
fwolf / gist:464533
Created July 5, 2010 17:14
Find and recover un-continous id of WordPress post.
<?php
/**
* Find and recover un-continous id of WordPress post.
*
* Will make empty draft using these id for edit them later.
* Also change revision or auto-draft to draft.
*
* @package fwolfweb
* @subpackage wordpress
* @copyright Copyright 2010, Fwolf
@fwolf
fwolf / php.ini
Created July 19, 2011 06:33
php.ini
;====================================================================
[Fwolf]
;在 PHP4 中使用 date 等函数的时候,并不需要考虑时区问题,会自动获得本地时间,
;但 PHP5 中则不行,如果你们有设置好时区,
;同样的代码在不同的系统可能会产生莫名其妙的问题(比如 Windows 和 Unix 之间)。
;想要正常使用时间函数,需要在 php.ini 中设置统一的时区:
date.timezone = PRC
;也有一个函数,只是需要在程序中使用
;date_default_timezone_set('Asia/Shanghai');
@fwolf
fwolf / php.ini
Created July 19, 2011 06:41
php.ini on MediaTemple VPS
;====================================================================
[Fwolf]
date.timezone = PRC
display_errors = on
error_log = /var/log/php.err
include_path = ".:/var/www/vhosts/fwolf.com/httpdocs/include"
post_max_size = 16M
;session.save_path = "/var/lib/php/session"
upload_max_filesize = 10M
@fwolf
fwolf / mt-mon.sh
Created August 24, 2011 09:04
Monitor system mem and load, if too high, restart some service.
#! /bin/bash
#====================================================================
# mt-mon.sh
#
# Copyright (c) 2011, Fwolf <[email protected]>
# All rights reserved.
# Distributed under the GNU General Public License, version 3.0.
#
# Monitor system mem and load, if too high, restart some service.
@fwolf
fwolf / mem.sh
Last active May 28, 2017 09:13
Monitor memory usage in VPS
#! /bin/bash
# https://gist.github.com/fwolf/5856230
#ps aux --width 80 | sort -nrk +6 | head -n 15
# bsdtime is shorter than cputime, hh:mm:ss vs MMM:SS
ps -eo 'user,pid,%cpu,%mem,rss,vsz,stime,bsdtime,s,cmd' --sort '-rss,-vsz' --width 80 | head -n 16
echo
@fwolf
fwolf / snow.sh
Created October 23, 2013 14:01
Snow in bash
#!/bin/bash
# Author unknown
LINES=$(tput lines)
COLUMNS=$(tput cols)
declare -A snowflakes
declare -A lastflakes
@fwolf
fwolf / php-quote-benchmark.php
Created October 27, 2013 14:06
Speed benchmark for PHP single-quote VS double-quote. Result: almose same.
<?php
$blah="blah"; $s=microtime(true); for($i=0;$i<100000;$i++) 'omgwtf'.$blah."\n"; echo microtime(true)-$s . "\n"; $s=microtime(true); for($i=0;$i<100000;$i++) "omgwtf{$blah}\n"; echo microtime(true)-$s . "\n";
@fwolf
fwolf / compute-base-convert-safe-length.php
Created October 31, 2013 14:06
Number equal or larger than 100000000000000(1.0E+14) will represent by Scientific Notation(科学记数法), cause base_convert() loose precision. So for larger number, use BC Math or GMP. This array is used to check number string length per base, if string is longer than the array value, it should not use build-in base_convert(). Un-formatted for run usi…
for ($j = 2; $j < 63; $j ++) {
$x = $j; $i = 1; $y = $x;
while ($y < 100000000000000) {
$i ++;
$y = pow($x, $i);
}
$i --;
$y = pow($x, $i);
echo "$x^$i = $y, length " . strlen($y) . "\n";
}
@fwolf
fwolf / btc38-reminder.php
Last active March 11, 2017 08:43
Send reminder when trade price reach setting criteria.
#! /usr/bin/php
<?php
/**
* btc38-reminder.php
*
* Copyright 2013 Fwolf <[email protected]>
* All rights reserved.
*
* Distributed under the MIT License.
* http://opensource.org/licenses/mit-license
@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 <[email protected]>
* All rights reserved.
*
* Distributed under the MIT License.
* http://opensource.org/licenses/mit-license