Skip to content

Instantly share code, notes, and snippets.

View mortenpi's full-sized avatar

Morten Piibeleht mortenpi

View GitHub Profile
@mortenpi
mortenpi / gadfly-spy-test.jl
Created December 29, 2015 17:02
Gadfly spy() test
if length(ARGS) != 1
error("Output file name not provided!")
end
ofile = ARGS[1]
println("Writing the plot to: $ofile")
using Gadfly
M,N = 22,30
matrix = zeros(Float64, (M,N))
for i=1:M, j=1:N
#!/bin/bash
echo "Working directory:" `pwd`
date
echo
echo "SLURM variables"
# For a full list, see http://slurm.schedmd.com/sbatch.html
echo SLURM_JOB_ID=${SLURM_JOB_ID}
echo SLURM_JOB_NAME=${SLURM_JOB_NAME}
echo SLURM_JOB_NODELIST=${SLURM_JOB_NODELIST}
@mortenpi
mortenpi / softwarecenter.css
Last active November 15, 2015 15:47
A better style for the Ubuntu Software Center (/usr/share/software-center/ui/gtk3/css/softwarecenter.css)
@define-color light-aubergine #BBBBBB;
@define-color super-light-aubergine #EDEDED;
/*
do not use text-shadow until bugzilla.gnome.org bug #686209 is
fixed - its leaking memory
*/
#featured-star {
@mortenpi
mortenpi / time_lm.jl
Created October 3, 2015 16:19
Time a function multiple times to see how memory usage behaves.
import Base: gc_bytes, gc_time_ns, time_print
function lm_1_10(x1, x10)
A = (x10-x1)/9
B = (10*x1-x10)/9
A,B
end
macro time_N(N, ex)
quote
@mortenpi
mortenpi / bit.jl
Created September 28, 2015 14:54
Get the nth bit of a number in Julia.
# Gets the Nth bit of m
function bit(N, m)
m & (1<<(N-1)) >> (N-1)
end
@show [bit(n,0) for n=1:5]
@show [bit(n,1) for n=1:5]
@show [bit(n,2) for n=1:5]
@show [bit(n,3) for n=1:5]
@show [bit(n,5) for n=1:5]
@mortenpi
mortenpi / ComposeHacks.jl
Last active September 21, 2015 18:56
A collection of helper macros and stuff for Julia's Compose and Gadfly packages.
# 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
@mortenpi
mortenpi / NoninteractiveGadfly.jl
Created September 7, 2015 14:06
Makes the plots in Gadfly non-interactive (Juno lags with interactive plots)
module NoninteractiveGadfly
import Compose
import Compose: writemime
import Gadfly
export @noninteractive
type NoninteractivePlot
p::Gadfly.Plot
end
@mortenpi
mortenpi / yumhelp-dbgen.py
Last active September 6, 2015 20:38
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)
dirs.sort()
@mortenpi
mortenpi / range.cc
Created August 28, 2015 18:35
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
mortenpi / acbh-audio.py
Created August 21, 2015 19:52
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 = [