Skip to content

Instantly share code, notes, and snippets.

View vayn's full-sized avatar

Vayne Tsai vayn

View GitHub Profile
@ssokolow
ssokolow / README.markdown
Created August 13, 2010 06:09
Wordpress WXR to Jekyll exporter

Having decided to move my blog to Jekyll, I went looking for solutions. AzizLight's class proved the simplest, but fell short of what I wanted.

This version has been modified to be runnable as a command-line script (help available via -h) and, aside from category permalink continuity (which I'm working on), produces a ready-to-use _posts directory for your Jekyll blog.

Full details on the changes are available in the git commit log.

@Leechael
Leechael / WeiboController.php
Created January 25, 2011 05:23
The weibo oauth processing controller with li3_oauth.
<?php
namespace app\controllers;
use lithium\net\http\Router;
use lithium\storage\Session;
use li3_oauth\models\Consumer;
class WeiboController extends \lithium\action\Controller {
@vayn
vayn / factorial.py
Created July 16, 2011 16:34
Y combinator
#!/usr/bin/env python
# vim: set fileencoding=utf-8:
# @Author: Vayn a.k.a. VT <vayn@vayn.de>
# @Name: factorial.py
# @Date: 2011年07月16日 星期六 21时28分50秒
#
# 这是使用了赋值,以及需要 2 个参数的匿名函数的 factorial 实现。
# 赋值可以通过 () 符号取消掉,
# 使用 curry 这个技巧后可以减少一个参数,
# 这样就转化成 Y combinator 了
@maximebf
maximebf / webtail.py
Created October 21, 2011 13:25
Web tail / tail -f as a webpage using websocket
#!/usr/bin/python
# Equivalent of "tail -f" as a webpage using websocket
# Usage: webtail.py PORT FILENAME
# Tested with tornado 2.1
# Thanks to Thomas Pelletier for it's great introduction to tornado+websocket
# http://thomas.pelletier.im/2010/08/websocket-tornado-redis/
import tornado.httpserver
@tebeka
tebeka / sumtuples.py
Created November 1, 2011 17:58
Sum tuples of data using sqlite3
#!/usr/bin/env python
import sqlite3
def sumtuples(data, key_index):
cur = sqlite3.connect(':memory:').cursor()
cols = ['i{0}'.format(i) for i, _ in enumerate(data[0])]
schema = 'CREATE TABLE items ({0})'.format(','.join(cols))
cur.execute(schema)
@paulirish
paulirish / rAF.js
Last active March 22, 2024 00:00
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@hrldcpr
hrldcpr / tree.md
Last active May 1, 2024 00:11
one-line tree in python

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!

@moklett
moklett / openconnect.md
Created July 24, 2012 15:21
OpenConnect VPN on Mac OS X

Unfortunately, the Cisco AnyConnect client for Mac conflicts with Pow. And by "conflicts", I mean it causes a grey-screen-of-death kernel panic anytime you connect to the VPN and Pow is installed.

As an alternative, there is OpenConnect, a command-line client for Cisco's AnyConnect SSL VPN.

Here's how to get it set up on Mac OS X:

  1. OpenConnect can be installed via homebrew:

     brew update
    

brew install openconnect

@lastland
lastland / BeyesianAvg.py
Created August 11, 2012 07:14
尝试用这篇post: http://www.matrix67.com/blog/archives/5044 中的方法实现的一个自动中文抽词算法的Python程序
# -*- coding=utf-8 -*-
import collections
# Usage:
# 我的做法是把WordsDetector.py里的结果输出到文件,
# 然后把文件名放到下面的names列表中,运行本程序。
names = ['name0',
'name1',
'name2',
@railwaycat
railwaycat / Emacs_starter.pl
Last active March 12, 2023 01:26
Start Emacs.app from CLI
#!/usr/bin/perl
# Emacs starter for Emacs mac port
# Thanks to Aquamacs Project and David Reitter
my $args = "";
my $tmpfiles = "";
for my $f (@ARGV) {