Skip to content

Instantly share code, notes, and snippets.

View jcouyang's full-sized avatar
🈚
💢

Jichao Ouyang jcouyang

🈚
💢
View GitHub Profile

What is Promises

Promise is a proxy for a value not knowing when its creation time. It provide 2 Methods then and catch, which return promise so they can be chained.

Promise.prototype.then(onFulfilled, onRejected)

Appends fullfillment and rejection handlers to the promise, and returns a new promise resolving to the return value of the called handler.

Promise.prototype.catch(onRejected)

Appends a rejection handler callback to the promise, and returns a new promise resolving to the return value of the callback if it is called, or to its original fulfillment value if the promise is instead fulfilled.

@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 / 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 / all github 887 emojis.md
Last active February 5, 2018 08:05
all github 887 emoji

💯 👍 👎 🔢 🎱 🅰️ 🆎 🔤 🔡 🉑 🚡 ✈️ ⏰ 👽 🚑 ⚓ 👼 💢 😠 😧 🐜 🍎 ♒ ♈ ◀️ ⏬ ⏫ ⬇️ 🔽 ▶️ ⤵️ ⤴️ ⬅️ ↙️ ↘️ ➡️ ↪️ ⬆️ ↕️ 🔼 ↖️ ↗️ 🔃 🔄 🎨 🚛 😲 👟 🏧 🅱️ 👶 🍼 🐤 🚼 🔙 🛄 🎈 ☑️ 🎍 🍌 ‼️ 🏦 📊 💈 ⚾ 🏀 🛀 🛁 🔋 🐻 🐝 🍺 🍻 🪲 🔰 🔔 🍱 🚴 🚲 👙 🐦 🎂 ⚫ 🃏 ⬛ ◾ :

@jcouyang
jcouyang / learnjulia.jl
Last active May 23, 2020 10:20
Y 分钟学 Julia
# 单行注释只需要一个井号
#= 多行注释
只需要以 '#=' 开始 '=#' 结束
还可以嵌套.
=#
####################################################
## 1. 原始类型与操作符
####################################################
@jcouyang
jcouyang / atom workspaceView events
Last active May 31, 2018 01:32
the atom workspaceView events
```
application:about: "Application: About"
application:bring-all-windows-to-front: "Application: Bring All Windows To Front"
application:hide: "Application: Hide"
application:hide-other-applications: "Application: Hide Other Applications"
application:minimize: "Application: Minimize"
application:new-file: "Application: New File"
application:new-window: "Application: New Window"
application:open: "Application: Open"
application:open-dev: "Application: Open Dev"
@jcouyang
jcouyang / 00 Setup Env.md
Last active September 8, 2016 01:44
Build Yourself a Backbone.js Step by Step

Install Node

brew install node

node here is use for setup tools like grunt and mocha

npm install -g grunt

grunt is js build tool.

@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 / 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 / vpn
Last active August 29, 2015 14:03
connect cisco anyconnect in terminal
#!/bin/sh
/opt/cisco/anyconnect/bin/vpn -s $1 blur.blur.com <<"EOF"
0
your.name
your.password
y
exit
EOF