Skip to content

Instantly share code, notes, and snippets.

View mgronhol's full-sized avatar

Markus Grönholm mgronhol

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / php-append-log.php
Created September 6, 2012 08:13
Append log for PHP [4|5]
<?php
function append_log_write( $filename, $parametres ){
// Return FALSE if no parametres given
if( count( $parametres ) < 1 ){
return FALSE;
}
// Timestamp in Zebra Time
@mgronhol
mgronhol / hello-world.c
Created August 29, 2012 12:14
Random hello world
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char **argv ){
int i;
srand( 22315606 ); rand();
for( i = 0 ; i < 5 ; ++i ){ printf( "%c", 'A' + rand() % 32 ); }
@mgronhol
mgronhol / gist:6553af49ff4d173c29b2
Created July 17, 2012 09:34
Small stack virtual machine
/*
Commands in the virtual machine
+ - * / :Pop two numbers from the stack, [add|sub|mul|div] them and push the result back
pop :Pops a value from the stack
print :Pops a value from the stack and prints it to stdout
@mgronhol
mgronhol / gist:2936176
Created June 15, 2012 12:14
Nginx fastcgi cachcing
## Taa ensin tonne HTTP tai HTTPS blockin sisalle (esim. virtual.conf tai sitten sites-enables/default tms filuun)
fastcgi_cache_path /var/cache/nginx
levels=1:2 keys_zone=ZONE_KEY_TAHAN:10m
inactive=5m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
# ja taa sitten locationiin