Skip to content

Instantly share code, notes, and snippets.

View ivan-kleshnin's full-sized avatar
🏠
Working from home

Ivan Kleshnin ivan-kleshnin

🏠
Working from home
View GitHub Profile
let R = require("ramda")
let {Observable, Subject} = require("rx")
let scanFn = function (state, updateFn) {
if (typeof updateFn != "function" || updateFn.length != 1) {
throw Error("updateFn must be a function with arity 1, got " + updateFn)
} else {
return updateFn(state)
}
}

Free port after manual kill

$ lsof -i :$PORT -- set desired port, e.g. 3000
$ kill $PID -- set discovered PID, e.g. 2227
let assert = require("assert");
function curryN(N, fn) {
let self = undefined;
let collectFn = Object.defineProperties(function (...args) {
if (this) {
self = this;
}
if (args.length >= N) {
return fn.apply(self, args);
@ivan-kleshnin
ivan-kleshnin / test.parse5.js
Created January 29, 2016 11:15
Test Parse5
import Fs from "fs";
import Parse5 from "parse5";
import MemWatch from "memwatch-next";
import humanFormat from "human-format";
process.on("unhandledRejection", function (reason, p) {
throw reason;
});
let timeScale = new humanFormat.Scale({
@ivan-kleshnin
ivan-kleshnin / test.htmlparser2.js
Created January 29, 2016 11:15
Test HtmlParser2
import Fs from "fs";
import {Parser} from "htmlparser2";
import MemWatch from "memwatch-next";
import humanFormat from "human-format";
process.on("unhandledRejection", function (reason, p) {
throw reason;
});
let timeScale = new humanFormat.Scale({
@ivan-kleshnin
ivan-kleshnin / lwip.wrapper.demo.js
Last active November 13, 2015 13:43
Lwip basic wrapper demo
/*
This wrapper
1. Reduces boilerplate. Lwip functions like .resize() are very low-level. See the code to get what I mean.
2. Adds sharpen to downsampling.
3. Has promise-based API
4. Operates on file buffers instead of image buffers to make operations immutable.
Use Lwip directly if you experience bottleneck and need to batch operations for performance.
Use this wrapper (it's forks) in other cases.
*/
import Path from "path";
const splitPathRe =
/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
function assertPath(path) {
if (typeof path !== 'string') {
throw new TypeError('Path must be a string. Received ' +
util.inspect(path));
}
@ivan-kleshnin
ivan-kleshnin / bash.npm_package_is_installed.sh
Created January 31, 2015 12:25
Check npm package is installed
function npm_package_is_installed {
if [ $(npm list --depth 0 --parseable true "${2}" | grep "${1}$") ]; then
echo "1"
else
echo "0"
fi
}
# npm_package_is_installed gulp
# npm_package_is_installed gulp -g
@ivan-kleshnin
ivan-kleshnin / lwip.utils.js
Last active August 29, 2015 14:12
Resize with lwip
// resolution is [width, height] structure
// Evaluate resolution by width (height doesn't matter, just keep it proportional)
function evalResolutionByWidth(requiredWidth, actualResolution) {
var actualWidth = actualResolution[0];
var actualHeight = actualResolution[1];
if (actualWidth > requiredWidth) {
var scale = actualWidth / requiredWidth;
return [requiredWidth, Math.round(actualHeight / scale)];
} else {
@ivan-kleshnin
ivan-kleshnin / .goaccessrc
Last active August 29, 2015 14:10
How to reveal hackers and spammers in standard nginx logs (OS X instruction)
# put this file in home folder
date_format %d/%b/%Y
log_format %h %^[%d:%^] "%r" %s %b "%R" "%u"