Skip to content

Instantly share code, notes, and snippets.

@sandacn
sandacn / touch_time.sh
Created June 30, 2019 02:54
修改文件的最后修改时间
#!/bin/bash
dir=$1
if [ ! -d $dir ];
then
echo "$dir does not exist"
exit 1
fi
@sandacn
sandacn / split.go
Created April 24, 2019 15:43
split string with fixed size in golang
package main
import (
"fmt"
"strings"
"time"
"math"
)
func splitByWidthMake(str string, size int) []string {
@sandacn
sandacn / re_bench.php
Last active December 10, 2018 00:24
PHP 7.3 upgrade to PCRE2 performance test
<?php
### run this with php 7.3 and php lower version such as php 7.2
### time php re_bench.php
### time php73 re_bench.php
$regex_list = [
'#Twain#',
'#(?i)Twain#',
@sandacn
sandacn / resolv.conf updates.md
Created January 16, 2018 07:45 — forked from ganey/resolv.conf updates.md
AWS - php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
@sandacn
sandacn / gist:32721e3b4efa9a5cd67d485957bfebe1
Last active September 4, 2017 09:23 — forked from oppara/gist:132274
php: mb_trim
function mb_trim( $str ) {
return mb_ereg_replace(
'^[[:space:]]*([\s\S]*\S)?[[:space:]]*$', '\1', $str );
}
@sandacn
sandacn / ngx-lua.sh
Created January 9, 2016 17:25 — forked from hit9/ngx-lua.sh
Script to compile nginx on ubuntu with lua support.
#!/bin/sh
# Script to compile nginx on ubuntu with lua support.
NGX_VERSION='1.6.2'
LUAJIT_VERSION='2.0.3'
LUAJIT_MAJOR_VERSION='2.0'
NGX_DEVEL_KIT_VERSION='0.2.19'
LUA_NGINX_MODULE_VERSION='0.9.15'
@sandacn
sandacn / gist:ad6686249d7bc0ee0014
Last active August 29, 2015 14:09
判断ip是否为内网ip
<?php
function is_intranet_ip($ip = null) {
if (!$ip) {
$ip = $_SERVER['REMOTE_ADDR'];
}
$long_ip = ip2long($ip);
$ret = false;
// 分别判断10. 192.168. 172.16-31. 127.0.0.1
if ($long_ip >> 24 == 0xa || $long_ip >> 20 == 0xac1 || $long_ip >> 16 == 0xc0a8 || $long_ip == 0x7f000001) {
@sandacn
sandacn / gc_test.php
Last active December 17, 2015 18:19
<?php
ini_set('xdebug.trace_format', '1');
class MyPhotoBO {
public static $SPEC_GIANT = "giant";
public static $SPEC_BIG = "big";
public static $SPEC_MIDDLE = "middle";
public static $SPEC_MIDDLE_BIG = "middlebig";
public static $SPEC_SQUARE_200 = "middlesquare";
public static $SPEC_SQUARE_100 = "smallsquare";
public static $SPEC_FIT_100 = "smallfit";
@sandacn
sandacn / if_switch_test.php
Created April 16, 2011 09:19
## 测试 if else 和switch 哪个更快
<?php
## 测试 if else 和switch 哪个更快
## 测试结果是 if else 更快
// prepare test data
$MAX = 1000000;
$data = array();
$actions = array("add", "remove", "edit");
$rates = array(1, 1, 1);
$limits = array();
@sandacn
sandacn / i_plus_plus_test.php
Created April 16, 2011 09:13
## 测试到底是i++ 快还是 ++i快
<?php
## 测试到底是i++ 快还是 ++i快
$MAX = 1000000;
$start_ts = microtime(true);
for ($i = 0; $i < $MAX; $i++) {
$a = 1;