Skip to content

Instantly share code, notes, and snippets.

View mgronhol's full-sized avatar

Markus Grönholm mgronhol

View GitHub Profile
@mgronhol
mgronhol / trie.py
Created May 13, 2012 16:10
Trie in Python
#!/usr/bin/env python
class Node( object ):
def __init__( self, end_node = False ):
self.end_node = end_node
self.prefix_count = 0
self.children = {}
@mgronhol
mgronhol / gist:2658316
Created May 11, 2012 08:18
Näppiksen käsittely C:llä.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
int main(){
@mgronhol
mgronhol / stdinReader1.java
Created April 11, 2012 10:02
Java simple read line from stdin.
import java.io.*;
public class stdinReader1 {
public static void main( String args[] ){
System.out.println( "Moi kaikki!" );
try {
BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
@mgronhol
mgronhol / KnnDemo.java
Created March 6, 2012 11:23
k-NN luokitin
import java.io.*;
import java.util.Iterator;
import java.util.HashMap;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Collections;
@mgronhol
mgronhol / DijkstraDemo.java
Created March 6, 2012 08:54
Dijkstra shortest path
import java.io.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Collections;
// Linkki kahden noden välillä
class Edge {
private String fromNode, toNode;
private double weight; // weight == etäisyys noiden kahden noden välillä
@mgronhol
mgronhol / Python (x)html templating with context manager
Created December 12, 2011 07:37
Referring to https://gist.github.com/1461441 , a pure python (no extra modules) version (NOT thread safe).
#!/usr/bin/env python
class HtmlDocument( object ):
TAGS = ['html', 'head', 'body', 'div', 'link', 'script',
'title', 'meta', 'p', 'a', 'span', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
'ul', 'li', 'ol', 'pre', 'code', 'footer', 'article', 'canvas', 'img', 'text' ]
def __init__( self ):