Skip to content

Instantly share code, notes, and snippets.

@AntoineMurat
AntoineMurat / script.py
Last active December 16, 2018 00:03
Average number of leaves in an uniformly random, label-less, binary tree with a total number of nodes of n.
# Fast nCk with memoization.
memo_b = {}
def binomial(n, k):
"""
A fast way to calculate binomial coefficients by Andrew Dalke.
See http://stackoverflow.com/questions/3025162/statistics-combinations-in-python
"""
if (n, k) not in memo_b:
if 0 <= k <= n:
ntok = 1
@AntoineMurat
AntoineMurat / import.js
Created May 17, 2017 11:05
[HTML5 / JS / 2017] Load JSON/text file client-side (promise or callback)
/*
* Load an object from a JSON file on client's computer.
*/
const loadJSON = callback => {
if (callback)
return loadJSONCallback(callback)
return loadJSONPromise()
}
const loadJSONCallback = callback => {
{
"general": {
"numberOfIterations": 20
},
"paths": {
"vertices": [
{
"id": 0,
"position": {
"x": 124.24723822180408,
@AntoineMurat
AntoineMurat / quickDemo.js
Last active April 8, 2018 13:05
ES6, démonstration pour mes kheys (Arrow functions, Promises, Templates & let)
// let à la place de var pour un scope de bloc et non de fonction.
// Ecritures équivalentes d'une fonction :
//
// function doubler(x){return 2*x}
// doubler = function(x){return 2*x}
//
// Mieux :
// let doubler = function(x){return 2*x}
//