Skip to content

Instantly share code, notes, and snippets.

View objarni's full-sized avatar

Olof Bjarnason objarni

View GitHub Profile
@objarni
objarni / gist:8c9755f2a5671b9de930
Last active August 29, 2015 14:01
Zoo DDD tests
# Rule 1. Carnivors and herbivors cannot live together.
# For example, moving a lion to an enclosement with a zebra is not good, since the zebra will be eaten.
zoo = Zoo()
zoo.add_fenced_enclosure('Fenced area 1')
zoo.add_fenced_enclosure('Fenced area 2')
zoo.add_carnivore('lion', 'Fenced area 1')
zoo.add_herbivore('zebra', 'Fenced area 2')
assertThrows(zoo.move_animal('lion', 'Fenced area 2'))
# Rule 2: Herbivors can live side-by-side.
@objarni
objarni / install_hangout.bash
Created July 7, 2014 18:48
Install Google Hangoug plugin
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb http://dl.google.com/linux/talkplugin/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get install google-talkplugin
@objarni
objarni / minddump_bookmarklet.js
Created August 11, 2014 15:23
Mind dump bookmarklet
javascript:{var txt = prompt('Minddumpa vad?'); alert(txt); }
@objarni
objarni / domain event class in Python
Last active March 13, 2021 11:26
Simplistic Domain Events Python
# coding: utf-8
import unittest
# Unit tests for kata 'domevent'
''' Synchronous domain events in pure Python.
#- triggering an event
#- registering a callback
#- triggering an event with 1 handler
#- triggering an event with 2 handlers
@objarni
objarni / buz.py
Last active August 29, 2015 14:06
A code sketch of a nice simple asynchronous messaging library I'd like to call "Buz" - standing for lots of chatter - buzz, and it's a MessageBus architecturally. And it's a TLA that's nice to say ;)
from buz import Buz, Inbox
buz = Buz()
# Sending a message asynchronously is ridiculously simple
def long_computation(self):
# looong slow algorithm (possibly involving polling I/O ports!)
buz.publish(SomeMessage(..))
# Remember the hell we go through to do things in parallell
@objarni
objarni / cutup.py
Created March 11, 2015 20:23
Skära upp Eins bild i bitar
import Image
block = 7
img = Image.open('cutup.png')
w, h = img.size
print 'Image (w,h)=(%d,%d)' % (w,h)
ws, hs = w/float(block), h/float(block)
print 'Sub image (w,h)=(%d,%d)' % (ws, hs)
@objarni
objarni / jquery_ajax.html
Last active August 29, 2015 14:21
jQuery+Ajax-exempel
<h1>jQuery demo</h1>
<div id="theDiv">
Detta är en liten text.
</div>
<input id="theButton" type="button" value="Klicka mig!" />
<script type="text/javascript">
$(document).ready(function () {
class MachineRunner(object):
"""Simple quantuum programming inspired finite state machine runner"""
def add_machine(self, machine):
self.signal_queue = Queue.Queue() # good for concurrent/threade op!
self.machines.append(machine)
def tick(self):
while self.signal_queue.has_items():
sig = self.signal_queue.pop()
@objarni
objarni / pytddmon_reengineered.py
Last active August 29, 2015 14:23
Sketch of pytddmon re-engineered to a FSM architecture
import Queue
import logging
logging.basicConfig(
format='%(funcName)s: %(message)s',
level=logging.DEBUG
)
class MachineRunner(object):
def __init__(self):
@objarni
objarni / book.py
Last active August 29, 2015 14:26
Boka/avboka dator på enklaste sätt - genom att visa som bokad eller ej bokad!
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import gobject
BOOKING_MINUTES = 60