Skip to content

Instantly share code, notes, and snippets.

View robbinhan's full-sized avatar
🏠
Working from home

robbin han robbinhan

🏠
Working from home
View GitHub Profile
@robbinhan
robbinhan / array.c
Created March 17, 2012 05:15
php的array_chunk源码中模除的巧妙用法
/* If reached the chunk size, add it to the result array, and reset the
* pointer. */
if (!(++current % size)) {
add_next_index_zval(return_value, chunk);
chunk = NULL;
}
@robbinhan
robbinhan / crc32.c
Created March 18, 2012 06:43
php crc32算法
char *p;
int len, nr;
php_uint32 crcinit = 0;
register php_uint32 crc;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &p, &nr) == FAILURE) {
return;
}
crc = crcinit^0xFFFFFFFF;
@robbinhan
robbinhan / pptpd.sh
Created November 30, 2012 13:02 — forked from alvin2ye/pptpd.sh
Automaticlly install pptpd on Amazon EC2 Amazon Linux
# Automaticlly install pptpd on Amazon EC2 Amazon Linux
#
# Ripped from http://blog.diahosting.com/linux-tutorial/pptpd/
# pptpd source rpm packing by it's authors
#
# WARNING:
# first ms-dns setting to 172.16.0.23, 172.16.0.23 was showing on my
# /etc/resolv.conf, I'm not sure this is the same on all Amazon AWS zones.
#
# You need to adjust your "Security Groups" which you are using too.
@robbinhan
robbinhan / gist:4247728
Created December 10, 2012 00:48 — forked from markbates/gist:4240848
Getting Started with Rack

If you're writing web applications with Ruby there comes a time when you might need something a lot simpler, or even faster, than Ruby on Rails or the Sinatra micro-framework. Enter Rack.

Rack describes itself as follows:

Rack provides a minimal interface between webservers supporting Ruby and Ruby frameworks.

Before Rack came along Ruby web frameworks all implemented their own interfaces, which made it incredibly difficult to write web servers for them, or to share code between two different frameworks. Now almost all Ruby web frameworks implement Rack, including Rails and Sinatra, meaning that these applications can now behave in a similar fashion to one another.

At it's core Rack provides a great set of tools to allow you to build the most simple web application or interface you can. Rack applications can be written in a single line of code. But we're getting ahead of ourselves a bit.

@robbinhan
robbinhan / gist:5669167
Created May 29, 2013 09:43
链表迭代的代码写法
listNode *listIndex(list *list, long index) {
listNode *n;
if (index < 0) {
index = (-index)-1;
n = list->tail;
while(index-- && n) n = n->prev;
} else {
n = list->head;
while(index-- && n) n = n->next;
session.gc_probability = 1
session.gc_divisor = 100
session.gc_maxlifetime = 1440
这三个配置组合构建服务端session的垃圾回收机制
session.gc_probability与session.gc_divisor构成执行session清理的概率,理论上的解释为服务端定期有一定的概率调用gc函数来对session进行清理,清理的概率为:
gc_probability/gc_divisor 比如:1/100 表示每一个新会话初始化时(session_start),有1%的概率会启动垃圾回收程序,清理的标准为session.gc_maxlifetime定义的时间。
function verify_app_store_in_app($receipt, $is_sandbox)
{
//$sandbox should be TRUE if you want to test against itunes sandbox servers
if ($is_sandbox)
$verify_host = "ssl://sandbox.itunes.apple.com";
else
$verify_host = "ssl://buy.itunes.apple.com";
$json='{"receipt-data" : "'.$receipt.'" }';
//opening socket to itunes

#定义的宏

  • ZTS - 用于判断是否开始线程安全模式
  • EG - Zend引擎全局变量结构体宏(zend引擎一些变量设置,包含runtime环境的函数表、类表、zend常量、加载过的文件、error_reporting等)
  • PG - PHP核心全局变量的结构体宏(内存限制、display_error、include_path等)
  • SG - sapi全局变量的结构体宏(包含server信息、请求信息、请求的参数等)
  • PS - php的session函数库的全局变量结构体宏(包含每个session的信息,保存路径、名称、id、cookie的信息)

#Mysql Join

内连接

  • 内连接就是计算结果集的交集 SELECT * FROM table_a, table_b WHERE table_a.id = table_b.id ##左右外部连接(内连)
  • 左外部连接是计算左表全部数据以及和右表有交集的数据 SELECT * FROM table_a LEFT OUTER JOIN table_b ON table_a.id = table_b.id
  • 右外部连接是计算右表全部数据以及和左表有交集的数据 SELECT * FROM table_a RIGHT OUTER JOIN table_b ON table_a.id = table_b.id ##左右外部连接不内连

#Zend引擎分析 ##基础变量类型(zend_value)

  • zend_long

typedef int64_t zend_long;64位有符号整型

  • zend_uchar

typedef unsigned char zend_uchar;无符号字符型