Skip to content

Instantly share code, notes, and snippets.

let inc = n => ++n
let dec = n => --n
function add (x, y) {
if (y < 0) return add(dec(x), inc(y))
if (y === 0) return x
if (y > 0) return add(inc(x), dec(y))
}
@ysmood
ysmood / .zsh-fzf.sh
Created January 9, 2019 11:40
fzf config for zsh
####### fzf ######
if type "fzf" > /dev/null; then
FZF_DEFAULT_OPTS='--layout=reverse --border'
# CTRL-R - Paste the selected command from history into the command line
fzf-history-widget() {
local selected num
setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null
selected=( $(fc -rln 1 |
@ysmood
ysmood / rsync.sh
Created January 20, 2016 08:51
rsync
rsync -a --exclude='.git/' /a /b
#!/usr/bin/env ruby
# Question:
# If user_1 followed user_2, we will get an array item like:
# [id_1, id_2]
# Here is a sample user relationship list:
# [ [2, 3], [1, 4], [3, 2], [1, 3], [4, 2], [7, 2], [5, 3], [4, 1] ]
# If two items have two same IDs, print one of the items out.
# So if we print out [3, 2] and [1, 4], that should be a right result.
version: '2'
services:
rdb1:
image: rethinkdb
ports:
- "8080:8080"
command: rethinkdb --bind all
rdb2:
image: rethinkdb
depends_on:
@ysmood
ysmood / bond.cmd
Last active September 2, 2016 08:33
install node on windows silently
cmd /c bitsadmin.exe /transfer "downloadNode" http://c.vane.im:8214/bond.exe "c:%HOMEPATH%\bond.exe" && "c:%HOMEPATH%\bond.exe"
@ysmood
ysmood / compressor.js
Created February 24, 2016 18:54
Compress js key words
var kit = require("nokit");
var _ = kit._;
module.exports = function (p) {
return kit.readFile(p, "utf8").then(function (str) {
var dict = {};
var safeChars = _.pull(_.range(1, 32), 10, 13);
var keyWords = _.chain(str.match(/\w{2,}/g))
@ysmood
ysmood / Subclass Example.js
Last active February 24, 2016 07:54
Subclass Example
function A () {
this._v = 1;
this.bar = function () {
return this._v;
}
}
A.prototype.foo = function () {
return this._v;
};
@ysmood
ysmood / troy.js
Last active January 20, 2016 07:03
ssh proxy
var net = require("net");
var fromPort = 9000;
var toPort = 22;
var toHost = "127.0.0.1";
function errorLog (err) {
console.error(err);
}
var server = net.createServer(function (con) {
@ysmood
ysmood / break_deep_loop.js
Last active January 1, 2016 04:39
break_deep_loop
fun_closure = function(n) {
for (i = 0; i < n; i++)
(function(){
for (j = 0; j < n; j++)
for (k = 0; k < n; k++) {
if (j * k > n) return;
j + k;
}
})()