Skip to content

Instantly share code, notes, and snippets.

View jcouyang's full-sized avatar
🈚
💢

Jichao Ouyang jcouyang

🈚
💢
View GitHub Profile
@jcouyang
jcouyang / README.org
Last active December 9, 2023 16:46
Promise All with Limit of Concurrent N

The Promise All Problem

in case of processing a very large array e.g. Promise.all(A_VERY_LARGE_ARRAY_OF_XHR_PROMISE)

which would probably blow you browser memory by trying to send all requests at the same time

solution is limit the concurrent of requests, and wrap promise in thunk

Promise.allConcurrent(2)([()=>fetch('BLAH1'), ()=>fetch('BLAH2'),...()=>fetch('BLAHN')])

@jcouyang
jcouyang / why-curry-helps.md
Last active February 20, 2023 21:09
为什么要柯里化(why-curry-helps)slide http://git.io/why-curry-helps 📈

还记得 Haskell Curry吗,

多巧啊, 人家姓 Curry 名 Haskell, 难怪 Haskell 语言会自动柯里化, 呵呵. 但是不奇怪吗, 为什么要柯里化呢. 为什么如此重要导致 Haskell 会默认自动柯里化所有函数, 不就是返回一个部分配置好的函数吗.

我们来看一个 Haskell 的代码.

max 3 4
(max 3) 4
@jcouyang
jcouyang / contribution-svg.rb
Last active February 11, 2023 22:32
SVG image for your github contributions calendar
require "nokogiri"
require "open-uri"
url = "https://github.com/#{params['username']}"
document = Nokogiri::HTML(open(url))
contrib_boxes = document.css('svg.js-calendar-graph-svg')[0]
contrib_boxes['xmlns']="http://www.w3.org/2000/svg"
width = (params['width']||54*13-2).to_i
height = (params['height']||89).to_i
contrib_boxes.css('text').remove
contrib_boxes['width']=(width+11).to_s+'px'
@jcouyang
jcouyang / 2013-05-25-flash-dd-wrt-and-install-transmission.md
Last active January 21, 2023 07:03
flash dd-wrt and install transmission in WNR2200 router

Prepaire

  • USB disk 格式化成ext2/3格式, with gparted in linux. 根据官方wiki, 最新的v24已经 不用jffs了, 目前的dd-wrt目录结构是这样的:
/tmp ## mounted on the RAM drive of dd-wrt
/jffs  ## builti-in flash, 已经disable
/mnt ## used for rw drive
@jcouyang
jcouyang / surfingKeys.js
Last active November 27, 2022 06:01
Firefox Surfingkeys Settings
settings.startToShowEmoji = 3;
settings.tabsMRUOrder = false;
settings.tabsThreshold = 4;
api.mapkey(';oc', 'Org Capture', function() {
location.href='org-protocol://capture?' +
new URLSearchParams({
template: 'x',
url: window.location.href,
title: document.title,

Keybase proof

I hereby claim:

  • I am jcouyang on github.
  • I am oyanglulu (https://keybase.io/oyanglulu) on keybase.
  • I have a public key ASDd7C_jnHrfyZ-hv7yEPxWFSwbOCfYOX_oqoujJ55JeXwo

To claim this, I am signing this object:

@jcouyang
jcouyang / Emacs linux.xml
Created January 26, 2021 02:13
Intellij Emacs Keymap
<keymap version="1" name="Emacs copy" parent="macOS For All">
<action id="$Copy">
<keyboard-shortcut first-keystroke="alt c" />
</action>
<action id="$Cut">
<keyboard-shortcut first-keystroke="shift delete" />
</action>
<action id="$Delete">
<keyboard-shortcut first-keystroke="delete" />
<keyboard-shortcut first-keystroke="ctrl d" />
@jcouyang
jcouyang / 2012-12-31-node-dot-js-vs-tornado-vs-php.markdown
Last active January 15, 2021 02:38
为什么事件驱动服务器这么火

本文基本上这为两篇文章的翻译和整合 -- Scalable networking And Why are event-driven server so great

OPPC模型瓶颈

传统服务器模型如Apache为每一个请求生成一个子进程。当用户连接到服务器的一个子进程就产生,并处理连接。每个连接获得一个单独的线程和子进程。当用户请求数据返回时,子进程开始等待数据库操作返回。如果此时另一个用户也请求返回数据,这时就产生了阻塞。

这种模式在非常小的工作负荷是表现良好,当请求的数量变得太大是服务器会压力过于巨大。 当Apache达到进程的最大数量,所有进程都变得缓慢。每个请求都有自己的线程,如果服务代码使用PHP编写时,每个进程所需要的内存量是相当大的[1]。

fork()操作延时

@jcouyang
jcouyang / replace_evernote.md
Last active July 9, 2020 01:05
Why do we still need Evernote since there is awesome gist.github.com

I'm a Emacs user and as you may know there is a awesome mode called gist.el, and since then, I found that it's completely my Evernote replacement. Why replace Evernote with gist?

  • code snippet (very significant reason)
  • Version Control, gist actually is a git repo, so you have all the commit history.
  • Social, fork, star, and comment as well.
  • I have emacs open all the time my machine is on. no reason open another app for note taking.
  • annoying Evernote text editor without emacs like shotcut.
  • Github Flavored Markdown(with emoji), or even org-mode and reStructuredText support.

But since there are not so many Emacsers, I create a Atom package glist which do the exact thing as gist.el for Atom.io. as atom support markdown instant preview, note taking with gist is even better.

@jcouyang
jcouyang / stop-asking.el
Last active June 29, 2020 14:01
disable emacs asking following git symbolink
; 当要打开一个symbolink的时候,如果symbollink到一个被git(或者其他vc)管理的文件时,emacs老问
; Symbolic link to Git-controlled source file; follow link? (y or n)
; 配置下这个变量就好了
(setq vc-follow-symlinks nil)
; nil 表示 不要问,no
; ask 表示每次都问
; t 表示follow