print('Hello World')
import sys
import random | |
import time | |
import numpy | |
from exceptions import ValueError | |
class PushID(object): | |
# Modeled after base64 web-safe chars, but ordered by ASCII. | |
PUSH_CHARS = ('-0123456789' | |
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
local ffi = require("ffi") | |
-- cut from https://github.com/facebook/rocksdb/blob/e59cb2a19b2971707d75552ae517586ca0785a6a/include/rocksdb/c.h | |
ffi.cdef[[ | |
/* Exported types */ | |
typedef struct rocksdb_t rocksdb_t; | |
typedef struct rocksdb_backup_engine_t rocksdb_backup_engine_t; | |
typedef struct rocksdb_backup_engine_info_t rocksdb_backup_engine_info_t; | |
typedef struct rocksdb_restore_options_t rocksdb_restore_options_t; |
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
const parseAddr = (addr) => { | |
const sepList = ['省', '市', '市', '县', '区', '街道', '乡', '镇'] | |
const res = [] | |
let rest = addr | |
for (let sep of sepList) { | |
let m = rest.split(sep, 2) | |
let current | |
if (m.length > 1) { | |
current = m[0] + sep |
fcuntion() { | |
var text = encodeURIComponent(window.getSelection().toString() || window.document.title); | |
var url = encodeURIComponent(window.location.href); | |
var dstUrl = 'https://twitter.com/intent/tweet?url=' + url + '&text=' + text; | |
var windowName = 'Tweet Intent'; | |
var features = 'width=600,height=350,left=600,top=200'; | |
window.open(dstUrl, windowName, features); | |
}; |
create schema shard_1; | |
create sequence shard_1.global_id_sequence; | |
CREATE OR REPLACE FUNCTION shard_1.id_generator(OUT result bigint) AS $$ | |
DECLARE | |
our_epoch bigint := 1314220021721; | |
seq_id bigint; | |
now_millis bigint; | |
-- the id of this DB shard, must be set for each | |
-- schema shard you have - you could pass this as a parameter too |
The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.
In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.
This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.
from cffi import FFI | |
ffi = FFI() | |
# copied from https://github.com/google/leveldb/blob/master/include/leveldb/c.h | |
ffi.cdef(""" | |
/* Exported types */ | |
typedef struct leveldb_t leveldb_t; |
// demo_cpu.c | |
#include <stdbool.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define ISROM(a) ((a) < 16) | |
#define ISRAM(a) ((a) >= 16 && (a) < 20) |