This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_random_element(dictionary): | |
S = 0 | |
r = random.random() | |
for (key, val) in dictionary.items(): | |
S += val | |
if S > r: | |
return key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From <https://github.com/ondras/rot.js/blob/master/src/rng.js> | |
// I have no idea how this works | |
function getNormal (mean, stddev) { | |
do { | |
var u = 2*this.getUniform()-1; | |
var v = 2*this.getUniform()-1; | |
var r = u*u + v*v; | |
} while (r > 1 || r == 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define (last items) | |
"Get the last element of ITEMS" | |
(foldl (lambda (x acc) x) (void) items)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.lwjgl.Version | |
import org.lwjgl.glfw._ | |
import org.lwjgl.opengl.GL | |
println("LWJGL Version "+ Version.getVersion() +" is working.") | |
// Print to console on error | |
GLFW.glfwSetErrorCallback( | |
GLFWErrorCallback.createPrint(System.err) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function iota (n, zero = 0, delta = 1) { | |
return (new Array(n)).fill(null).map((_, i) => zero + delta * i); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "tail-call-ru", | |
"version": "0.0.1", | |
"description": "My personal site", | |
"main": " ", | |
"dependencies": {}, | |
"devDependencies": { | |
"babel-cli": "^6.26.0", | |
"babel-preset-es2015": "^6.24.1", | |
"babel-preset-react": "^6.24.1", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Coll zero padding hack | |
// See <https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date#comment52315011_30272803> | |
(new Array(100)).fill(null).map((_, i) => ("0" + i).slice(-2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeElement(tagName, attributes, ...children) { | |
let element = document.createElement(tagName); | |
Object.assign(element, attributes); | |
for (let child of children) { | |
element.appendChild(child); | |
} | |
return element; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Enum { | |
static create(...members) { | |
class DerivedEnum extends Enum { | |
static contains(member) { | |
return member instanceof DerivedEnum; | |
} | |
} | |
for (let member of members) { | |
DerivedEnum[member] = new DerivedEnum(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import verboseFunction from './verbose.js'; | |
const execute = verboseFunction(["after", "function"], (ms, cb) => setTimeout(cb, ms)); | |
execute.after(1000).function(() => console.log("so verbose!")); | |
// You also get currying for free | |
const waitOneSecondAndExecute = execute.after(1000); |