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 / api.js
Last active December 10, 2015 02:28 — forked from JacksonTian/api.js
var events = require('events');
var callA = function (callback) {
setTimeout(function () {
callback({name: "a", data: "I am result A"});
}, Math.round(Math.random() * 300));
};
var callB = function (callback) {
setTimeout(function () {
callback({name: "b", data: Math.round(Math.random() * 300) % 2 === 0});
@seckcoder
seckcoder / async_fetch_weibo.py
Last active December 10, 2015 06:58
Crawl weibo(repost timeline) asynchronously in python. It needs gevent and sina python weibo client(https://github.com/michaelliao/sinaweibopy) installed.
import math
import gevent
import gevent.greenlet
from gevent import monkey
from functools import partial
monkey.patch_all()
from weibo import APIClient
import time
class ActionCounter:
@seckcoder
seckcoder / gist:5575284
Last active December 17, 2015 07:48
从一个字符串中找到从右往左数第3个下划线的index
import itertools
a = "abc_d_e_f"
print list(itertools.islice((i for i,c in enumerate(reversed(a)) if c == '_'), 3))[2]
def take(n, iterable):
return list(itertools.islice(iterable, n))
print take(3, (i for i,c in enumerate(reversed(a)) if c == '_'))[2]
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@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)
@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)
# 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: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
};
@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: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))