Skip to content

Instantly share code, notes, and snippets.

Risent risent

Block or report user

Report or block risent

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
risent / parse-addr.js
Last active Nov 7, 2019
View parse-addr.js
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
risent / tweet_bookmarklet.js
Last active May 30, 2018
Twitter Shared Button Bookmarlet
View tweet_bookmarklet.js
fcuntion() {
var text = encodeURIComponent(window.getSelection().toString() || window.document.title);
var url = encodeURIComponent(window.location.href);
var dstUrl = '' + url + '&text=' + text;
var windowName = 'Tweet Intent';
var features = 'width=600,height=350,left=600,top=200';, windowName, features);
risent / postgresql_id.sql
Created May 10, 2018 — forked from yohang88/postgresql_id.sql
PostgreSQL Better ID & UUID Generator
View postgresql_id.sql
create schema shard_1;
create sequence shard_1.global_id_sequence;
CREATE OR REPLACE FUNCTION shard_1.id_generator(OUT result bigint) AS $$
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

Scaling your API with rate limiters

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.

Request rate limiter

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.

risent / rocksdb.lua
Created Mar 24, 2018
Lua binding for RocksDB
View rocksdb.lua
local ffi = require("ffi")
-- cut from
/* 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;
risent /
Last active Mar 24, 2018
Python LevelDB Simple Code use CFFI
from cffi import FFI
ffi = FFI()
# copied from
/* Exported types */
typedef struct leveldb_t leveldb_t;

Hello World In Python 10 Ways

1. general

print('Hello World')

2. sys stdout

import sys
View demo_cpu.c
// 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)
risent / # gcc - 2018-03-07_09-59-22.txt
Created Mar 7, 2018
gcc on macOS 10.13.3 - Homebrew build logs
View # gcc - 2018-03-07_09-59-22.txt
Homebrew build logs for gcc on macOS 10.13.3
Build date: 2018-03-07 09:59:22
risent /
Created Feb 9, 2017 — forked from Mistobaan/
How to enable cuda support for tensor flow on Mac OS X (Updated on April:2016 Tensorflow 0.8)

These instructions will explain how to install tensorflow on mac with cuda enabled GPU suport. I assume you know what tensorflow is and why you would want to have a deep learning framework running on your computer.


Make sure to update your homebrew formulas

brew update
You can’t perform that action at this time.