Skip to content

Instantly share code, notes, and snippets.

package model;
import java.util.HashSet;
import java.util.Set;
/* the documentation did not specify how an album should handle duplicates so I
* adopted the iPhoto idea of completely ignoring duplicates. Hence the use of
* the Set Collection, rather than i.e. list.
*
* This method follows the main idea that you shouldn't write methods that you
@KarlHerler
KarlHerler / DESHash.scala
Created February 14, 2012 20:01
A simple hashing function using DES
package com.karlherler.crypto
import com.karlherler.crypto.javax.des.DES
class DESHash(msg: Array[Byte]) {
private val h0 = Array(0x01.toByte, 0x23.toByte, 0x45.toByte,
0x67.toByte, 0x89.toByte, 0xab.toByte,
@KarlHerler
KarlHerler / GenCaesar.scala
Created January 19, 2012 15:03
Files used to attack assignment 3
import java.lang.RuntimeException
import java.io._
import scala.io.Source
class GenCaesar(cipher: Array[Byte]) {
def brute(b: Array[Byte]): IndexedSeq[(Int, Array[Byte])] =
(0 to 255).map {
i => (i, (b.map(decrypt(_, i))))
}
@KarlHerler
KarlHerler / tridoutput.txt
Created January 19, 2012 13:00
just the output of running trid.
TrID/32 - File Identifier v2.10 - (C) 2003-11 By M.Pontello
Definitions found: 4540
Analyzing...
File: decrypted\0.dat
50.0% (.JPG) JFIF JPEG Bitmap (4003/3)
File: decrypted\1.dat
Unknown!
@KarlHerler
KarlHerler / CachedSpot.scala
Created January 14, 2012 16:19
Relevant parts of a cache expiry timer
import java.util.Calendar
import java.util.GregorianCalendar
val d = new GregorianCalendar(TimeZone.getTimeZone("Europe/Helsinki"))
d.set(Calendar.HOUR, 10)
val expiry = ((d.getTimeInMillis-System.currentTimeMillis)/1000L).toInt
@KarlHerler
KarlHerler / build.sbt
Created January 8, 2012 11:51
The sbt output I get from using scalatras buildfile in a empty directory
// NOTE: I removed the seq(webSettings :_*) since it generates an error in this (also this comment doesn't exist in the file)
organization := "com.example"
name := "scalatra-sbt-prototype"
version := "0.1.0-SNAPSHOT"
scalaVersion := "2.9.1"
@KarlHerler
KarlHerler / gist:1575247
Created January 7, 2012 16:42
I JUST WANTED A LIST!
Karls-MacBook-Air:helloworld kalle$ g8 --list
Getting net.java.dev.jna jna 3.2.3 ...
:: retrieving :: org.scala-tools.sbt#boot-app
confs: [default]
1 artifacts copied, 0 already retrieved (838kB/23ms)
Getting Scala 2.9.1 (for giter8)...
downloading http://scala-tools.org/repo-releases/org/scala-lang/scala-compiler/2.9.1/scala-compiler-2.9.1.jar ...
[SUCCESSFUL ] org.scala-lang#scala-compiler;2.9.1!scala-compiler.jar (40184ms)
downloading http://scala-tools.org/repo-releases/org/scala-lang/scala-library/2.9.1/scala-library-2.9.1.jar ...
[SUCCESSFUL ] org.scala-lang#scala-library;2.9.1!scala-library.jar (30302ms)
@KarlHerler
KarlHerler / a.py
Created January 4, 2012 11:10
Importing without specified PYTHONPATH or virtualenv (/src/lib/ and src/test/)
# Fibonacci numbers module
print "I am imported!"
def printMe():
print "From a.py"
# IGNORE, just some test methods
def fib(n): # write Fibonacci series up to n
a, b = 0, 1
@KarlHerler
KarlHerler / mymem.c
Created December 2, 2011 11:26
A malloc written for the OS course in ÅA
#include <stdio.h>
int bitmap[20480];
int myalloc(int blocksize) {
int i=0; //counter
int x=0; //done
int z=0; //potential spot
while (x==0) {
if(i<20480) { //we're still in a valid range
@KarlHerler
KarlHerler / gist:1321706
Created October 28, 2011 05:45
productsample json
[
{
id: 3065,
name: { fi-fi: "Käsisaippua (sininen)", et-ee: "Käteseep (sinine)", sv-se: "Handtvål (blå)", sv-fi: "Handtvål (blå)" },
price:{ fi-fi: "4,40 €", et-ee:"4,40 €", sv-se: "43,00 kr", sv-fi: "4,40 €"},
tags: ["hands", "wash", "designs"],
color: "blue",
height: 10,
space: 2,
},