Skip to content

Instantly share code, notes, and snippets.

// 32 16 16 16 48
// 097d43fb e23d 4633 9608 e930f252d32e
// time_low(8) - time_mid(4) - time_hi_and_version(4) - clock_seq_hi_and_reserved(2)/clock_seq_low(2) - node(12)
// leftmost bits are 0100 leftmost bits are 10
var uuid = function () {
var a = new Uint8Array(16); // 16 8-bit octets that are represented by 2-digit hex numbers
crypto.getRandomValues(a);
a[6] = a[6] & 0x0f | 0x40;
a[8] = a[8] & 0x3f | 0x80;

Keybase proof

I hereby claim:

  • I am dthtvwls on github.
  • I am dthtvwls (https://keybase.io/dthtvwls) on keybase.
  • I have a public key whose fingerprint is 9ECC 667D C9CE BDE7 29BF 7840 B7AA 4D45 967D EA0A

To claim this, I am signing this object:

@dthtvwls
dthtvwls / echo.js
Last active July 22, 2016 15:43
Send back the raw HTTP request (for elastic beanstalk, use node 6.2.2)
require('http')
.createServer((req, res) => {
let body = []
req
.on('data', chunk => body.push(chunk))
.on('end', () => res.end(
req.rawHeaders
.filter((el, i) => i % 2 === 0)
.reduce(
(a, key, i) => a.concat(`${key}: ${req.rawHeaders[i * 2 + 1]}`),
@dthtvwls
dthtvwls / echo.go
Last active May 13, 2017 04:27
TCP echo server
package main
import (
"bufio"
"flag"
"io/ioutil"
"log"
"net"
)
@dthtvwls
dthtvwls / dict.go
Last active May 17, 2017 14:18
Ask if a word is in the dictionary via TCP
package main
import (
"bufio"
"flag"
"fmt"
"io/ioutil"
"log"
"net"
"os"
@dthtvwls
dthtvwls / trie.go
Last active May 24, 2017 11:41
Search stems in the dictionary using a trie
package main
import (
"bufio"
"flag"
"io/ioutil"
"log"
"net"
"os"
"strconv"
@dthtvwls
dthtvwls / sessionize.js
Created August 30, 2016 23:16
sessionize
function sessionize(nums, threshold) {
threshold = threshold || 3;
var i = 0, j = 0, sessions = [];
while (j < nums.length - 1) {
if (nums[j + 1] - nums[j] > threshold) {
sessions.push([nums[i], nums[j]]);
i = ++j;
} else {
@dthtvwls
dthtvwls / README.md
Last active August 3, 2017 19:17
rpc_engine
package main

import (
	"encoding/json"
	"fmt"
	"rpc_engine"
)

func main() {
@dthtvwls
dthtvwls / app.js
Last active February 24, 2018 04:47
crossfader shim backend with socket.io
const express = require('express')
const app = express()
const http = require('http')
const server = http.createServer(app)
const socket = require('socket.io')
const io = socket(server)
let config = {
servers: ['example.com', 'example.net'],
subtrahend: 0
@dthtvwls
dthtvwls / server.go
Created May 15, 2018 19:49
Display departing trains from FiDi
package main
import (
"encoding/json"
"html/template"
"io/ioutil"
"net/http"
"sort"
"time"
)