Skip to content

Instantly share code, notes, and snippets.

View huandu's full-sized avatar

Huan Du huandu

View GitHub Profile
@huandu
huandu / OUTPUT.txt
Last active July 18, 2019 12:01
Show currency in different locales
$ go run main.go
CNY cn-ZH 123,456.79元
CNY en-US ¥123,456.79
CNY es-MX ¥123,456.79
CNY en-AU ¥123,456.79
CNY ja-JP ¥123,456.79
CNY es-PE ¥123,456.79
USD cn-ZH $123,456.79
USD en-US $123,456.79
USD es-MX $123,456.79
@huandu
huandu / nginx-cors.conf
Last active July 11, 2020 12:28 — forked from sbuzonas/nginx-cors.conf
Nginx CORS maps
map $http_origin $allow_origin {
default "$http_origin";
}
map $request_method $cors_method {
default "allowed";
"OPTIONS" "preflight";
}
map $cors_method $cors_max_age {
@huandu
huandu / ..build-protbuf-2.5.0.md
Last active August 29, 2015 14:25 — forked from BennettSmith/..build-protbuf-2.5.0.md
Build script for protobuf 2.5.0 on iOS devices

Google Protobuf 2.5.0 - Mac OS X and iOS Support

The script in this gist will help you buid the Google Protobuf library for use with Mac OS X and iOS. Other methods (such as homebrew or direct compilation) have issues that prevent their use. The libraries built by this script are universal and support all iOS device architectures including the simluator.

Get the Script

The easiest way to use this script is to simply clone the gist onto your

#!/bin/bash
set -e
# Setup architectures, library name and other vars + cleanup from previous runs
ARCHS=("armv7" "armv7s" "arm64" "i386" "x86_64")
SDKS=("iphoneos" "iphoneos" "iphoneos" "macosx" "macosx")
LIB_NAME="libevent-2.0.22-stable"
SCRIPT_DIR=$(dirname "$0")
OUTPUT_DIR="${SCRIPT_DIR}/.."
HEADER_DEST_DIR="${OUTPUT_DIR}/include/ios/libevent"
@huandu
huandu / queue.go
Last active September 29, 2017 07:02
第二种方案:一个简单的并发可控、任务可随意拼接的任务队列实现
// 一个简单的并发可控、任务可随意拼接的任务队列实现。
// 仅作概念演示用,细节不要纠结。
//
// 基本结构:
// Task:当前任务共享的上下文,任务通过上下文交换数据,一个任务可分为很多的工作(Work)
// Dispatcher:任务队列管理器,负责创建 Task 并使用合适的 Worker 来处理数据
// Worker:任务的抽象接口
// XXXWorker:各个具体的任务处理逻辑
// WorkerBench:一个 Worker 池,确保当前正在运行的 Worker 数量不超过限制
package main
@huandu
huandu / queue.go
Created January 28, 2015 11:36
一个简单的并发可控、任务可随意拼接的任务队列实现
// 一个简单的并发可控、任务可随意拼接的任务队列实现。
// 仅作概念演示用,细节不要纠结。
//
// 基本结构:
// Context:所有任务共享的上下文,任务通过上下文交换数据
// Dispatcher:任务队列管理器,负责创建 Context 并把它放入合适的工作队列
// Worker:任务的抽象接口
// XXXWorker:各个具体的任务处理逻辑
package main
@huandu
huandu / LICENSE
Created January 7, 2015 04:15
Proxy calls to all Obj-C objects
The MIT License (MIT)
Copyright (c) 2015 Huan Du
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@huandu
huandu / README.md
Last active August 29, 2015 14:11
Planning for `go-rat`

This is a simple planning file for go-rat. I'm using a public gist to make the whole progress transparent for anyone who interests this project.

Here is a very short introduction to go-rat: This is a pre-compiler project for go to support generic, generator, method/operator overloading at compile time.

Project URL: https://github.com/go-rat

WARNING: This is quite a big project for me. I don't have any dedicated time nor commitment on it. I may take quite a long time get all things done. Anyway, I still want to have a done. This public gist is a way to push myself keep walking.

Planning

@huandu
huandu / parse_csv_demo.sh
Created December 3, 2014 05:28
Demo to parse CSV file with awk.
# parse csv files to an awk array.
awk -F, '{
parse_csv(r);
# replace following line with your code.
print r[1], r[2], r[3], r[4];
} function parse_csv(r, _quote, _i, _n) {
_i = 1;
_quote = 0; # in a quoted string or not.
@huandu
huandu / README.md
Created November 28, 2014 11:53
Javascript style generator in Golang

This is a javascript style iterator sample using go. It's only a demo so don't expect too much from it.

I'm writing this to test whether it's possible to use goroutine to simulate generator without any issue. I take special care on memory issue. I use runtime.SetFinalizer to make sure once it is released all related goroutines will stop properly.

The result is quite good. It's promising.

And I also think of a way to declare generator function in go - using valid go syntax.

// Look at its return type.