Skip to content

Instantly share code, notes, and snippets.

View nl253's full-sized avatar
🎯
Focusing

nl253

🎯
Focusing
View GitHub Profile
@nl253
nl253 / trie.js
Last active February 16, 2020 16:18
Trie
class Trie {
constructor() {
this.n = 0;
this.children = {};
}
add(s) {
if (s === '') {
this.n++;
return;
@nl253
nl253 / timeToComputeConcurrently.js
Created February 1, 2020 19:07
Time to compute concurrently
const timeToComputeConcurrently = (
costOfThreadSpawn = 0.001,
costOfComputation = 0.5,
nJobs = 8,
cpuCount = 4
) => {
const timeToComputeNthJob = nth =>
(nth + 1) * costOfThreadSpawn +
costOfComputation +
(nth >= cpuCount ? timeToComputeNthJob(nth - cpuCount) : 0);
@nl253
nl253 / swagger.json
Created December 22, 2019 15:50
Swagger 2.0
{
"swagger": "2.0",
"info": {
"title": "NLP",
"description": "Natural Language Processing API.",
"contact": {
"name": "API Support",
"url": "http://www.swagger.io/support",
"email": "support@swagger.io"
},
@nl253
nl253 / htmlElementRXJSLink.js
Last active August 27, 2019 20:33
RXJS example of linking to events emitted by an input element #javascript #rxjs #angular #reactive-extensions #html #html5 #event-driven
@nl253
nl253 / JetBrainsMarkdown.css
Created July 26, 2019 19:59
CSS styles for Markdown preview in JetBrains IDEs
p {
font-family: Alegreya, serif;
box-sizing: border-box;
}
button, input[type=button] {
padding: 5px 8px;
}
@nl253
nl253 / keyboard_distance.py
Last active March 4, 2019 23:13
Keyboard Distance Metric
# Standard Library
from functools import lru_cache
from math import sqrt
from typing import List, Optional, Tuple
KB: Tuple[Tuple, Tuple, Tuple, Tuple, Tuple] = (
(('`', '¬'), ('1', '!'), ("2", '"'), ('3', '£'), ('4', '$'), ('5', '%'), ('6', '^'), ('7', '&'), ('8', '*'), ('9', '('), ('0', ')'), ('-', '_'), ('=', '+')),
(('\t',), ("",), ("q", 'Q'), ("w", 'W'), ("e", 'E'), ("r", 'R'), ("t", 'T'), ("y", 'Y'), ("u", 'U'), ("i", 'I'), ("o", 'O'), ("p", 'P'), ('[', '{'), (']', '}'), ('\n',)),
(("",), ("",), ('a', 'A'), ('s', 'S'), ("d", 'D'), ("f", 'F'), ("g", 'G'), ("h", 'H'), ("j", 'J'), ("k", 'K'), ("l", 'L'), (';', ':'), ("'", '@'), ('#', '~')),
(('',), ('\\', '|'), ("z", 'Z'), ("x", 'X'), ("c", 'C'), ("v", 'V'), ("b", 'B'), ("n", 'N'), ("m", 'M'), (',', '<'), ('.', '>'), ('/', '?')),
@nl253
nl253 / latency.txt
Created August 30, 2018 20:19 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@nl253
nl253 / manage.sh
Created August 26, 2018 09:45
Self documenting Bash build / utility script
#!/usr/bin/env bash
# ------------------------------------------------------------
# YOUR WORKSPACE
# ------------------------------------------------------------
# GLOBAL VARIABLES (CANNOT BE DELETED)
# ------------------------------------------------------------
# You are free to add / modify the values of these globals.
# However, you cannot delete them as core functions depend on them.
@nl253
nl253 / main.rs
Created July 31, 2018 16:57
Big O Estimation in Rust
#![feature(duration_as_u128, extern_prelude)]
#![warn(bad_style, rust_2018_idioms, nonstandard_style)]
#![deny(future_incompatible)]
use std::collections::VecDeque;
fn measure_time(n: u128, f: fn(u128) -> ()) -> u128 {
let start = std::time::SystemTime::now();
f(n);
let end = std::time::SystemTime::now();
@nl253
nl253 / SelfOrgList.java
Last active May 27, 2018 13:37
Self-Organising Doubly-Linked List with 2 heuristics - move to front and transpose
import java.util.Optional;
import java.util.function.Predicate;
import java.util.logging.Logger;
enum Heuristic {TRANSPOSE, MOVE_TO_FRONT}
class Metadata<E> {
SelfOrgList<E> hd, lst;
Heuristic heuristic = Heuristic.MOVE_TO_FRONT;
int len;