Skip to content

Instantly share code, notes, and snippets.

View jcouyang's full-sized avatar
🈚
💢

Jichao Ouyang jcouyang

🈚
💢
View GitHub Profile
@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()操作延时

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 / 2013-11-27-bdd-using-jasmine-jquery.org
Last active August 29, 2015 13:57
BDD using jasmine jquery

jasmine-jquery 来BDD 就是一个bug, 一个大bug

参加 TWU 时写 jasmine 测试的时候花了大量时间研究为什么不能绑定事件到 fixture. 这导致 teamate 和我自己都会认为我这个带头引入这么难用的 jasmine 的人简直是要杀千刀. 但是其实问题不是 jasmine 当然也不是我, 都是 jasmine-jquery

不管是 loadfixtures 还是 preload(fixtureUrl[, fixtureUrl, …]) 都无法 绑定事件到 fixtures

有同学问初学该有个什么starter-kit之类的, 虽然我之前也在用 emacs-starter-kit, 但是那玩意其实对 emacs 24 来说已经很鸡肋了. emacs 24 对包管理这块做的已经足够好,而且源也足够多, 因此, 配置 emacs 24 会变 得容易的多.

我也不知道在哪翻出来的这个 repo, 正好同时解决了新手配置以及文档化的问 题. 所以我决定从 starter-kit 迁过来, 这样以后只用维护

--------------------------> **这个Org文件** <------------------------

最近再一次偶然的机会在github上见到了这样一个repo http://www.github.com/donnfelker/android-bootstrap 能让你迅速搭建起基本ui和框架.但是基本上没有什么文档,非常可惜.环境搭好 了,却不知道在哪里加代码. 于是我玩几天准备把我的理解写一下,以供找不到文 档的同学可以快速上个手.

101 什么是 android bootstrap

http://www.androidbootstrap.com/images/ab-screenshot.png Android Bootstrap 其实是一堆框架的集合, 让你迅速搭好android 开发的基本

@jcouyang
jcouyang / 2013-06-11-use-mock-in-python.markdown
Created April 1, 2014 13:19
Evernote with emacs and org-mode

最近在用 nosetestsmock1 为 bottle 应用测试, 发现几个使用nosetests 要注意的 地方:

1 patch method of module

patch 一个导入 module 的 method, 因为 method 已经被导入到目标文件, 因此必须 要 patch 目标文件的 该方法, 而不是原 module.

@jcouyang
jcouyang / 2013-06-03-how-to-use-octopress-and-write-post-using-org-mode.org
Created April 1, 2014 12:54
How to Write Post Using Octopress Travis CI and Org Mode

getting started

Github page 上建博客本来就是很geek的事情, 用octopress来建博客可用说是 for ruby geeks, 因为可以用欢乐的rake <task> 来完成建立文章和发布等一系 列task. 当然他依赖于 Jekyll

如果wordpress的发布过程是这样的:

  • 打开wordpress
  • 点下new post
  • 在textarea中输入内容
@jcouyang
jcouyang / 2013-06-11-use-mock-in-python.markdown
Created March 30, 2014 02:52
How to use Mock testing Python

最近在用 nosetestsmock1 为 bottle 应用测试, 发现几个使用nosetests 要注意的 地方:

1 patch method of module

patch 一个导入 module 的 method, 因为 method 已经被导入到目标文件, 因此必须 要 patch 目标文件的 该方法, 而不是原 module.

@jcouyang
jcouyang / 2014-01-24-pure-and-secure-javascript-oauth-with-yql.org
Last active August 29, 2015 13:57
pure and secure javascript oauth with yql

It would be awesome if we can use OAuth in JavaScript purely in client side. before start to do that, please let me explain “OAuth2” with this picture in feeeew word (skip to section 2 YQL if you know OAuth2):

http://hueniverse.com/wp-content/uploads/2007/12/My-Endpoints-300x267.png

OAuth 2

OAuth 2 is widely use as authorize third party application without expose user’s password, OAuth2 using 2 steps verification. Take github as example:

There are 2 role in this story: Developer Oyang and User Lulu

[x/2 for x in range(2,10,2)]