Skip to content

Instantly share code, notes, and snippets.

View huandu's full-sized avatar

Huan Du huandu

View GitHub Profile
@huandu
huandu / list_properties.swift
Created November 22, 2014 18:00
List properties of a swift class.
import Foundation
struct Point {
var x = 0.0
var y = 0.0
}
class PropertyHub {
var simpleProp = "Foo"
var structProp = Point()
@huandu
huandu / macro_strrchr.cpp
Created July 12, 2014 15:13
A macro implementation of `strrchr()`
#include <iostream>
using namespace std;
#define _STRRCHR_IMPL_COMMON(str, ch, offset) (str)[sizeof((str)) - 1 - (offset)] == (ch)? (str) + sizeof((str)) - (offset): sizeof((str)) <= (offset) + 1? (str)
#define _STRRCHR_IMPL_31(str, ch) (_STRRCHR_IMPL_COMMON(str, ch, 31): (str))
#define _STRRCHR_IMPL_30(str, ch) (_STRRCHR_IMPL_COMMON(str, ch, 30): _STRRCHR_IMPL_31(str, ch))
#define _STRRCHR_IMPL_29(str, ch) (_STRRCHR_IMPL_COMMON(str, ch, 29): _STRRCHR_IMPL_30(str, ch))
#define _STRRCHR_IMPL_28(str, ch) (_STRRCHR_IMPL_COMMON(str, ch, 28): _STRRCHR_IMPL_29(str, ch))
#define _STRRCHR_IMPL_27(str, ch) (_STRRCHR_IMPL_COMMON(str, ch, 27): _STRRCHR_IMPL_28(str, ch))
@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 / 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 / README.md
Created May 31, 2013 08:25
Quick thoughts about my new personal project, "the sisters".

System admin work is boring. I want to find a way to save myself (and other system admins if possible).

I was inspired by github's hubot. It's expressive simple and really make system admin's work funny. I like the idea learning by watching. I want to use the hubot in my project.

But sadly, hubot just misses one important thing - it's a centralized bot without any network level support. In my scenario, I have some computers in cloud, some in real racks and some in company's intranet. I don't have a server that can communicate to all other servers. I need a "bridge" to connect all servers so that I can use the bot to control everything.

What's more, I want the "bridge" is able to work as a back door application. I don't want to be bothered by authentication details. I need to use one unified credential to operate all servers.

I call this bridge application as "the sisters". This name comes from a Japanese novel [Toaru Majutsu no Index](http://ja.wikipedia.org/wiki/%E3%81%A8%E3

@huandu
huandu / README.md
Last active December 11, 2015 15:58
Sample concept source files for project "shana".

"shana" is a project to introduce html-like rendering experience to opengl-based cross platform mobile apps. It will be built on top of cocos2d-x 2.x.

"shana" will define a new mark-up UI language looks like html. It will use stylesheet and CSS selectors to ease styling work. To make styling work even more flexible, "shana" will support expressions in all node attributes and style rules. Writing "center" in attribute "x", or "parent.width/2+10" in attribute "width" will work exactly as expected.

"shana" will include a compiler to generate binary shana file from xml sources and a C++ lib to render shana file and manipulate nodes. It may include an http server to compile source files on the fly. And it may also include several apps to load and preview shana file on mobile devices.

"shana" project scope is quite big. Currently, I'm doing very early design work. If you are interested in this project, please feel free to let me know. Your suggestion and/or participant is highly appreciated.

@huandu
huandu / flip_cards.html
Created December 19, 2012 03:43
A flip card demo for Chrome and Safari.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Test Flip Cards Performance</title>
<link rel="stylesheet" href="cards.css" />
<style type="text/css">
body { background: #000; padding-top: 200px; font-family: Helvetica; }
#scene { background: url(body.jpg) no-repeat; margin: auto; text-align: center; width: 640px; height: 350px; padding: 50px; }
@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
@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.
*