Skip to content

Instantly share code, notes, and snippets.

@melpomene
melpomene / mergesort.scala
Created October 24, 2012 20:18
Merge-sort in Scala
import scala.util.Random
import scala.Math.min
import scala.runtime.ScalaRunTime._
class MergeSort(list: Array[Int]) {
def sort(): Array[Int] = {
reqSort(list)
}
def merge(v1: Array[Int], v2: Array[Int]): Array[Int] = {
@melpomene
melpomene / MultiDimBin.scala
Last active December 10, 2015 01:09
Calculates the probability of a distribution of multidimensional stocastic variables (binominal distrubution).
package probability
import scala.math
/***
* Calculates the probability of a distribution of multidimensional stocastic variables (binominal distrubution).
*
* param n: number of events
* param probabilityList: Array of the probabilites of the different event
* param occurance: Array of number of occurances we want to know the probability of
*
* called with i.e. multidimensionalBinProb(12, Array(0.5, 0.5), Array(6,6))
@melpomene
melpomene / gist:4948497
Created February 13, 2013 21:30
Clear recent items in OS X without logout.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
LSSharedFileListRef recentDocsList = LSSharedFileListCreate(NULL, kLSSharedFileListRecentDocumentItems, NULL);
LSSharedFileListRemoveAllItems(recentDocsList);
NSLog(@"Cleared files!");
@melpomene
melpomene / convert.py
Last active December 15, 2015 03:58
From tabseperated list to RDF tripples.
import codecs
class Card:
def __init__(self, data):
self.idnr= data[0].strip("\n")
self.category = data[1].strip("\n")
self.star = data[2].strip("\n")
self.name = data[3].strip("\n")
self.questions = list()
self.addQuestion(data[4].strip("\n"), data[5].strip("\n"), data[6].strip("\n"))
@melpomene
melpomene / explainregex.py
Created March 24, 2013 13:25
"Explain regex" terminal utility.
#!/usr/bin/env python
# encoding: utf-8
import sys, urllib2, urllib
from bs4 import BeautifulSoup
if __name__ == '__main__':
if len(sys.argv) < 2:
print "Called with './explainregex therege(x)?'"
else:
page = urllib2.urlopen('http://rick.measham.id.au/paste/explain.pl?regex='+ urllib.quote(sys.argv[1]))
@melpomene
melpomene / toSVM.py
Last active December 16, 2015 01:19
Parse the list of question cards and turn them in to SVM readable format. http://svmlight.joachims.org/
#!/usr/bin/env python
# encoding: utf-8
import codecs
from collections import Counter
class Card:
def __init__(self, data):
self.idnr= data[0].strip("\n")
self.category = data[1].strip("\n")
self.star = data[2].strip("\n")
self.name = data[3].strip("\n")
@melpomene
melpomene / tosvm_ngrams.py
Created April 18, 2013 15:50
Takes tabseperated card files and turns them into light svm files for course in intelligent systems.
#!/usr/bin/env python
# encoding: utf-8
import codecs
from collections import Counter
class Card:
def __init__(self, data):
self.idnr= data[0].strip("\n")
self.category = data[1].strip("\n")
self.star = data[2].strip("\n")
self.name = data[3].strip("\n")
@melpomene
melpomene / tostringkernelarff.py
Last active December 16, 2015 09:49
This script transforms the tab seperated files to ARFF to allow us to use String Kernel from SVM. There are some issues with WEKA and UTF-8 yet to be resolved.
#!/usr/bin/env python
# encoding: utf-8
import codecs
from collections import Counter
class Card:
def __init__(self, data):
self.idnr= data[0].strip("\n")
self.category = data[1].strip("\n")
self.star = data[2].strip("\n")
self.name = data[3].strip("\n")
@melpomene
melpomene / toXRFF.py
Last active December 16, 2015 11:18
Converts the card into XRFF format, allowing WEKA to read UTF-8 data.
#!/usr/bin/env python
# encoding: utf-8
import codecs
from collections import Counter
class Card:
def __init__(self, data):
self.idnr= data[0].strip("\n")
self.category = data[1].strip("\n")
self.star = data[2].strip("\n")
self.name = data[3].strip("\n")
(1000603665) {"1000046259": 1.0, "1000045077": 1.0}
(1001390102) {"1000913520": 1.0, "1000042346": 1.0}
(1004797975) {"1000046435": 1.0, "1003829903": 1.0}
.... some 200k rows more ...
(1004536000)-[:SIMILAR]->(1000840000)
(1004536000)-[:SIMILAR]->(1005442000)