Skip to content

Instantly share code, notes, and snippets.

View mgronhol's full-sized avatar

Markus Grönholm mgronhol

View GitHub Profile
@mgronhol
mgronhol / csv_org.py
Created September 6, 2012 11:21 — forked from kauppim/csv_org.py
Pythonized version of kauppim's code
#!/usr/bin/env python
import sys, csv
# Checking for cli parametres
if len( sys.argv ) < 4:
print "Usage: %s input.csv column-label output.csv"%( sys.argv[0] )
sys.exit( 1 )
@mgronhol
mgronhol / notebook.py
Created September 10, 2012 11:25
Simple notebook with REST api using Flask
#!/usr/bin/env pytohn
from flask import Flask, request, jsonify, abort
import time
app = Flask( __name__ )
notes = {}
next_note_id = 0
@mgronhol
mgronhol / Sorttaa.java
Created September 23, 2012 11:43
Sort three entries
public class Sorttaa {
public static int sorttaa( int a, int b, int c, int monesko ){
int tmp;
if ( a > b ){
tmp = b;
b = a;
a = tmp;
@mgronhol
mgronhol / sum-problem.py
Created October 17, 2012 09:46
Constraint solving using backtracking
#!/usr/bin/env python
import libConstraint as LC
solution = LC.Solution()
@solution.must_satisfy
@mgronhol
mgronhol / all-paths-problem.py
Created October 17, 2012 11:17
Constraint solving using backtracking, get all paths
#!/usr/bin/env python
import libConstraint as LC
solution = LC.Solution()
@solution.must_satisfy
def no_loops_constraint( params, candidate ):
return len( candidate ) == len( set( candidate ) )
@mgronhol
mgronhol / plan1-.hpp
Created October 25, 2012 09:00
Tipsy Treeshrew, plan.hh
// Luokat:
/*
create_key( y, x, version, is_current )
y << 32 | x << 12 | is_current << 10 | version
*/
uint64_t create_key( uint32_t y, uint32_t x, uint16_t version, bool is_current );
uint32_t get_row( uint64_t key );
uint32_t get_column( uint64_t key );
@mgronhol
mgronhol / pick-nodes.py
Last active December 23, 2015 12:19
How to pick outer nodes by inner node content
#!/usr/bin/env python
import xml.dom.minidom as dom
import xml
import sys
def read_xml_file( fn ):
return dom.parse( fn ).documentElement
@mgronhol
mgronhol / poor-grep.py
Created September 20, 2013 09:10
Search recursively a directory tree for files that contain a specified string (poor mans grep replacement)
#!/usr/bin/env python
import sys, os
basedir = "."
if len( sys.argv ) > 2:
basedir = sys.argv[1]
string = sys.argv[-1]
@mgronhol
mgronhol / Vektori.java
Last active August 29, 2015 13:57
Simple vector class in java
public class Vektori {
public double x, y, z;
public static Vektori fromPolar( double r, double phi ){
return new Vektori( r * Math.cos( phi ), r * Math.sin( phi ), 0 );
}
@mgronhol
mgronhol / fetchMultiple.js
Created March 15, 2014 20:12
Fetch and parse multiple JSON datasets
function fetchMultiple( datasets, predicate, finished ){
var functions = [];
var results = [];
for( var i = 0 ; i < datasets.length ; ++i ){
functions.push( (function(i){ return function(){
$.getJSON( datasets[i], function( response ){
results.push( predicate( response ) );
functions[i+1]();
});