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 / main.go
Created January 8, 2018 03:06 — forked from petergloor/main.go
MaxInt, MinInt, MaxUint and MinUint in Go (golang)
package main
import "fmt"
// Constant definitions
const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(^uint(0) >> 1)
const MinInt = -MaxInt - 1
@wudi
wudi / di.php
Created December 13, 2017 04:45
Demo Dependency injection
<?php
/**
* Class Dependency injection
*/
class DI
{
protected $store = [];
@wudi
wudi / demo.go
Created July 31, 2017 09:51
demo.go
package main
import (
"encoding/json"
"fmt"
)
type Source struct {
ID string `json:"id"`
Title string `json:"title"`
package main
import (
"fmt"
"time"
"gopkg.in/redis.v5"
)
func main() {
@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);
@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)) {
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
)
<?php
$SECRET_KEY = '387a1a3091c29cf7ff253621c347f6df';
$args = $_POST;
// 校验必要参数是否存在
if((!isset($args['sign'])) || (!isset($args['timestamp']))){
echo "缺少必要参数";
exit(1);
}
// 校验请求是否过期,自定义延迟10分钟以上的消息丢弃
@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));
@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"