Skip to content

Instantly share code, notes, and snippets.

/*
The MIT License (MIT)
Copyright (c) 2014 Ismael Celis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@dhilip89
dhilip89 / dht-walkthrough.md
Created April 16, 2019 13:04 — forked from gubatron/dht-walkthrough.md
DHT walkthrough notes

DHT Walkthrough Notes

I've put together these notes as I read about DHT's in depth and then learned how the libtorrent implementation based on the Kademlia paper actually works.

What problem does this solve?

400,000,000,000 (400 billion stars), that's a 4 followed by 11 zeros. The number of atoms in the universe is estimated to be around 10^82. A DHT with keys of 160 bits, can have 2^160 possible numbers, which is around 10^48

@dhilip89
dhilip89 / javascript-promise-timeout.js
Created October 27, 2018 17:57 — forked from john-doherty/javascript-promise-timeout.js
Adds a timeout to a JavaScript promise, rejects if not resolved within timeout period
/**
* wraps a promise in a timeout, allowing the promise to reject if not resolve with a specific period of time
* @param {integer} ms - milliseconds to wait before rejecting promise if not resolved
* @param {Promise} promise to monitor
* @Example
* promiseTimeout(1000, fetch('https://courseof.life/johndoherty.json'))
* .then(function(cvData){
* alert(cvData);
* })
* .catch(function(){
@dhilip89
dhilip89 / test_v8.js
Created September 30, 2018 06:00 — forked from yuvalbl/test_v8.js
Test cases on v8
// run with :
// node --trace_deopt --allow-natives-syntax FILENAME
function adder(a, b) {
return new Function('a', 'b', 'return b%2 ? a + b : b%3 ? a - b : b%5 ? b / a : a * b')(a, b);
}
function addereval(a, b) {
return eval('b%2 ? a + b : b%3 ? a - b : b%5 ? b / a : a * b');
}
@dhilip89
dhilip89 / SevenZipHelper.cs
Created September 21, 2018 09:38 — forked from ststeiger/SevenZipHelper.cs
LZMA-Compression with SevenZip SDK
// http://www.nullskull.com/a/768/7zip-lzma-inmemory-compression-with-c.aspx
// http://www.7-zip.org/sdk.html
namespace SevenZip.Compression.LZMA
{
public static class SevenZipHelper
{
@dhilip89
dhilip89 / transform.js
Created September 3, 2018 07:59 — forked from mbostock/transform.js
2D Matrix Decomposition
d3.transform = function(string) {
d3_transformG.setAttribute("transform", string);
var m = d3_transformG.transform.baseVal.consolidate().matrix;
if (m.a * m.d - m.b * m.c) return new d3_transform(m); // if invertible
};
// Compute x-scale and normalize the first row.
// Compute shear and make second row orthogonal to first.
// Compute y-scale and normalize the second row.
// Finally, compute the rotation.
@dhilip89
dhilip89 / Matrix.md
Created May 28, 2018 01:22 — forked from nadavrot/Matrix.md
Efficient matrix multiplication

High-Performance Matrix Multiplication

This is a short post that explains how to write a high-performance matrix multiplication program on modern processors. In this tutorial I will use a single core of the Skylake-client CPU with AVX2, but the principles in this post also apply to other processors with different instruction sets (such as AVX512).

Intro

Matrix multiplication is a mathematical operation that defines the product of

@dhilip89
dhilip89 / support-table-webgl1-webgl2.md
Created May 26, 2018 05:36 — forked from TimvanScherpenzeel/support-table-webgl1-webgl2.md
Support table - WebGL & WebGL2 support
Device OS OS version Browser Browser version WebGL WebGL2
Apple iPad 5th iOS 11.0.3 Mobile Safari 11.0 X
Apple iPad Air 2 iOS 8.4 Mobile Safari 8.0 X
Apple iPad Mini 3 iOS 8.1.2 Mobile Safari 8.0 X
Apple iPad Pro iOS 11.2.1 Mobile Safari 11.0 X
Apple iPhone 5S iOS 8.1.3 Mobile Safari 8.0 X
Apple iPhone 6 Plus iOS 8.1 Mobile Safari 8.0 X
Apple iPhone 6 iOS 8.1.3 Mobile Safari 8.0 X
Apple iPhone 6S Plus iOS 9.0.1 Mobile Safari 9.0 X
@dhilip89
dhilip89 / inlineworker.js
Created May 8, 2018 00:32 — forked from SunboX/inlineworker.js
Create web workers without a separate worker JS files. Source: http://jsbin.com/owogib/8/
function worker() {
setInterval(function() {
postMessage({foo: "bar"});
}, 1000);
}
var code = worker.toString();
code = code.substring(code.indexOf("{")+1, code.lastIndexOf("}"));
var blob = new Blob([code], {type: "application/javascript"});
@dhilip89
dhilip89 / duffs_device.js
Created May 2, 2018 01:47 — forked from JamieMason/duffs_device.js
JavaScript Duff's Device
/**
* 1. Original JS Implementation by Jeff Greenberg 2/2001 - http://home.earthlink.net/~kendrasg/info/js_opt/
* 2. (fast duff's device) from an anonymous donor to Jeff Greenberg's site
* 3. (faster duff's defice) by Andrew King 8/2002 for WebSiteOptimization.com
* 4. bug fix (for iterations<8) by Andrew B. King April 12, 2003
*/
function duffsDevice (iterations) {
var testVal = 0,
n = iterations % 8;