Skip to content

Instantly share code, notes, and snippets.

@enil
enil / README.md
Last active July 2, 2017 12:17
Trying to publish an NPM project through gist

Hello world

This is the documentation.

@enil
enil / compare.js
Created May 10, 2017 18:54
JS Iterator comparison
const Iterators = {
compare(left, right) {
const leftIterator = left[Symbol.iterator](), rightIterator = right[Symbol.iterator]();
while (true) {
const {done: leftDone, value: leftValue} = leftIterator.next();
const {done: rightDone, value: rightValue} = rightIterator.next();
if (leftValue !== rightValue || leftDone !== rightDone) {
@enil
enil / myordset.erl
Created April 20, 2017 18:32
Implementation of basic set functionality with an ordered list (like ordset).
-module(myordset).
-export([new/0, add_element/2, del_element/2, union/2, intersect/2, is_subset/2]).
new() -> [].
add_element(E, []) -> [E];
add_element(E, [E|_] = L) -> L;
add_element(E, [H|T]) when E < H -> [E,H|T];
add_element(E, [H|T]) when E > H -> [H|add_element(E, T)].
@enil
enil / runimage.sh
Created April 17, 2017 14:07
Build and run a temporary Docker image contained in a shell script
#!/bin/sh
TAG=$(uuidgen | tr -d '-' | tr '[A-Z]' '[a-z]')
docker build -t $TAG - << EOF
FROM debian
ENTRYPOINT ["echo", "Hello world from ${TAG}!"]
EOF
docker run --rm $TAG
@enil
enil / binToString.js
Created March 12, 2017 11:58
Recursive conversion to a binary string
function binToString(n) {
if (n <= 1) {
return String(n);
} else {
return binToString(n >> 1) + binToString(n & 1);
}
}
@enil
enil / shacheck.sh
Created December 22, 2016 11:47
Verify SHA-256 checksums of only the files that exist
# sha256sum doesn't like if the checksum file contains entries for missing files
awk '{ if (system("test -f " $2) == 0) { print $0 } }' $1 | sha256sum -c
@enil
enil / urlparse.js
Created November 21, 2016 13:23
Simple URL parsing
url.match(/^([a-z]+):\/\/([^\/:]+)(?::([0-9]+))?(\/[^?#]+)?(?:\?([^#]*))?(?:#(.+))?$/);
@enil
enil / sample.go
Created November 4, 2016 12:49
Pick N random values from a slice
func min(x, y int) int {
if x > y {
return y
} else {
return x
}
}
func Sample(source []int, count int) []int {
count = min(count, len(source))
@enil
enil / cap.go
Created November 3, 2016 08:47
Populate a Go slice using append and cap
numbers := make([]int, 0, 10)
for i := 0; i < cap(numbers); i++ {
numbers = append(numbers, i)
}
fmt.Println(numbers)
@enil
enil / main.go
Created October 27, 2016 12:21
Mock random number source
package main
import (
"fmt"
"math/rand"
)
type MockSource struct {
values []int64
position int