Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / rapport.tex
Created October 15, 2012 11:05
Latex rapport empty
%
%
% Created by christopher on 2012-05-11.
% Copyright (c) 2012 __MyCompanyName__. All rights reserved.
%
\documentclass[]{article}
% Use utf-8 encoding for foreign characters
\usepackage[utf8]{inputenc}
@melpomene
melpomene / Main.py
Created October 14, 2012 21:50
Parse rainbows from stdin
#!/usr/bin/env python
# encoding: utf-8
"""
Kallas med:
cat bRPM_data/Yes/brpm_yes_11_1.in | python Main.py
"""
import sys
@melpomene
melpomene / collatz.py
Created October 8, 2012 20:01
Collatz sequence generator
#!/usr/bin/env python
# encoding: utf-8
from random import random
from heapq import heappush, nsmallest, nlargest
import time, sys
from sets import Set
def rotl32(a, b):
return (((a << (b & 0x1f)) & 0xffffffff) |
((a >> (32 - (b & 0x1f))) & 0xffffffff))