Skip to content

Instantly share code, notes, and snippets.

View jcouyang's full-sized avatar
🈚
💢

Jichao Ouyang jcouyang

🈚
💢
View GitHub Profile
@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

@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 / 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 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.

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

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

————————–> **这个Org文件** <————————

@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

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 / 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
@jcouyang
jcouyang / monad.md
Last active August 29, 2015 14:04
你造Promise 就是 Monad 吗

Monad 这个概念好难解释, 你可以理解为一个 Lazy 或者是状态未知的盒子. 听起来像是薛定谔猫(估计点进去你会更晕了). 其实就是的, 在你打开这个盒子之前, 你是不知道里面的猫处在那种状态.

Monad 这个黑盒子, 里面到底卖的神马药,我们要打开喝了才知道.

等等, 不是说好要解释 Either 的吗, 嗯嗯, 这里就是在解释 Either. 上节说 Either 是一个 Functor, 可以被 fmap over. 怎么这里又说道黑盒子了? 好吧, Monad 其实也是 Functor. 还记得我说的 Functor 其实是一个带 context 的盒子吗. 而 fmap 使得往盒子里应用函数变换成为了可能.

Either

先来看看 Either 这种类型会干什么事情. Either 表示要不是左边就是右边的值, 因此我们可以用它来表示薛定谔猫, 要不是活着, 要不死了. Either 还有个方法: either

var Request = require("sdk/request").Request;
var request = function(url, method, data){
var res = $.Deferred();
Request({
url: url,
content: data,
onComplete: function (response) {
res.resovle(response.json);
}
})[method]();