Skip to content

Instantly share code, notes, and snippets.

View manonthemat's full-sized avatar

Matthias Sieber manonthemat

View GitHub Profile
@manonthemat
manonthemat / gist:9938961
Created April 2, 2014 17:32
Example of a simple algorithm with a running time that grows proportional to the input size
def find_max(data):
"""Return the maximum element from a nonempty Python list."""
biggest = data[0]
for val in data:
if val > biggest:
biggest = val
return biggest
@manonthemat
manonthemat / base.hs
Created May 21, 2014 18:28
simple math fun with haskell - custom number base systems
import Data.Char (digitToInt)
numberToBaseString :: Int -> Int -> String
numberToBaseString n base
| n < base = show n
| otherwise = numberToBaseString ((n - (n `mod` base)) `div` base) base ++ show (n `mod` base)
baseStringToValue :: String -> Int -> Int
baseStringToValue n base
| n == [] = 0
puts' ______________________________ '
puts'< What\'s wrong with this food? >'
puts' ------------------------------ '
puts' \ ^__^'
puts' \ (oo)\_______'
puts' (__)\ )\/\''
puts' ||----w |'
puts' || ||'
@manonthemat
manonthemat / roman.cpp
Created January 19, 2015 19:59
first draft of a simple roman calculator
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <regex>
#include <sstream>
using namespace std;
@manonthemat
manonthemat / stack.cpp
Last active August 29, 2015 14:14
simple stack data structure in C++
#include <iostream>
using namespace std;
class Stack_overflow {};
class Stack_underflow {};
class Stack {
public:
Stack(int sz) : sz{sz}, top{-1}, elem {new int[sz]} {};
@manonthemat
manonthemat / gist:687c5457d09ea0c1235d
Created April 13, 2015 19:12
simple token strategy with hapi
server.register(require('hapi-auth-jwt2'), function(err) {
if (err) {
throw err;
}
server.auth.strategy('token', 'jwt', false, {
key: constants.application.secretKey,
validateFunc: function(decoded, request, callback) {
if (!decoded || !decoded.verified) {
return callback(null, false);
import urllib2
import random
import difflib
import datetime
def fetch(url):
"""Fetches requested url, returns lines in list"""
response = urllib2.urlopen(url)
lines = response.readlines()
return lines
@manonthemat
manonthemat / top_history.rb
Created November 18, 2013 03:48
function to sort a shell history file and print out the lines of commands that has been executed the most
def sortCommands(histFile, limit=10)
file = open(histFile, 'r')
lines = file.readlines
file.close
freqs = Hash.new(0)
lines.each do |line|
freqs[line] += 1
end
a = freqs.sort_by {|k, v| -v}[0..limit]
i = 0
@manonthemat
manonthemat / gist:cfb8272ef6695daf7624
Created February 6, 2016 18:48
copying nodes with labels and properties - hacky
// requires cypher-rest
// npm i cypher-rest
// gist for http://stackoverflow.com/questions/35191765/how-can-we-copy-labels-from-one-node-to-another-in-one-cypher
'use strict';
const util = require('util');
const c = require('cypher-rest');
const neoUrl = 'http://127.0.0.1:7474/db/data/transaction/commit';
@manonthemat
manonthemat / m.js
Created November 18, 2017 16:17
quick and dirty javascript "lib" to prepare for a statistics exam
'use strict';
var _fstore = [];
function factorial (n) {
if (n == 0 || n == 1) {
return 1;
}
if (_fstore[n] > 0) {
return _fstore[n];
}