Skip to content

Instantly share code, notes, and snippets.

@ntim
ntim / unused_references.py
Created March 18, 2016 11:46
List unused entries in latex bibliographies by parsing the aux file generated by biber
#!/usr/bin/python
#-*- coding: utf-8
import os
import glob
from pybtex.database.input import bibtex
from pyparsing import Word, alphanums, Literal
auxfile = glob.glob("*.aux")[0]
bibfiles = []
parser = bibtex.Parser()
@ntim
ntim / wrap_array_first_argument.py
Created February 21, 2016 13:47
Function wrapper for uncertainties package for wrapping of functions accepting arrays
def wrap_array_first_argument(f, derivatives_args=[], derivatives_kwargs={}):
"""
Wraps a function f into a function that also accepts numbers with
uncertainties (UFloat objects) using uncertainties.wrap().
If the wrapped function is called with an array as first argument, the
wrap iterates over all values and therefore the result will also be an
array.
"""
def f_with_array_first_argument(*args, **kwargs):
@ntim
ntim / range_integer.py
Created February 21, 2016 13:46
Luigi RangeBase implementation replacing datetime with an integer
import luigi
import datetime
import itertools
import time
class RangeInteger(luigi.tools.range.RangeBase):
"""
Instead of datetime with a specific resolution, we use a simple integer.
The rangeBase is a bit inflexible regarding the parameter type, but we can
work around it by parsing it to unix timestamps back and forth.
@ntim
ntim / uncertainty_parameter.py
Created February 21, 2016 13:42
Luigi Parameter with a number with uncertainty
import luigi
import uncertainties
class UncertaintyParameter(luigi.Parameter):
"""
Implements luigi.Parameter for the uncertainties package.
https://github.com/spotify/luigi/
https://github.com/lebigot/uncertainties
"""
@ntim
ntim / f_number_axes_scale.py
Last active February 21, 2016 13:43
F-Number axes scale for matplotlib
import numpy as np
import matplotlib.scale as mscale
import matplotlib.transforms as mtransforms
from matplotlib.ticker import Formatter, FixedLocator
class FNumberScale(mscale.ScaleBase):
name = 'fnumber'
def __init__(self, axis, **kwargs):
@ntim
ntim / gitcheck.sh
Created November 30, 2015 14:41
Gitcheck from
#!/bin/bash
##
## Downloaded from https://astrofloyd.wordpress.com/2013/02/10/gitcheck-check-all-your-git-repositories-for-changes/
##
## gitcheck:
## Check all git repositories in subdirectories, and list the ones with changes
## 30/07/2011, AstroFloyd, bzrcheck
## 18/01/2013, Astrofloyd, gitcheck
# Initialise counters:
@ntim
ntim / .gitignore
Last active August 29, 2015 14:26 — forked from kogakure/.gitignore
Git: .gitignore file for (Xe)LaTeX projects
*.aux
*.glo
*.idx
*.log
*.toc
*.ist
*.acn
*.acr
*.alg
*.bbl
@ntim
ntim / distance_of_time_in_words.coffee
Last active August 29, 2015 14:25 — forked from sulf/gist:1157909
Rails helper time_ago_in_words() and distance_of_time_in_words() translated into an AngularJs filter in CoffeScript
app.filter('distance_of_time_in_words', ->
(from_time, to_time, include_seconds) ->
include_seconds = include_seconds || true
to_time = to_time || 0
distance_in_minutes = Math.round(Math.abs(to_time - from_time) / 60 / 1000)
distance_in_seconds = Math.round(Math.abs(to_time - from_time) / 1000)
if 0 <= distance_in_minutes and distance_in_minutes <= 1
if !include_seconds
if distance_in_minutes == 0
return 'less than 1 minute ago'
@ntim
ntim / legend.py
Last active August 29, 2015 14:23
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from matplotlib.table import Table
from matplotlib.artist import allow_rasterization
from matplotlib.text import Text
import sig
class LegendTable(Table):
def __init__(self, ax, loc=None, bbox=None, title=None):
Table.__init__(self, ax, loc, bbox)
[Unit]
Description = Hyperion systemd service
After = mediacenter.service
[Service]
Type = simple
ExecStart = /usr/bin/hyperiond /etc/hyperion.config.json
Restart = always
[Install]