Skip to content

Instantly share code, notes, and snippets.

View huandu's full-sized avatar

Huan Du huandu

View GitHub Profile
@huandu
huandu / facebook.go
Last active August 29, 2015 14:02
Facebook Golang SDK: Get location information in a post.
//
// this code is only a sample to demostrate how to read "place" field in a post.
//
package main
import fb "github.com/huandu/facebook"
type Location struct {
City string
@huandu
huandu / goo-design-doc.md
Last active August 29, 2015 14:02
Design doc for `goo`: Supercharging `go` command line

This is only a conceptual document. Every detail may change in my real implementation.

goo: Supercharging go command line

Motivation

Golang is a great language with a powerful built-in command line tool go. Unlike other language's compiler tool, go can do much more than just compiling code: go get or go install can download or install external packages; go test is for testing; and more...

As a developer, I always have needs to do something before or after go command to do my own customization.

@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.
@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 / 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 / queue.go
Created January 28, 2015 11:36
一个简单的并发可控、任务可随意拼接的任务队列实现
// 一个简单的并发可控、任务可随意拼接的任务队列实现。
// 仅作概念演示用,细节不要纠结。
//
// 基本结构:
// Context:所有任务共享的上下文,任务通过上下文交换数据
// Dispatcher:任务队列管理器,负责创建 Context 并把它放入合适的工作队列
// Worker:任务的抽象接口
// XXXWorker:各个具体的任务处理逻辑
package main
#!/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 / ..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

@huandu
huandu / class.js
Created August 15, 2011 05:14
A way to define javascript class. support multiple base class and static method.
(function(window, undefined) {
var Abstract = function() {
return arguments.callee;
},
Static = function(cb) {
this.cb = cb;
},
/**
* define your class.
*
@huandu
huandu / git-checkout-all-remotes
Created October 6, 2012 03:54
git checkout all remote branches
#! /bin/bash
REMOTE_NAME=$1
if [ "$REMOTE_NAME" == "" ]; then
cat <<EOF
Usage: $0 remote
remote Remote name, which can be 'origin' in common case.
EOF