Skip to content

Instantly share code, notes, and snippets.

View seckcoder's full-sized avatar

Wei Li seckcoder

  • Blablabla
  • San Francisco
View GitHub Profile
# 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)
#
# 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: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]
@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 / 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});