Skip to content

Instantly share code, notes, and snippets.

View wongyouth's full-sized avatar

Ryan Wang wongyouth

View GitHub Profile
@wongyouth
wongyouth / ssh-tunnel.sh
Last active December 25, 2017 06:04
SSH tunnel 在家链接公司Mac电脑
# 1. 公司电脑打开 远程登录 功能
# 2. 公司电脑连接到 服务器,并监听服务器本地 3456 端口
# 当有链接到服务器 3456 时,tunnel 回公司电脑的 22 端口,及 sshd 服务
ssh -NR 3456:localhost:22 server
# 3. 在家链接公司服务器 3456 端口
# 假设服务器登录时不需要输入密码。
1. Map 没有来自 Object.prototype 的属性,比如: __proto__, toString
2. Map 中的key可以是任何类型,Object 只能是 String
3. Map 对象迭代时的顺序与加入时的顺序一致。
ref: https://ponyfoo.com/articles/es6-maps-in-depth
@wongyouth
wongyouth / gcd.exs
Created March 29, 2018 15:44
求最大公约数
# Write a function gcd(x,y) that finds the greatest common divisor between two nonnegative integers.
# Algebraically, gcd(x,y) is x if y is zero; it’s gcd(y, rem(x,y)) otherwise.
defmodule Mathx do
def gcd(x, 0) do
x
end
def gcd(x, y) do
gcd(y, rem(x,y)
end
@wongyouth
wongyouth / Makefile
Created April 12, 2018 03:32
convert json to csv sample
%.csv : %.json
@cat $< | $(MAKE) -s words | $(MAKE) -s csv > $@
# {
# "code": "0",
# "data": {
# "block": [
# {
# "type": "text",
# "line": [
@wongyouth
wongyouth / fab.js
Created May 4, 2018 07:23
Use generator to calc fabonacci in javascript
function * fab (max) {
let [n, a, b] = [0, 0, 1]
while (n++ < max) {
[a, b] = [b, a + b]
yield b
}
}
for (let n of fab(5)) {
console.log(n)
@wongyouth
wongyouth / mongo-memo.md
Created June 20, 2018 06:42
Some memo to use mongodb

Mongodb

Mongo Console Shell

db.coll.find().forEach(doc => {})

loop all documents and update

db.coll.find().forEach(doc => { // ... change doc

// update

{
// Place your snippets for vue here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
@wongyouth
wongyouth / getQueryParams.js
Created July 26, 2018 03:32
getQueryParams
// https://github.com/nuxt/example-auth0/blob/master/utils/auth.js
const getQueryParams = () => {
const params = {}
window.location.href.replace(/([^(?|#)=&]+)(=([^&]*))?/g, ($0, $1, $2, $3) => {
params[$1] = $3
})
return params
}
@wongyouth
wongyouth / gist:2390e5e511040cb6a512cb1416773e07
Created August 10, 2018 06:02 — forked from sartak/a.md
Anki 2 annotated schema
-- see https://github.com/ankidroid/Anki-Android/wiki/Database-Structure for a more maintained version of this
-- cards are what you review. easy!
CREATE TABLE cards (
id integer primary key,
-- the epoch milliseconds of when the card was created
nid integer not null,
-- notes.id
did integer not null,
-- deck id (available in col table)