Skip to content

Instantly share code, notes, and snippets.

Morten Piibeleht mortenpi

  • Massey University
  • Auckland, New Zealand
Block or report user

Report or block mortenpi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
mortenpi /
Created Mar 17, 2014
Previous / current / next iterator in Python
def previous_current_next(iterable):
"""Make an iterator that yields an (previous, current, next) tuple per element.
Returns None if the value does not make sense (i.e. previous before
first and next after last).
prv = None
cur =
View FindGSL.cmake
# Try to find gnu scientific library GSL
# See
# and
# Based on a script of Felix Woelk and Jan Woetzel
# (
# Available at:
mortenpi /
Created Mar 24, 2014
Short generic C++ function to read random data of any type from /dev/urandom.
#include <fstream>
#include <cstdlib>
template<class T>
T read_urandom()
union {
T value;
char cs[sizeof(T)];
} u;
mortenpi /
Created Apr 28, 2014
C++ Timer class using POSIX times()
#include "Timer.hh"
#include <iostream>
#include <sys/times.h>
#include <unistd.h>
// ---------------------------------------------------------------------
// class Time
// ---------------------------------------------------------------------
const long Time::sc_clk_tck = sysconf(_SC_CLK_TCK);
#include <iostream>
using namespace std;
struct type_t {
int i;
void function()
mortenpi /
Created Aug 21, 2015
Assassin's Creed: Brotherhood audio puzzle solver
#!/usr/bin/env python3
import itertools
def powerset(iterable):
xs = list(iterable)
return itertools.chain.from_iterable(
itertools.combinations(xs,n) for n in range(len(xs)+1)
samples = [
mortenpi /
Created Aug 28, 2015
Function to create a vector of evenly spaced numbers in C++.
// Create a vector of evenly spaced numbers.
vector<double> range(double min, double max, size_t N) {
vector<double> range;
double delta = (max-min)/double(N-1);
for(int i=0; i<N; i++) {
range.push_back(min + i*delta);
return range;
mortenpi /
Last active Sep 6, 2015
A quick hack to generate a sqlite database from yumdb and repository cache to ease understanding what packages are installed and available.
#!/usr/bin/env python3
import argparse
import os
import os.path
import re
import sqlite3
def yumdb_packages(path):
dirs = os.listdir(path)
mortenpi / NoninteractiveGadfly.jl
Created Sep 7, 2015
Makes the plots in Gadfly non-interactive (Juno lags with interactive plots)
View NoninteractiveGadfly.jl
module NoninteractiveGadfly
import Compose
import Compose: writemime
import Gadfly
export @noninteractive
type NoninteractivePlot
mortenpi / ComposeHacks.jl
Last active Sep 21, 2015
A collection of helper macros and stuff for Julia's Compose and Gadfly packages.
View ComposeHacks.jl
# ComposeHacks module
# This module is a collection of hacks to make working with Compose and Gadfly
# more convenient (in Julia).
# The MIT License (MIT)
# Copyright (c) 2015 Morten Piibeleht
# Permission is hereby granted, free of charge, to any person obtaining a copy
You can’t perform that action at this time.