Skip to content

Instantly share code, notes, and snippets.

View leeoniya's full-sized avatar
😕
shaving bytes and milliseconds. dependencies: {}

Leon Sorokin leeoniya

😕
shaving bytes and milliseconds. dependencies: {}
View GitHub Profile
function stats(arr) {
arr = arr.slice().sort();
var n = arr.length;
var sum = arr.reduce((acc, val) => acc + val, 0);
var prod = arr.reduce((acc, val) => acc * val, 1);
var amean = sum / n;
var gmean = Math.pow(prod, 1 / n);
var median = n % 2 === 0 ? (arr[n / 2 - 1] + arr[n / 2]) / 2 : arr[(n - 1) / 2];
var variance = 0;
var stddev = 0;
@leeoniya
leeoniya / letsencrypt_2017.md
Created December 31, 2017 02:54 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two main modes to run the Let's Encrypt client (called Certbot):

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80).

In the following, we're setting up mydomain.com. HTML is served from /var/www/mydomain, and challenges are served from /var/www/letsencrypt.

<!doctype html>
<html>
<head>
<script>
domvm = (function() { "use strict";
var doc = document;
var emptyObj = {};
var isArr = Array.isArray;
function VNode() {}
<!doctype html>
<html>
<head>
<script src="https://cdn.rawgit.com/leeoniya/domvm/3.x-dev/dist/nano/domvm.nano.js"></script>
</head>
<body>
<script>
// http://imgur.com/a/YATqh
// https://cdn.rawgit.com/leeoniya/6149d983cd128ca6ac7c06e9dd3bd80f/raw/fe86cef4cc97aad1b89ef685643afa8590763a66/domvm-memleak.html
<!doctype html>
<html>
<head>
<script src="https://cdn.rawgit.com/leeoniya/domvm/3.x-dev/dist/nano/domvm.nano.js"></script>
</head>
<body>
<script>
// http://imgur.com/a/YATqh
var el = domvm.defineElement;
<!doctype html>
<html>
<head>
<script src="https://rawgit.com/leeoniya/domvm/3.x-dev/dist/pico/domvm.pico.min.js"></script>
</head>
<body>
<style>
h1 {
font-size: 4em;
}
@leeoniya
leeoniya / gist:64c6d859e0ebd0a3f945f02669a9b624
Created July 2, 2017 13:56 — forked from micho/gist:728639
Throttle and debounce examples
// Run the function as soon as it's called, but prevent further calls during `delay` ms
// Example: function.throttle(200) will only run function() once every 200 ms.
// Useful, for example, to avoid constant processing while typing in a live search box.
Function.prototype.throttle = function(delay) {
var fn = this
return function() {
var now = (new Date).getTime()
if (!fn.lastExecuted || fn.lastExecuted + delay < now) {
fn.lastExecuted = now
fn.apply(fn, arguments)
<!doctype html>
<html>
<head></head>
<body>
<ul id='cycleResults'></ul>
<div id="result"></div>
<br>
<button id="btn">Run Tests</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.2/lodash.min.js"></script>
<!doctype html>
<html>
<head></head>
<body>
<ul id='cycleResults'></ul>
<div id="result"></div>
<br>
<button id="btn">Run Tests</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.2/lodash.min.js"></script>
<!doctype html>
<html>
<head></head>
<body>
<ul id='cycleResults'></ul>
<div id="result"></div>
<br>
<button id="btn">Run Tests</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.2/lodash.min.js"></script>