Skip to content

Instantly share code, notes, and snippets.

@JohannesBuchner
JohannesBuchner / pbar.py
Last active December 16, 2015 03:29
Python progressbar
import progressbar
pbar = progressbar.ProgressBar(widgets=[progressbar.Percentage(),
progressbar.Counter('%5d'), progressbar.Bar(), progressbar.ETA()])
for obj in pbar(to_handle):
# deal with object
@JohannesBuchner
JohannesBuchner / caching.py
Last active December 17, 2015 13:39
joblib caching for expensive functions
import joblib
import os
cachedir = 'cache'
if not os.path.isdir(cachedir): os.mkdir(cachedir)
mem = joblib.Memory(cachedir=cachedir, verbose=True)
@mem.cache
def my_long_function(i):
return i + i
@JohannesBuchner
JohannesBuchner / installMultiNest.sh
Last active December 23, 2015 04:19
install {,Py,R}MultiNest
#!/bin/bash
#
# necessary packages:
# sudo apt-get install python-{scipy,numpy,matplotlib,progressbar} ipython libblas{3,-dev} liblapack{3,-dev} libatlas{3-base,-dev} cmake build-essential git gfortran r-base r-base-dev
#
echo 'checking installed software requirements'
for c in R cmake; do
if ! hash $c; then echo "install '$c' first"; exit 1; fi
@JohannesBuchner
JohannesBuchner / publishPython.sh
Created September 20, 2013 17:00
tool for publishing sphinx documentation on github and releasing packages on PyPI
#!/bin/bash
# Author: Johannes Buchner (C) 2013
# tool for publishing sphinx documentation on github
# and releasing packages on PyPI
case "$1" in
doc)
# see https://help.github.com/articles/creating-project-pages-manually
make -C doc/ html &&
git checkout gh-pages &&
@JohannesBuchner
JohannesBuchner / thunderbird_build_notes.txt
Last active December 24, 2015 10:09
Thunderbird/Mozilla build notes
Follow https://developer.mozilla.org/en-US/docs/Simple_Thunderbird_build
comm-central/.mozconfig:
ac_add_options --enable-application=mail
ac_add_options --with-ccache=/usr/bin/ccache
ac_add_options --enable-calendar
#ac_add_options --disable-debug
ac_add_options --enable-debug
@JohannesBuchner
JohannesBuchner / runProcess.py
Last active December 24, 2015 16:19
launch process
import subprocess
def runscript(name):
args = ('./interact', name,)
p = subprocess.Popen(args)
# p.communicate() # set stdin/stdout/stderr=subprocess.PIPE
if p.wait() != 0:
raise Exception('return value of startup script was non-zero')
@JohannesBuchner
JohannesBuchner / updateGentoo.sh
Created October 9, 2013 11:05
update Gentoo Linux
#!/bin/bash
#rm /usr/portage/distfiles/*
renice +20 -p $$
ionice -c3 -p $$
pgrep emerge >/dev/null || rm /var/tmp/portage/*-* -rf
emerge-webrsync && eix-update
ARGS="--quiet-build --load-average=10 --jobs=3"
@JohannesBuchner
JohannesBuchner / howlong.py
Last active December 27, 2015 17:29
ETA from external programs
"""Estimate Time until completion of a process.
Usage: <statusprog> | howlong.py <n>
<statusprog> is a program that writes a line to stdout from time to time.
The line is the number of items completed so far.
<n> is the total number of items to complete.
Example:
for((i=0;i<20;i++)); do echo $i; sleep 1; done | python howlong.py 20
@JohannesBuchner
JohannesBuchner / install.rst
Last active December 29, 2015 22:19
Prepare VirtualBox image

Installation notes for Virtual machine

Contains

  • BXA
  • MultiNest
  • PyMultiNest
  • Sherpa
  • Xspec
@JohannesBuchner
JohannesBuchner / toy.py
Last active August 29, 2015 14:05
Toy linefitting
import numpy
from numpy import log, isnan, isfinite, sin, cos, tan, abs, any, pi
import scipy, scipy.stats
import pymultinest
import json
import sys
import matplotlib.pyplot as plt
numpy.random.seed(1)
outputfiles_basename = "mnchains_toy_"