Skip to content

Instantly share code, notes, and snippets.

View jacobbubu's full-sized avatar

Rong Shen jacobbubu

  • Li Auto.
  • Beijing, China
View GitHub Profile
jacobbubu / 如何实现 pull-stream 的
Last active March 7, 2023 14:31
如何实现 pull-stream 的 Source

Source(read) 概述

Sink 对 Source 有两种请求:

  1. read: 向 Source 请求数据,通过 read(null, currCb) 来请求。
  2. abort: 通知 Source 终止当前的 stream,通过 read(endOrError, currCb) 来请求。endOrError 的类型是 true | Error,表示是一次正常的终止还是异常的终止。

对于 read 请求,Sink 应该基于 上一次的 read 请求回调了,再发起新的 read 请求这样的规则。 对于 abort 请求,由于有时 Source 也不知道何时需要 abort(出现了异常或者外部其他条件触发的),因此可能在上一次 read 没有回调就发生。

  • 对于 Sink 的 read 请求,如果”重入“(上一次 read 没有结束,新的 read 来了),Source 完成实际资源的读取后,仅仅调用最后一个传入的 currCb 来传递数据。
jacobbubu /
Created October 17, 2019 08:49
Create a github repo. using the name from package.json and then put the repo's url back to `package.repository`
name=`node -e "process.stdout.write((require('./package.json').name.replace(/^@[\w\d\-\_]+\//, '')))"`
if [ -z ${name+x} ]; then
echo 'No "name" field found in package.json'
output=`gh re --browser false --new $name`
repo=`echo $output | grep -Eo '(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'`
echo $repo | `node -e "process.stdin.resume();process.stdin.setEncoding('utf8');var gitUrl = '';process.stdin.on('data', function(chunk) { gitUrl = chunk.split('\n')[0]; });process.stdin.on('end', function() {var fs=require('fs');var pkg=require('./package.json');pkg.repository = { type: 'git', url: gitUrl };fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2), 'utf8');})"`
jacobbubu /
Created August 20, 2017 07:15
Run Dgraph docker image on another port
docker run -it -p 8081:8081 -v ~/dgraph-naive:/dgraph --name dgraph-naive dgraph/dgraph dgraph --bindall=true --memory_mb 2048 --port 8081
jacobbubu / tennisKata.js
Created April 11, 2017 07:53
Flow-type example for Tennis Kata
/* @flow */
type Point = 'Love' | 'Fifteen' | 'Thirty';
type Deuce = 'Deuce';
type PlayerOne = 'Player1';
type PlayerTwo = 'Player2';
type Player = PlayerOne | PlayerTwo;
type GameOfPlayer = {
gameOfPlayer: Player
jacobbubu / blender-multi_gpu.markdown
Created January 7, 2017 02:53 — forked from Fweeb/blender-multi_gpu.markdown
Rendering in Blender on a machine with multiple GPUs

Rendering in Blender on a machine with multiple GPUs

So here's the premise: For scenes that take around a minute or less to render, performance is actually worse if you render on all of the cards with a single instance of Blender. This is because (AFAIK) there's a bit of additional time necessary to collect the render results from each card and stitch them together. That time is a fixed short duration, so it's negligible on larger/longer render jobs. However, on shorter render jobs, the 'stitch time' has a much more significant impact.

I ran into this with a machine I render on that has 4 Quadro K6000s in it. To render animations, I ended up writing a few little scripts to facilitate launching 4 separate instances of Blender, each one tied to one GPU. Overall rendertime was much shorter with that setup than one instance of Blender using all 4 GPUs.

The setup works basically like this. In my .blend file, I embed 4 text files,,,, and `batch-rende

jacobbubu /
Created October 19, 2016 08:54
assign = (target, firstSource) ->
if !target?
throw new TypeError('Cannot convert first argument to object')
to = Object(target)
hasPendingException = false
pendingException = undefined
i = 1
while i < arguments.length
nextSource = arguments[i]
jacobbubu / countries.json
Created April 9, 2015 07:13
Chinese country names and their ISO code
"ISO2": "AD",
"ISO3": "AND",
"DIGITS": "20",
"ISO-3166-2": "ISO 3166-2:AD",
"English": " Andorra",
"China": "安道尔",
"Taiwan": "安道爾",
"Hongkong": "安道爾",
jacobbubu / compactTimezone.json
Last active December 17, 2015 23:29
Very compact and easy to use timezone + daylight saving table. Data comes from [Oslon timezone database]( (ver. 2013-04-20).
"Africa/Abidjan": {
"offset": 0,
"dst": []
"Africa/Accra": {
"offset": 0,
"dst": []
"Africa/Addis_Ababa": {
jacobbubu / country.json
Created May 28, 2013 12:26
Link country table from Weibo to's data.
This file has been truncated, but you can view the full file.
"weiboCode": "005",
"name": "Argentina",
"geoNames": {
"countryId": "3865483",
"alternateNames": [
"name": "Argentinië",
"lang": "af"
jacobbubu / province.json
Created May 28, 2013 12:23
Link province table of Weibo to's data.
"weiboProvCode": "001011",
"name": "Beijing",
"countryCode": "CN",
"geoNames": {
"alternateNames": [
"name": "",
"lang": "link"