Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthias Sieber manonthemat

View GitHub Profile
@manonthemat
manonthemat / trees.hs
Created Aug 6, 2021
Functional Programming in Haskell - The University of Glasgow
View trees.hs
data Tree =
Leaf
| Node Int Tree Tree
deriving Show
treeDepth :: Tree -> Int
treeDepth Leaf = 0
treeDepth (Node _ a b) = 1 + max (treeDepth a) (treeDepth b)
treeSum :: Tree -> Int
@manonthemat
manonthemat / m.js
Created Nov 18, 2017
quick and dirty javascript "lib" to prepare for a statistics exam
View m.js
'use strict';
var _fstore = [];
function factorial (n) {
if (n == 0 || n == 1) {
return 1;
}
if (_fstore[n] > 0) {
return _fstore[n];
}
@manonthemat
manonthemat / gist:cfb8272ef6695daf7624
Created Feb 6, 2016
copying nodes with labels and properties - hacky
View gist:cfb8272ef6695daf7624
// 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 / gist:687c5457d09ea0c1235d
Created Apr 13, 2015
simple token strategy with hapi
View gist:687c5457d09ea0c1235d
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);
@manonthemat
manonthemat / stack.cpp
Last active Aug 29, 2015
simple stack data structure in C++
View stack.cpp
#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 / roman.cpp
Created Jan 19, 2015
first draft of a simple roman calculator
View roman.cpp
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <regex>
#include <sstream>
using namespace std;
View gist:dda18bb2f28dee2c528a
puts' ______________________________ '
puts'< What\'s wrong with this food? >'
puts' ------------------------------ '
puts' \ ^__^'
puts' \ (oo)\_______'
puts' (__)\ )\/\''
puts' ||----w |'
puts' || ||'
@manonthemat
manonthemat / base.hs
Created May 21, 2014
simple math fun with haskell - custom number base systems
View base.hs
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
@manonthemat
manonthemat / gist:9938961
Created Apr 2, 2014
Example of a simple algorithm with a running time that grows proportional to the input size
View gist:9938961
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 / top_history.rb
Created Nov 18, 2013
function to sort a shell history file and print out the lines of commands that has been executed the most
View top_history.rb
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