This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis | |
client = redis.StrictRedis() | |
client.flushdb() | |
def incr(pipe): | |
value = pipe.get('key') | |
value = int(value) + 1 | |
pipe.multi() | |
pipe.set('key', value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2013 Jike Inc. All Rights Reserved. | |
# Author: [email protected] | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var assert = require("assert"), | |
ms = require("ms"); | |
function LimitedAccessObject(opts) { | |
var initial = { | |
times:1, | |
costed:0, | |
autoRefresh:false, | |
refreshInterval:0 | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) '()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let ((a 1)) | |
(define (f x) | |
(define b (+ a x)) | |
(define a 5) | |
(+ a b)) | |
(f 10)) |
OlderNewer