Skip to content

Instantly share code, notes, and snippets.

View seckcoder's full-sized avatar

Wei Li seckcoder

  • Blablabla
  • San Francisco
View GitHub Profile
@seckcoder
seckcoder / gist:9204855
Last active May 22, 2023 04:29
implementation of exception, generator and coroutine based on continuation
#lang racket
; Implementations and examples are inspired by Matt Might's blog posts:
; http://matt.might.net/articles/programming-with-continuations--exceptions-backtracking-search-threads-generators-coroutines/
; Note I didn't just copy the code. I implemented it independently, so it looks a lot different from Matt's code.
(define (current-continuation)
(call/cc (lambda (k)
(k k))))
(define (exception)
@seckcoder
seckcoder / schengen_calculator.py
Created November 2, 2019 05:54
schengen_calculator.py
"""
Simple calculator to calculate the remaining number of days that I can stay in the schengen zone
"""
from datetime import datetime, timedelta
dates = [
"2019-06-28", "2019-07-27",
"2019-09-02", "2019-10-05",
@seckcoder
seckcoder / gist:8234822
Created January 3, 2014 08:37
ocamlinit
(* Added by OPAM. *)
let () =
try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
with Not_found -> ()
;;
#use "topfind";;
#thread;;
#camlp4o;;
#require "core.top";;
@seckcoder
seckcoder / gist:7511433
Created November 17, 2013 09:53
高昌, 侯旭, 蠢货第一次修改
To 侯:
我把
And we present a system that's capable of
integrating transfer function design results
from a group of experts to facilitate the
design process of novice users by providing
useful interactions that enable flexible
navigation in the transfer function feature
space and effective visual suggestion.
@seckcoder
seckcoder / gist:6749188
Created September 29, 2013 03:48
scheme implementation test
(let ((a 1))
(define (f x)
(define b (+ a x))
(define a 5)
(+ a b))
(f 10))
@seckcoder
seckcoder / gist:6732850
Last active December 24, 2015 02:49
words->lines
#!/usr/local/bin/guile -s
!#
; Scheme(guile) implementation for http://weibo.com/1822142792/Abqbesr1n?mod=weibotime
; include guile pattern matching module
(use-modules (ice-9 match))
; transform a list of words to list of lines, with length of line not exceeding line-len
(define (words->lines words line-len)
(cond ((null? words) '())
@seckcoder
seckcoder / gist:6281530
Last active December 21, 2015 08:58
limited access object
var assert = require("assert"),
ms = require("ms");
function LimitedAccessObject(opts) {
var initial = {
times:1,
costed:0,
autoRefresh:false,
refreshInterval:0
};
# Copyright 2013 Jike Inc. All Rights Reserved.
# Author: liwei@jike.com
from gevent import monkey
monkey.patch_all()
from gevent.pool import Pool
import time
from weibo_offline_base.ttypes import PlatForm
from hbase_rabbitMQ_interface import HbaseRabbitMQ
@seckcoder
seckcoder / gist:5782977
Created June 14, 2013 15:54
A demo for redis transation's strong exception guarantee.
"""
A demo for redis transation's strong exception guarantee.
"""
import logging
import redis
client = redis.StrictRedis(host="127.0.0.1",
port=6379,
db=1)
@seckcoder
seckcoder / gist:5697196
Last active December 18, 2015 00:29
redis transaction
import redis
client = redis.StrictRedis()
client.flushdb()
def incr(pipe):
value = pipe.get('key')
value = int(value) + 1
pipe.multi()
pipe.set('key', value)