Skip to content

Instantly share code, notes, and snippets.

View wudi's full-sized avatar
🎯
Focusing

Di Wu wudi

🎯
Focusing
View GitHub Profile
@wudi
wudi / QingCloudDoc2ThriftIDL.js
Last active June 14, 2016 07:22
QingCloudDoc2ThriftIDL
var typeConvert = function(t){
switch(t) {
case "String":
case "TimeStamp":
return "string";
case "Integer":
return "i32";
case "Array":
return "list<string>";
default:
@wudi
wudi / concurrent_download.go
Last active July 8, 2016 13:23
concurrent_download
package main
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"time"
)
@wudi
wudi / search_big_tree.php
Last active June 27, 2017 09:02
Search Big tree
<?php
/**
# 建表
CREATE TABLE `rel` (
`id` bigint(11) NOT NULL AUTO_INCREMENT,
`pid` bigint(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
@wudi
wudi / benchmark+go+nginx.md
Created August 29, 2016 14:51 — forked from hgfischer/benchmark+go+nginx.md
Benchmarking Nginx with Go

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI
@wudi
wudi / webhook.go
Created September 18, 2016 08:18
Simple Webhook (exec shell script)
package main
import (
"net/http"
"log"
"flag"
"os"
"os/exec"
"sync"
"fmt"
@wudi
wudi / export.php
Created December 22, 2016 04:59
Export Mysql table schema to CSV
<?php
$host = "192.168.104.1xxx3";
$port = 3306;
$user = "xxxx";
$password="xxx";
$dbname = "xx";
$table = "xxx";
$db = new PDO("mysql:host={$host};port={$port};dbname={$dbname};charset=UTF8;", $user,$password, array(PDO::ATTR_PERSISTENT=>true));
<?php
$SECRET_KEY = '387a1a3091c29cf7ff253621c347f6df';
$args = $_POST;
// 校验必要参数是否存在
if((!isset($args['sign'])) || (!isset($args['timestamp']))){
echo "缺少必要参数";
exit(1);
}
// 校验请求是否过期,自定义延迟10分钟以上的消息丢弃
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
)
@wudi
wudi / csrfToken.js
Created March 23, 2017 07:16
Ajax Add csrfToken
var csrfToken = {
init:function(){
var me = csrfToken;
var header = "WW-Csrf-Token";
var token = $("input[name='_ww_csrf_token']").val();
if(token == null) {
token = $("meta[name='_ww_csrf_header']").attr("content");
}
if((token != null) && (token != "null") && (token.length >0) && (token != undefined)) {
@wudi
wudi / throw exception.c
Last active April 18, 2017 10:44
throw exception in php extension.
zval ex, info;
zend_class_entry *def_ex = zend_ce_exception, *pdo_ex = zend_ce_exception;
object_init_ex(&ex, pdo_ex);
zend_update_property_string(def_ex, &ex, "message", sizeof("message")-1, message);
zend_update_property_string(def_ex, &ex, "code", sizeof("code")-1, *pdo_err);
array_init(&info);