Skip to content

Instantly share code, notes, and snippets.

View archie's full-sized avatar
😃

Marcus Ljungblad archie

😃
View GitHub Profile
@archie
archie / mf.py
Created January 17, 2012 14:58
Simple Matrix Factorization
#!/usr/bin/python
#
# Created by Albert Au Yeung (2010)
# Updated by Marcus Ljungblad (2012)
#
# An implementation of matrix factorization
#
try:
import numpy
@archie
archie / Hashing.scala
Last active September 4, 2019 09:24
Implementation of various hash functions for strings in Scala. Details here: http://hs.ljungblad.nu/post/64624649234/a-dive-into-the-mystery-of-hashes
object Hashing {
val BUCKETSIZE = 1000
val words = io.Source.fromFile("/usr/share/dict/words").getLines
.map(x => x.toLowerCase).toList
def initBuckets(size: Int): Array[List[String]] = {
var arr = new Array[List[String]](size)
arr.map(_ => List[String]())
}
@archie
archie / ParentChild.scala
Created December 13, 2013 22:42
Examples of testing Akka actor parent-child relationships, mostly based on findings from https://www.assembla.com/spaces/akka/tickets/3043#/activity/ticket:
package pc
import akka.actor.Actor
import akka.actor.Props
import akka.actor.ActorRef
import akka.actor.ActorRefFactory
class Parent extends Actor {
val child = context.actorOf(Props[Child], "child")
var ponged = false
@archie
archie / ddd_cqrs_es.md
Last active May 20, 2019 07:36
Draft blog post about ddd, cqrs, and es.

DDD, CQRS and Event Sourcing

In preparation for a new gig I'm reading up on the terms Domain-Driven Design, Command-Query Responsibility Segregation, and Event Sourcing. Here are a list of useful texts and talks that I've discovered so far. If anything is missing please leave a comment.

DDD

@archie
archie / cmov_summaries.txt
Created June 5, 2011 16:27
Mobile Computing Paper summaries
- Some computer science issues in Ubiquitous computing (M. Weiser)
Takes inspiration from everyday objects and how we interact with them such that the interaction is unconscious and non-intrusive. The objects of interaction are proactive in a way that makes humans "think less". Developed three prototypes: Tab (post-it like), Pad (think iPad), and Smartboard (interactive whiteboard). Identified X areas for future work: 1) Hardware - such as pens, battery life, wireless scalability. 2) Network protocols - media access, real-time capabilities, mobile IP. 3) Interaction substrates - surface on which users can pass commands, other ways of passing commands (speaking), separating view from logic, moving views around. 4) Applications - location-awareness, context-aware, collaboration, not only technical challenges. 5) Privacy - what information is the user willing to share, number of devices increasing, voluntary vs involuntary sharing. 6) Computational Methods - caching, disconnected operations.
- Pervasive Compu
@archie
archie / EchoSpec.scala
Last active December 30, 2015 23:39
This does not compile since ImplicitSender depends on TestKit and not TestKitBase. Error message: "illegal inheritance; self-type demo.EchoSpec does not conform to akka.testkit.ImplicitSender's selftype akka.testkit.ImplicitSender with akka.testkit.TestKit [---] line 18"
package demo
import org.scalatest._
import akka.testkit.TestKit
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.testkit.TestKitBase
import akka.testkit.ImplicitSender
import akka.actor.Props
@archie
archie / Log.scala
Created November 25, 2013 14:34
Using "Pimp my library" pattern to add customised functionality to a Scala Vector.
package raft
import scala.language.implicitConversions
import akka.actor.ActorRef
abstract class Entry[T](val command: T, val term: Int, val sender: (ActorRef, Int))
case class StringEntry(
override val command: String,
override val term: Int,
@archie
archie / Zoo.scala
Last active December 28, 2015 20:29
Playing with futures in Scala
import scala.util.{ Failure, Success }
import scala.concurrent.{ Future }
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import math.random
object Zoo extends App {
val animals = List("monkey", "donkey", "giraffe").map { animal =>
for {
@archie
archie / GraphGenerator.scala
Created November 9, 2013 02:32
Demo using Scala generators constructing random instances of InductiveGraph with nodes having an edge to another node with 75% probability.
package graph
trait Generator[+T] {
self =>
def generate: T
def map[U](f: T => U): Generator[U] = new Generator[U] {
def generate: U = f(self.generate)
}
def flatMap[U](f: T => Generator[U]): Generator[U] = new Generator[U] {
def generate: U = f(self.generate).generate
@archie
archie / FSMDemo.scala
Last active December 26, 2015 19:19
Demo FSM in Scala and Akka with spec
package demo
import akka.actor.Actor
import akka.actor.FSM
import akka.actor.ActorSystem
import akka.actor.Props
import akka.actor.ActorRef
sealed trait State
case object Awake extends State