Skip to content

Instantly share code, notes, and snippets.

View creamidea's full-sized avatar

NekoTrek creamidea

View GitHub Profile
@creamidea
creamidea / app.coffee
Last active December 28, 2015 15:49
旋转木马 简单实现
"use strict"
( ($) ->
loadImage = ($image, src, callback) ->
$image.bind "load", (e) ->
$image.unbind "load"
callback $image
.each ->
if $image[0].complete
$image.trigger "load"
def addListener(self, listener, msgClass):
if listener not in self.listeners:
self.listeners[listener] = {}
amTypes = self.listeners[listener]
amTypes[msgClass.get_amType()] = msgClass
def dispatchPacket(self, source, packet):
...
for l in self.listeners:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 字典法
global counter
counter = 0
def gem(a, k):
"""
k是用来表明这次递归从那个固定的数开始
"""
n = len(a)
#include <stdio.h>
void print(int a, int b) {
printf("a=%d, b=%d\n", a, b);
}
int v1(int a, int b) {
int c;
c = a;
@creamidea
creamidea / hanoi.py
Created December 27, 2013 07:29
汉诺塔算法
#!/usr/bin/env python
def move(origin, dest):
print "%s -> %s" % (origin, dest)
def hanoi(n, origin, assist, dest):
if n is 1:
move(origin, dest)
else:
hanoi(n - 1, 'A', 'C', 'B')
@creamidea
creamidea / memorize.js
Last active July 14, 2022 15:26
函数式编程当中,缓存技巧叫做「记忆」(memorization),一阶乘函数。
function memorize(f) {
var cache = {};
// 这个函数是什么意思呢
// 就是使用闭包的特性,保留了cache的值
// 这值将间接使用上次调用时产生的值。下面例子中会详细讲解。
return function() {
console.log(cache); // 打印缓存值
// 这里的key就是一个签名档意思,也就是被缓存函数的参数
var key = Array.prototype.join.call(arguments, ',');
// console.log(key)
@creamidea
creamidea / horspool_matching.py
Created January 1, 2014 13:46
horspool字符匹配算法
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def create_shift_table(pattern):
ascii_table = {}
len_pattern = len(pattern)
for i in range(0, 128): # 初始化表
ascii_table[chr(i)]=len_pattern
for i in range(0, len_pattern-1): # 构造移动表,排除模式的最后一个字符
p = pattern[i:i+1]
@creamidea
creamidea / ace-vim.js
Last active January 2, 2016 09:18
ace vim.js
ace.require("ace/lib/net").loadScript("https://raw.github.com/ajaxorg/ace-builds/master/src-min-noconflict/keybinding-vim.js", function() {
e = document.getElementById("ace-editor").env.editor;
e.setKeyboardHandler(ace.require("ace/keyboard/vim").handler);
})
// for gist
ace.require("ace/lib/net").loadScript("https://rawgithub.com/ajaxorg/ace-builds/master/src-min-noconflict/keybinding-vim.js",
function() {
e = document.querySelector(".ace_editor.ace-github").env.editor;
#!/usr/bin/env python
__copyright__ = 'Yuanxuan Wang <zellux at gmail dot com>'
from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import Tag, NavigableString
from collections import OrderedDict
from contextlib import nested, closing
import json
@creamidea
creamidea / smart-table.coffee
Last active January 2, 2016 16:39
本来想制作一个智能表格的,但是没有写完。写贴在这里
$smartTable = $("#smart-table")
class Table
constructor: (option) ->
{@templateName, @$wrapper} = option
@context = [] #内部存储数据列表
click: (e) ->
$li = $(e.target)
action = $li.attr('action')
switch action
when "add"