Skip to content

Instantly share code, notes, and snippets.

View skydark's full-sized avatar

Skydark Chen skydark

View GitHub Profile
##Some points to mention...
##
##The model knows nothing about the view or the controller.
##The view knows nothing about the controller or the model.
##The controller understands both the model and the view.
##
##The model uses observables, essentially when important data is changed,
##any interested listener gets notified through a callback mechanism.
##
##The following opens up two windows, one that reports how much money you
// jQuery Plugin Boilerplate
// A boilerplate for jumpstarting jQuery plugins development
// version 1.1, May 14th, 2011
// by Stefan Gabos
// remember to change every instance of "pluginName" to the name of your plugin!
;(function($) {
// here we go!
$.pluginName = function(element, options) {
@skydark
skydark / closures-in-ruby.rb
Created May 23, 2012 16:04
Ruby's closures #ruby
# CLOSURES IN RUBY Paul Cantrell http://innig.net
# Email: username "cantrell", domain name "pobox.com"
#
# 翻译: kenshin54 http://kenbeit.com
# I recommend executing this file, then reading it alongside its output.
# 我强烈建议执行此脚本,然后根据它的输出来理解它。
#
# Alteratively, you can give yourself a sort of Ruby test by deleting all the comments,
# then trying to guess the output of the code!
@skydark
skydark / lis.py
Created July 17, 2012 03:04
Scheme Interpreter in Python #scheme #python
################ Lispy: Scheme Interpreter in Python
## (c) Peter Norvig, 2010; See http://norvig.com/lispy.html
################ Symbol, Env classes
from __future__ import division
Symbol = str
@skydark
skydark / raskell.rb
Created May 24, 2013 13:11 — forked from andkerosine/raskell.rb
list comprehension in ruby, see also: https://gist.github.com/freakhill/5564328 #ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@skydark
skydark / patternmatch.py
Created December 5, 2012 05:42
A simple pattern matcher #python
#!/usr/bin/python
# -*- coding: utf-8 -*-
import unittest
GREATER, LESSER, EQUAL, NOT_COMPARABLE = 1, -1, 0, None
def compare(e1, e2):
order = e1.compare(e2)
from threading import Thread
import hashlib
def async(gen):
def func(*args, **kwargs):
it = gen(*args, **kwargs)
result = it.next()
Thread(target=lambda: list(it)).start()
return result
return func
@skydark
skydark / sendevent.c
Created September 20, 2012 14:23
以前在智器Q5/V5上配合Openbox时自己胡乱写的一个东西,推荐用xdotool替代。#C #X
/*
* sendevent
* A Simple Wraper to Send XEvent
* usage:
* sendevent key|mouse [-modifier] name
*
* Start : 2010/3/6
* Last : 2010/3/24
*
* Copyright (c) 2010 Skydark Chen <skydark2 [at] gmail.com>
@skydark
skydark / wawammseg.py
Created August 23, 2012 09:47 — forked from onlytiancai/wawammseg.py
写了一个简单的支持中文的正向最大匹配的机械分词,其它不用解释了,就几十行代码 #python
# -*- coding:utf-8 -*-
'写了一个简单的支持中文的正向最大匹配的机械分词,其它不用解释了,就几十行代码'
'搜狗词库下载地址:http://vdisk.weibo.com/s/7RlE5'
import string
__dict = {}
def load_dict(dict_file='words.dic'):
'加载词库,把词库加载成一个key为首字符,value为相关词的列表的字典'