Skip to content

Instantly share code, notes, and snippets.

@ruanyf
ruanyf / gist:4670316
Last active December 11, 2015 22:29
A bookmarklet which turns your browser into a notepad. Based on https://coderwall.com/p/lhsrcq
data:text/html, <html style="background-color:FFFFCC;"><title>Editor</title><textarea style="margin:0;padding:0;font-size: 1.5em; background-color:FFFFCC;width: 100%; height: 100%; border: none; outline: none" placeholder="Use Ctrl+S to save ..." autofocus />
@ruanyf
ruanyf / tracker
Created February 18, 2015 00:45
Tracker List
http://94.228.192.98/announce
http://anisaishuu.de:2710/announce
http://bigfoot1942.sektori.org:6969/announce
http://bt2.careland.com.cn:6969/announce
http://exodus.desync.com/announce
.dance
.democrat
.rich
.farm
.guru
.codes
.sale
.video
.garden
.fashion
@ruanyf
ruanyf / gist:cae49b92b0bd43c4d57d
Created March 4, 2015 03:18
JavaScript作用域
function a(x,y){
y = function() { x = 2; };
return function(){
var x = 3;
y();
console.log(x);
}.apply(this, arguments);
}
a();
@ruanyf
ruanyf / require.js
Created May 20, 2015 08:36
require() in browser
function require(p){
var path = require.resolve(p)
, mod = require.modules[path];
if (!mod) throw new Error('failed to require "' + p + '"');
if (!mod.exports) {
mod.exports = {};
mod.call(mod.exports, mod, mod.exports, require.relative(path));
}
return mod.exports;
}
@ruanyf
ruanyf / key.md
Created February 4, 2016 09:04
3 Ways of Generating SSH Keys: OpenSSH, OpenSSL and GPG
# OpenSSH
# 运行后,要求用户提供密钥文件名
# 然后在当前目录生成两个密钥文件:id_rsa(私钥)和id_rsa.pub(公钥)
$ ssh-keygen -t rsa -b 4096 -C "your.email@service.com"

# OpenSSL
# 生成私钥,然后生成公钥
$ openssl genrsa -out private_key.pem 4096
$ openssl rsa -pubout -in private_key.pem -out public_key.pem
@ruanyf
ruanyf / proxy.js
Created November 28, 2016 06:41
使用 Proxy 实现观察者模式
// 实现
const queuedObservers = new Set();
const observe = fn => queuedObservers.add(fn);
const observable = obj => new Proxy(obj, {set});
function set(target, key, value, receiver) {
const result = Reflect.set(target, key, value, receiver);
queuedObservers.forEach(observer => observer());
return result;
@ruanyf
ruanyf / map-vs-flatmap.js
Created January 19, 2017 10:47
map vs. flatMap
const map = (array, func) => (
array.map(func)
);
const flatMap = (array, func) => (
array.reduce((result, element) => (
result.concat(func(element))
), [])
);
@ruanyf
ruanyf / default-parameter-scope.js
Created January 20, 2017 07:03
默认参数的作用域
// 情况一
let str = 'outer';
function foo(x = () => str) {
let str = 'inner';
console.log(x()); // outer
}
foo();
@ruanyf
ruanyf / default-parameter-by-express.js
Created January 20, 2017 09:21
默认参数不是传值调用
let x = 99;
function foo(p = x + 1) {
console.log(p);
}
foo() // 100
x = 100;
foo() // 101