Skip to content

Instantly share code, notes, and snippets.

View avoronkin's full-sized avatar

Alexandr Voronkin avoronkin

  • Saint-Petersburg
View GitHub Profile
function waterfall (fns = []) {
return async (...args) => {
return fns.reduce((p, fn) => p.then(args => fn.apply(this, args)), Promise.resolve.call(this, args))
}
}
@luckydev
luckydev / gist:b2a6ebe793aeacf50ff15331fb3b519d
Last active October 22, 2022 14:03
Increate max no of open files limit in Ubuntu 16.04/18.04 for Nginx
# maximum capability of system
user@ubuntu:~$ cat /proc/sys/fs/file-max
708444
# available limit
user@ubuntu:~$ ulimit -n
1024
# To increase the available limit to say 200000
user@ubuntu:~$ sudo vim /etc/sysctl.conf
@malko
malko / enchainProxifier.js
Created March 8, 2017 13:33
add a fluent interface on object with promise methods
const enchainProxifier = (target, promise = Promise.resolve()) => {
return new Proxy(target, {
get(target, propName) {
if (propName === 'promise') {
return promise;
} else if (propName === 'then') {
return (...args) => promise.then(...args);
}
if (target[propName] instanceof Function) {
return (...args) => enchainProxifier(target, promise.then(() => target[propName](...args)));
@Yimiprod
Yimiprod / difference.js
Last active April 5, 2024 13:17
Deep diff between two object, using lodash
/**
* This code is licensed under the terms of the MIT license
*
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
@maxvyaznikov
maxvyaznikov / raw.js
Last active October 15, 2022 02:19
NodeJS, raw-socket, custom TCP/IPv4 SYN-packet sending
var raw = require("raw-socket");
var ip = require('ip');
var util = require('util');
function send(src_ip, src_port, dst_ip, dst_port) {
var socket = raw.createSocket({
protocol: raw.Protocol.TCP, // See http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
addressFamily: raw.AddressFamily.IPv4
});
@cvan
cvan / frameMessenger.js
Created May 27, 2015 22:09
wrapper class for BroadcastChannel
class FrameMessenger {
constructor(name) {
this._listeners = {};
this.name = name || 'frame';
this.bc = new BroadcastChannel(this.name);
this.bc.addEventListener('message', e => {
if (e.data && typeof e.data === 'object' && e.data.type) {
this.emit(e.data.type, e.data.data);
@yunano
yunano / consul-template.service
Created May 1, 2015 15:54
/etc/systemd/system/consul-template.service
[Unit]
Description=consul-template
Requires=network-online.target
After=network-online.target consul.service vault.service
[Service]
EnvironmentFile=-/etc/sysconfig/consul-template
Restart=on-failure
ExecStart=/usr/local/sbin/consul-template $OPTIONS -config=/etc/consul-template.d
@paulirish
paulirish / bling.js
Last active May 1, 2024 19:56
bling dot js
/* bling.js */
window.$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
}
NodeList.prototype.__proto__ = Array.prototype;
module.exports = {
/**
* Recipients of notificaton about new loan registered on website.
* Subject is parsed by jade
*/
'success-order-loan': {
from: 'boria1966@gmail.com',
to: 'boria1966@gmail.com',
subject: '| Новая заявка на заем #{id}, #{city}'
}
@denji
denji / nginx-tuning.md
Last active May 3, 2024 03:57
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.