Skip to content

Instantly share code, notes, and snippets.

@hit9
hit9 / tree.md
Created January 13, 2013 12:47 — forked from hrldcpr/tree.md

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@hit9
hit9 / gist:5037573
Created February 26, 2013 10:41
如何翻转链表中的相邻两个元素?
/*
* Q: 如何翻转链表中的相邻两个元素?
* Link: http://www.foreach.cn/question/16
* 比如原链表是:
* a->b->c->d->e->f
* 我们只翻转相邻两个,即1和2翻转,3和4翻转,翻转后如下:
* b->a->d->c->f->e
*/
#include <stdio.h>

GitHub OAuth Busy Developer's Guide

This is a quick guide to OAuth2 support in GitHub for developers. This is still experimental and could change at any moment. This Gist will serve as a living document until it becomes finalized at Develop.GitHub.com.

OAuth2 is a protocol that lets external apps request authorization to private details in your GitHub account without getting your password. All developers need to register their application before getting started.

Web Application Flow

  • Redirect to this link to request GitHub access:
@hit9
hit9 / str_to_int.py
Created March 13, 2013 02:12
字符串转数字. eg: "3456" => 3456
reduce(lambda x,y:10*x+y,map(lambda x:ord(x)-48,a))
@hit9
hit9 / misaka_hilite.py
Last active December 15, 2015 06:59
use misaka to highlight code with pygments
import houdini as h
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
import misaka as m
from misaka import HtmlRenderer, SmartyPants
# Create a custom renderer
class BleepRenderer(HtmlRenderer, SmartyPants):
@hit9
hit9 / sources.list
Created April 3, 2013 06:00
哈工大ubuntu 11.04源
deb http://run.hit.edu.cn/ubuntu/ natty main universe restricted multiverse
deb-src http://run.hit.edu.cn/ubuntu/ natty universe main multiverse restricted
deb http://run.hit.edu.cn/ubuntu/ natty-security universe main multiverse restricted
deb-src http://run.hit.edu.cn/ubuntu/ natty-security universe main multiverse restricted
deb http://run.hit.edu.cn/ubuntu/ natty-updates universe main multiverse restricted
deb-src http://run.hit.edu.cn/ubuntu/ natty-updates universe main multiverse restricted
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {
@hit9
hit9 / gist:5429402
Last active December 16, 2015 11:39
个人用以重装Ubuntu操作系统的记录

准备镜像,显卡驱动

1.. 准备系统Ubuntu 11.04 (我发现这是我最喜欢的ubuntu版本) 2. 准备好ati 11-04 版本的catalyst驱动 3. 准备好

初始系统

  1. 开始重装, 装好后,安装驱动:
@hit9
hit9 / update_nested_dict.py
Created May 20, 2013 12:35
Update a nested dict with another one.
a = {
'a': {
'x': 1,
'y': 2
},
'b': 3
}
b = {
'a': {
@hit9
hit9 / progress.py
Created May 21, 2013 13:50
打印一个百分进度
import sys
import time
from termcolor import colored
class Progress(object):
def __init__(self):
size = 0