Skip to content

Instantly share code, notes, and snippets.

View tristanwietsma's full-sized avatar

Tristan Wietsma tristanwietsma

  • Chicago, Illinois
View GitHub Profile
@tristanwietsma
tristanwietsma / redislogger.go
Created April 30, 2013 03:20
Redis channel logger Log all incoming messages published to a Redis channel.
package main
import (
"fmt"
"github.com/vmihailenco/redis"
)
func main() {
client := redis.NewTCPClient("localhost:6379", "", -1)
@tristanwietsma
tristanwietsma / index.html
Created April 30, 2013 04:44
Redis to websocket relay Relays a Redis channel to a websocket, or multiple channels to multiple sockets.
<html>
<head>
<title>Redis Listener</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var conn;
var msg = $("#msg");
var log = $("#log");
function appendLog(msg) {
@tristanwietsma
tristanwietsma / deco.py
Created May 3, 2013 01:18
Function decorator basics Python decorator example for management of functions.
def Decorator():
registry = {}
def registrar(func):
registry[func.__name__] = func
return func
registrar.all = registry
return registrar
my_func_decorator = Decorator()
@tristanwietsma
tristanwietsma / connections.txt
Last active September 21, 2022 19:42
Three digit LED control for Arduino Arduino sketch to control a 3 digit LED display (TOT-5361BE-D).
Connect the Arduino UNO pins "(x)" to the LED leads "-" as follows:
_________
| |
(1)-| ***** |-(11)
| * * * |
(2)-| ***** |-(10)
| |
(3)-| ***** |-(9)
| * * * |
@tristanwietsma
tristanwietsma / vegetronix.ino
Created May 8, 2013 16:33
Vegetronix soil moisture sensor & LED display sketch Building on the triple digit LED display, this code connects a Vegetronix soil moisture probe to the A0 pin and outputs the sensor value to display.
int segA = 10;
int segB = 6;
int segC = 4;
int segD = 2;
int segE = 1;
int segF = 9;
int segG = 5;
int pnt = 3;
int dig1 = 7;
@tristanwietsma
tristanwietsma / fx_arb.py
Created May 22, 2013 05:03
Forex arbitrage hiring puzzle. While not realistic, the algorithm discovers currency arbitrage opportunities given a JSON with exchange rates. The method used is the Bellman-Ford shortest path algorithm.
from __future__ import division
import urllib, json, string, datetime
from itertools import permutations
from math import log
def _bf(V, E, src):
# init
dist = dict(zip(V, [float('Inf') for v in V]))
pred = dict(zip(V, [None for v in V]))
@tristanwietsma
tristanwietsma / fetch-gists.py
Created May 25, 2013 20:36
Fetch and print gists from GitHub
import urllib, json, datetime
def ParseGist(g):
id = str(g[u'id'])
dt = datetime.datetime.strptime(g[u'created_at'], '%Y-%m-%dT%H:%M:%SZ').strftime('%Y-%m-%d')
files = g[u'files']
desc = g[u'description']
link = g[u'html_url']
comments = g[u'comments']
languages = [files[f][u'language'] for f in files.keys()]
@tristanwietsma
tristanwietsma / naivebayes.go
Created May 26, 2013 01:22
Naive Bayes (with a little concurrency)
package main
import (
"fmt"
"math"
"sync"
)
func Average(x []float64) float64 {
sum := 0.0
@tristanwietsma
tristanwietsma / rtop.go
Created May 26, 2013 05:43
Redis top log example with curses
package main
import (
"flag"
"github.com/tncardoso/gocurses"
"github.com/vmihailenco/redis"
"os"
"strings"
"time"
)
@tristanwietsma
tristanwietsma / anonymous.go
Created May 29, 2013 02:00
Anonymous functions in Go
package main
import "fmt"
func Coef(k float64) func(float64) float64 {
return func(x float64) float64 {
return k * x
}
}