Skip to content

Instantly share code, notes, and snippets.

@upsuper
upsuper / complex.cpp
Created June 27, 2011 14:38
Complex class in C++
#include <iostream>
using namespace std;
template<typename T>
class Complex {
private:
T m_real;
T m_imag;
public:
Complex<T>(T real=0.0, T imag=0.0)
@upsuper
upsuper / gae_proxies
Created November 16, 2011 13:57
nginx GAE反向代理配置
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_pass http://ghs.google.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
@upsuper
upsuper / sendkeys.py
Created December 23, 2011 14:04
Send keys to clipboard or input directly (now only for Mac OS X and partly Linux)
# - * - coding: UTF-8 - * -
import subprocess
def macosx_set_clipboard(text):
p = subprocess.Popen('pbcopy', stdin=subprocess.PIPE)
p.communicate(text)
def macosx_send_keys(text):
text = text.replace('\\', '\\\\').replace('"', '\\"')
@upsuper
upsuper / directory_icon.c
Created January 24, 2012 16:57
Set directory icon on Mac
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <CoreServices/CoreServices.h>
#include "directory_icon.h"
int setDirectoryIcon(const char *dirName, const char *iconData, size_t iconSize)
{
const int kResidIcon = -16455;
const OSType kRsrcType = 'icns';
@upsuper
upsuper / status.py
Created March 10, 2012 11:34
a python script to monitor account of twitter
#!/usr/bin/python
# - * - coding: UTF-8 - * -
import cgi
import json
import urllib
import httplib2
h = httplib2.Http()
query = urllib.urlencode({
@upsuper
upsuper / Makefile
Created March 21, 2012 10:54
中文C编程
CFLAGS=-fextended-identifiers -std=c99
objects=chinese.ucn.o
target=chinese
.PHONY: all clean
all: $(target)
$(target): $(objects)
$(CC) $< -o $@
@upsuper
upsuper / mail.func.php
Created April 17, 2012 06:43
检验是否为有效的电子邮件地址的 PHP 函数
<?php
/**
* 检验是否为有效的电子邮件地址
*
* 根据 http://www.linuxjournal.com/article/9585 编写
*
* @param string $email
* @return bool
*/
@upsuper
upsuper / tree.md
Created April 28, 2012 10:38 — forked from hrldcpr/tree.md
一行 Python 实现树

一行 Python 实现树

使用 Python 内置的 defaultdict,我们可以很容易的定义一个树形数据结构:

def tree(): return defaultdict(tree)

就是这样!

@upsuper
upsuper / gist:2633348
Created May 8, 2012 07:51
HTML5 Canvas demo with lines smoothed using Bézier curve
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title></title>
<style type="text/css">
canvas { position: absolute; top: 0; left: 0; }
#c { background: #ccc; }
#ps { position: absolute; top: 0; right: 0; }
@upsuper
upsuper / update_self.sh
Created May 29, 2012 08:17
将 DNSPod 上指定子域名指向当前本机 IP 的脚本
#!/bin/bash
# 将 DNSPOD 上指定子域名指向当前本机 IP 的脚本
#
# 依赖:
# urlencode: http://www.shelldorado.com/scripts/cmds/urlencode
# jsawk: https://github.com/micha/jsawk
# 配置信息
EMAIL=""