Skip to content

Instantly share code, notes, and snippets.

View stianeikeland's full-sized avatar

Stian Eikeland stianeikeland

View GitHub Profile
(ns ttt-gametree.core)
(def win-patterns [[0 1 2] ; 1st row
[3 4 5] ; 2nd row
[6 7 8] ; 3rd row
[0 4 8] ; diagonal
[2 4 6] ; diagonal
[0 3 6] ; 1st col
[1 4 7] ; 2nd col
[2 5 8]]) ; 3rd col
@stianeikeland
stianeikeland / core.clj
Created December 2, 2014 14:04
tic-tac-zipper
(ns ticzip.core
(:require [clojure.zip :as z]))
(def game {:board (vec (repeat 9 nil))
:player :x})
(def next-player {:x :o, :o :x})
(defn- free-tiles [{:keys [board]}]
(->> board
@stianeikeland
stianeikeland / keybase.md
Created December 4, 2014 22:05
keybase.md

Keybase proof

I hereby claim:

  • I am stianeikeland on github.
  • I am stianeikeland (https://keybase.io/stianeikeland) on keybase.
  • I have a public key whose fingerprint is 5D10 C9C5 6178 0BA2 0D29 6AE4 795E B458 3552 AF2F

To claim this, I am signing this object:

1
| ||1 1 +
| | | ||& + | 2|
| | | | _|_ 5 | ]||1
| | _|_ | 2 _|_ 1|]
_|_ | | | 5 5 < _|_
7 & | | | | 1 & ] 4
| " | | ____| |**____| [ 1 <
| |___ | |____ | | | |____| -
_| | | | | | | |11]-2
@stianeikeland
stianeikeland / core.clj
Last active August 29, 2015 14:19
🍌🎹 Banana piano
(ns musikk.core
(:require [serial-port :as serial]
[overtone.live :refer :all]
[overtone.inst.sampled-piano :refer :all]))
(def port (serial/open "/dev/tty.usbserial-A800F185" 57600))
(defn chr->int [c]
(-> (char c)
(str)
@stianeikeland
stianeikeland / coffeetimer-msp430.c
Created March 20, 2011 15:06
MSP430 Coffeetimer
/*
* Coffetimer (safetytimer)
*
* Activated when button (pin 4) is grounded.
* Connected to a RF - remote control on pin 5 and 6
* via a couple of transistors, controling the
* coffemakers power outlet.
*
* */
@stianeikeland
stianeikeland / broker.coffee
Created September 10, 2012 19:22
0MQ.. push/pull => pub/sub
# Router / Central hub for home automation.
# Receives events and distributes via pub/sub
zmq = require 'zmq'
inputPort = 'tcp://*:8888'
outputPort = 'tcp://*:9999'
# Pull socket for incoming (push/pull), pub for outgoing (pub/sub)
input = zmq.socket 'pull'
@stianeikeland
stianeikeland / subexample.coffee
Created September 24, 2012 16:13
Subscribe to sensor data.
sub = (require 'zmq').socket 'sub'
sub.connect 'tcp://raspberrypi:9999'
sub.subscribe 'sensor'
sub.on 'message', (topic, data) -> console.log "#{topic} => #{data}"
@stianeikeland
stianeikeland / msgbuspower.coffee
Created October 20, 2012 14:31
Power control on the message bus
power = new Power new MessageBus
# Power coffeemaker off 60 minutes after it was powered on:
power.on 'kitchen-coffeemaker', (event) ->
turnOff = () ->
power.send {
command: "off",
location: "kitchen-coffeemaker" }
setTimeout turnOff, 60*60*1000 if event.command is "on"
#!/usr/bin/env bash
for i in {0..255} ; do
printf "\x1b[38;5;${i}mcolour${i}\n"
done