Skip to content

Instantly share code, notes, and snippets.

View archie's full-sized avatar
😃

Marcus Ljungblad archie

😃
View GitHub Profile
@archie
archie / Main.scala
Last active December 25, 2015 17:39
First implementation of a Trie in Scala. Only supports Strings as of now.
import scala.language.postfixOps
import sys.process._
import trie._
object Main {
val ENTER = 10
val BACKSPACE = 127
val BUFFER_SUGGESTION_THRESHOLD = 2
@archie
archie / Example.scala
Last active December 25, 2015 13:18
Draft of inductive graph implementation in Scala based on http://web.engr.oregonstate.edu/~erwig/papers/InductiveGraphs_JFP01.pdf
import graph._
object Main {
def main(args: Array[String]): Unit = {
println(" Exploring the graph ")
val sample =
Context(Adj(List(("left", Node(2)), ("up", Node(3)))),
Node(1), "a", Adj(List(("right", Node(2))))) &:
Context(Adj(List()), Node(2), "b", Adj(List(("down", Node(3))))) &:
@archie
archie / run_test.py
Created February 26, 2013 12:05
Illustrating how to load (through discovery) Python unit tests and executing them.
def test_project(self, projectname):
logging.info('Running tests on: %s' % projectname)
loader = unittest.TestLoader()
tests = loader.discover(projectname)
runner = unittest.TextTestRunner()
runner.run(tests)
@archie
archie / gist:4482874
Created January 8, 2013 10:53
I found this somewhere online but I cannot remember where, so reposting here. Using the command line tool 'imagesnap' it grabs a photo every time you make a commit. It is activated through the post-commit hook. ➜ myrepo git:(master) cat .git/hooks/post-commit
#!/usr/bin/env ruby
file="~/.gitshots/#{Time.now.to_i}.jpg"
unless File.directory?(File.expand_path("../../rebase-merge", __FILE__))
puts "Taking capture into #{file}!"
system "imagesnap -q -w 3 #{file} &"
end
exit 0
@archie
archie / fabfile.py
Created May 11, 2012 08:53
Fabric example
@hosts("local")
def prepare_config(data, maxcap='5'):
local("cp deploy/template.conf deploy/application.conf")
local("sed -i -f \"s/FOLDERPLACEHOLDER/" + data + "/g;s/MAXCAPACITYPLACEHOLDER/" +
maxcap + "/g;\" deploy/application.conf")
def config():
put("deploy/application.conf", "~/recsys/")
run("sed -i \"s/IPPLACEHOLDER/$(hostname -f)/g;\" ~/recsys/application.conf")
@archie
archie / playcount.py
Created April 19, 2012 16:30
Playcount.py
import sys
import random
import math
if len(sys.argv) != 3:
print "Usage: ./playcount.py <file_to_parse> <output_counts_to_file>"
exit(1)
countmap = {}
@archie
archie / gist:2422239
Created April 19, 2012 16:47
Clustering
...
# Read the vectors
data = read_from_file(sys.argv[1])
items = numpy.array(data)
# Normalise vectors
normalised_items = whiten(items)
# Cluster time!
@archie
archie / gist:1922816
Created February 27, 2012 09:38
Signature Matrix Creation
def createSignatureMatrix(characterMatrix: Array[Array[Int]], hashFunctions: List[HashFunction]): Array[Array[Int]] = {
val signatureMatrix: Array[Array[Int]] = createEmptySignatureMatrix(hashFunctions.length, characterMatrix(0).length)
characterMatrix.zipWithIndex.foreach { case (row, i) =>
row.zipWithIndex.foreach { case (character, j) =>
/* only apply hash functions if character is not 0 */
if (character == 1) {
hashFunctions.zipWithIndex.foreach { case (hasher, k) =>
val hashedRowValue: Int = hasher.apply(i)
if (isReplaceable(signatureMatrix(k)(j), hashedRowValue)) {
signatureMatrix(k)(j) = hashedRowValue
@archie
archie / dummy.erl
Created November 29, 2011 20:31
Dummy application that use gaoler
-module(dummy).
-export([important_task/0]).
important_task() ->
gaoler:acquire(beer),
drink_beer(),
gaoler:release(beer).
drink_beer() ->
io:format("I'm a happy application!", []).
@archie
archie / xor.c
Created September 27, 2011 12:05
Xor arbitrary number of files hack
#include <stdlib.h>
#include <stdio.h>
int xor_files(FILE *files[], int number_of_files, char *outputfilename) {
int file_index;
int x = 0;
FILE* output;
output = fopen(outputfilename, "wb");