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 / Program.cs
Last active February 12, 2020 10:14
Fun Parser
using System;
using System.Collections.Generic;
namespace FunParser
{
class ParseResult
{
public string Method { get; set; }
public string Path { get; set; }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
namespace DownloadTaskDemo
{
public class DownloadTaskManager
{
@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 / htmlpl.html
Created November 7, 2018 20:46
[Fun] HTML is a programming language!!!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>HTML is a programming language!!!</title>
</head>
<body>
<script>
@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