Skip to content

Instantly share code, notes, and snippets.

View zouppen's full-sized avatar

Joel Lehtonen OH64K zouppen

View GitHub Profile
@zouppen
zouppen / PowerParser.hs
Created October 12, 2011 21:14
I accidentally collected information of electricity switch state... :-)
-- |Parses log file for network card ups and downs. In Liittovaltio we
-- have a switch which shuts down all electric equipments in our
-- living room, including our network switch. I accidentally
-- discovered that when this button is pressed, the intranet interface
-- of Moskova is put offline, too. Moskova writes it to kernel log as
-- any good server should. The reverse happens when the power is
-- resumed. Some example log lines:
--
-- > 2011-10-04T23:46:04+0300 eth0: link up, 1000 Mb/s, full duplex, ...
-- > 2011-10-05T02:20:42+0300 eth0: link down
@zouppen
zouppen / standi.rst
Created October 13, 2011 23:02
Instanssiständi Alternative Partyillä

Visio ständistä

Lähtökohtana Joelin visio, joka laitettiin Alteille. 2x2m pöydällä on neljä näyttöä vierekkäin ja vastakkain, niin että kaksi tyyppiä tekee jollain tavalla luovaksi katsottua tekemistä niin, että se näkyy koko ajan myös käytävälle. Mahdollista luovaa on esim. grafiikan piirtäminen, kummallisen algoritmin vääntäminen jne. Ständille otetaan mukaan myös valopöntöt, jotka voisi avata Alttien lähiverkkoon samaan tapaan kuin Instansseilla.

@zouppen
zouppen / TransactionalMap.hs
Created November 18, 2011 13:17
A quick and sparse wrapping of Map to Software Transactional Memory. You can extend this to cover all features of Map easily. Useful for key-value storage where you otherwise need to signal the changes somehow. Now this is done automatically in STM. This
module TransactionalMap where
import Control.Concurrent.STM
import Control.Monad (unless)
import Data.Map (Map)
import qualified Data.Map as M
type TransactionalMap k a = TVar (Map k a)
newEmptyTransactionalMap :: STM (TransactionalMap k a)
@zouppen
zouppen / SlowResponse.hs
Created December 1, 2011 23:03
A proof of concept for a low overhead datamatrix. Probable use is visualizing Instanssi demos.
-- |Pseudorandom generation for ensuring entropy and distribution of
-- the bit map.
module SlowResponse where
import System.Random -- Requires 1.0.1.0
import Data.Word
import Data.Bits
-- import Data.Tuple (swap) -- Requires base 4.3
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as B
@zouppen
zouppen / runstop.sh
Created April 19, 2012 13:18
Runs a process for a given time
#!/bin/bash -eu
#
# Runs a process for given time (timeout format is same as in
# sleep(1)) and terminates it with SIGTERM after timeout occurs.
#
# Author: Joel Lehtonen <joel.lehtonen@iki.fi>
# Keeps some parameters and alters positional parameters
TIMEOUT=$1
PROG=$2
@zouppen
zouppen / Animation.hs
Created June 27, 2012 20:37
LED cube features and animation definitions
-- |Animation file and LED cube definition. This contains the internal
-- representation of the animation. The file format is defined
-- elsewhere (TODO). The actual implementation is free to stop if it
-- can not scale the data when animation file dimensions differ from
-- the LED cube. But you may also implement a scaler, if you will.
module Animation where
import Data.ByteString (ByteString)
-- |Animation file, contains animation dimensions, led counts for each
@zouppen
zouppen / gist:3733620
Created September 16, 2012 18:25
Elovalo symbol table, commit 5695c209a69891a13678e8e1abbaf860cec3731b
SYMBOL TABLE:
00800100 l d .data 00000000 .data
00800126 l d .bss 00000000 .bss
0080012c l O .bss 00000004 last_time.1765.1859.1606
00800129 l O .bss 00000002 ticks_volatile.1761.1613
0080012b l O .bss 00000001 cron_running.1629.1753.1604
0080010a l O .data 00000004 next
00800738 g O .bss 00000001 brown_x
00800739 g O .bss 00000006 worm_pos
00800112 g O .data 00000001 playlists_len
@zouppen
zouppen / commands.sh
Created September 26, 2012 23:26
Elovalo simulator test drive
# Generates 1 second (cont 25 times) long animation of effect number 5
# On background
simulavr -G -d atmega328 &
# On foreground
avr-gdb -batch -x simulator_commands.txt >simulator_output.txt
# Stop simulavr
kill %1
@zouppen
zouppen / KeyValueStorage-dojo.hs
Last active December 17, 2015 07:39 — forked from anonymous/KeyValueStorage-dojo.hs
Haskell/STM Dojo at Pub Hemingways, Jyväskylä, Finland on 2013-05-13.
{-# LANGUAGE OverloadedStrings #-}
module KeyValueStorage where
import Data.Functor
import Control.Concurrent.STM
import Data.Text (Text)
import Data.Text.Encoding (encodeUtf8)
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy.Char8 as B
import qualified Data.ByteString.Char8 as BS
@zouppen
zouppen / mail_sql_report
Last active December 23, 2015 18:19
Generate HTML reports from arbitary PostgreSQL queries
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Generates email reports from any SQL query. Usage:
#
# ./mail_sql_report config_file
#
# This script is not SQL injection safe script and should be run only
# with read-only credentials if you want to play sure. This just runs
# the SQL as-is.