Skip to content

Instantly share code, notes, and snippets.

@dthtvwls
dthtvwls / app.py
Created March 16, 2021 23:48
CORS proxy
from flask import Flask, request
from flask_cors import CORS
import requests
app = Flask(__name__)
CORS(app)
@app.route('/<path:path>')
def root(path):
@dthtvwls
dthtvwls / template-apply.go
Last active June 8, 2018 17:11
put a json structure on stdin, call `template-apply path/to/template`, receive executed template on stdout
package main
import (
"encoding/json"
"io/ioutil"
"os"
"text/template"
)
func check(err error) {
version: "3"
services:
kafka:
image: confluentinc/cp-kafka
depends_on:
- zookeeper
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
@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"
)
@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 / README.md
Last active August 3, 2017 19:17
rpc_engine
package main

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

func main() {
@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 / 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 / echo.go
Last active May 13, 2017 04:27
TCP echo server
package main
import (
"bufio"
"flag"
"io/ioutil"
"log"
"net"
)
@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 {