Skip to content

Instantly share code, notes, and snippets.

View MinweiShen's full-sized avatar

Minwei Shen MinweiShen

  • Bytedance
  • Shanghai, China
View GitHub Profile
@MinweiShen
MinweiShen / syscall_example
Created January 22, 2015 07:05
a simple example of using syscall()
#include <stdio.h>
#include <fcntl.h>
/*arguments of syscall can be found on http://blog.rchapman.org/post/36801038863/linux-system-call-table-for-x86-64*/
int main(int argc, char* argv[]){
const char* fileName[7] = "me.txt";
//create a file that the owner can read/write. flags can be found easily by google
syscall(SYS_open,fileName,O_CREAT,S_IRUSR|S_IWUSR);
//open it as write only
int fd = syscall(SYS_open,fileName,O_WRONLY);
@MinweiShen
MinweiShen / sublime_setting
Last active August 29, 2015 14:16
Sublime Text 3 User setting
{
"color_scheme": "Packages/Color Scheme - Default/Espresso Libre.tmTheme",
"font_size": 13,
"ignored_packages":
[
"Vintage"
],
// show spaces
"draw_white_space": "all",
// the theme
@MinweiShen
MinweiShen / Misra_Gries.py
Created March 24, 2015 01:15
Misra_Gries algorithm
def Misra_Gries(file,k):
result = {}
to_delete = []
with open(file,"r") as f:
for l in f.readlines():
chars = l.split()
for ch in chars:
to_delete = []
if ch in result:
result[ch] = result[ch] + 1
@MinweiShen
MinweiShen / gist:939396ef075bdadd156d
Created January 1, 2016 20:23
my slate configuration
# 定义查找窗口切换时显示在每个窗口图标的字符,类似于Vim的easymotion插件
alias showHintsLeftHand hint ASDFQWERT
alias showNormalHint hint QWERTASDFGZXCVYUIOPHJKLBNM
#KANA is remap to F18
#EISUU is remap to F19
# 一些位置定义:全屏,左半屏,右半屏等等
@MinweiShen
MinweiShen / gist:ee7538dfff14d1359343
Created January 1, 2016 20:23
Karabiner configuration
<?xml version="1.0"?>
<root>
<item>
<name>Remap KANA to F18</name>
<identifier>space_cadet.kana_to_f18</identifier>
<autogen>__KeyToKey__ KeyCode::JIS_KANA, KeyCode::F18</autogen>
</item>
@MinweiShen
MinweiShen / scrapy_save_chinese_pipeline.py
Created February 26, 2016 18:17
scrapy json 保存中文
import json,codecs
class WebCrawlerScrapyPipeline(object):
def __init__(self):
self.file = codecs.open('item.json', 'wb', encoding='utf-8')
def process_item(self, item, spider):
line = json.dumps(dict(item)) + '\n'
# print line
return month === 1 ?
((year % 4 ===0 && year%100!==0) or year %400===0) ? 28 : 29) : /* February */
((month % 2) ^ (month < 7) ? 31 : 30); /* Other months */
const get = require('lodash/get');
function transform(source, schema, ...ext) {
const result = Object.create(null);
for (let prop of Object.getOwnPropertyNames(schema)) {
if (typeof schema[prop] === 'function') {
result[prop] = schema[prop](source[prop], source);
} else {
result[prop] = schema[prop];
}
class Cache():
def __init__(self):
self._cache = {
'_index': {}
}
def set(self, key, value):
self._cache[key] = value
self.index(key)
@MinweiShen
MinweiShen / asyncPool
Last active June 21, 2021 05:44
asyncPool.js
async function asyncPool(poolSize, inputArray, fn) {
const all = [];
const inProgress = [];
for (const data of inputArray) {
const p = new Promise(resolve => resolve(fn(data)));
all.push(p);
if (inputArray.length > poolSize) {
const e = p.then(() => inProgress.splice(inProgress.indexOf(p), 1));
inProgress.push(e);
if (inProgress.length >= poolSize) {