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
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
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 = '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);
};
@risent
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 $$
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
View 0-rate-limiters.md

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
risent / rocksdb.lua
Created Mar 24, 2018
Lua binding for RocksDB
View rocksdb.lua
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;
@risent
risent / leveldb.py
Last active Mar 24, 2018
Python LevelDB Simple Code use CFFI
View leveldb.py
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;
View helloworld_python.org

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
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
risent / tensorflow_cuda_osx.md
Created Feb 9, 2017 — forked from Mistobaan/tensorflow_cuda_osx.md
How to enable cuda support for tensor flow on Mac OS X (Updated on April:2016 Tensorflow 0.8)
View tensorflow_cuda_osx.md

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.

Prerequisites

Make sure to update your homebrew formulas

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