Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python2
"""
Generate a script to create a multi-hop SSH connection.
Usage: sshroute.py [options...] HOST
Options:
-l SPEC, --local=SPEC Tunnel a port - local:via:remote
-r SPEC, --remote=SPEC Reverse tunnel a port - remote:via:local
-h HOST, --host=HOST Go via another host
@alanbriolat
alanbriolat / log_exception.py
Created June 9, 2014 14:15
Log unhandled Python exceptions with logging.critical(...).
import traceback
import sys
def excepthook(type, value, tb):
for part in traceback.format_exception(type, value, tb):
for line in part.splitlines():
logging.critical(line)
sys.excepthook = excepthook
import logging
logging.basicConfig(level=logging.DEBUG)
class Foo(object):
def __init__(self):
self.bar = "hello"
def __getitem__(self, key):
return getattr(self, key)
program pointer_remap
type :: real_pointer
real, pointer :: p => null()
end type real_pointer
real, target, dimension(1:3) :: vec
type(real_pointer), dimension(-1:1) :: pVec
integer :: i

Keybase proof

I hereby claim:

  • I am alanbriolat on github.
  • I am alanbriolat (https://keybase.io/alanbriolat) on keybase.
  • I have a public key whose fingerprint is 139D 86F0 095A E34A 4E82 AED9 4911 5981 D488 B8BB

To claim this, I am signing this object:

@alanbriolat
alanbriolat / ifort_initialisation_bug.f90
Created October 2, 2013 13:09
A demonstration of a weird cross-module array-inside-derived-type initialisation bug in ifort.
! A demonstration of a weird cross-module array-inside-derived-type
! initialisation bug in ifort. ifort --version: ifort (IFORT) 14.0.0 20130728.
! None of these issues appear in other compilers tested (gfortran 4.6 and 4.7).
module module_a
implicit none
private
integer :: i
! Test the array initialiser, works just fine.
@alanbriolat
alanbriolat / broken_associate.F90
Created June 3, 2013 14:43
Checking for ASSOCIATE deficiencies in Fortran compilers when combined with derived type arrays. Must be saved with uppercase extension (broken_associate.F90) so the C preprocessor bits will work.
program test_associate
implicit none
type foo_t
integer :: a, b, c
end type
type(foo_t), dimension(6) :: foo
type(foo_t) :: sfoo
@alanbriolat
alanbriolat / examples.txt
Last active December 11, 2015 05:49
An ugly Python script to work out what proportion of weekday instances are on odd "day of month" numbers for a given year
$ python3 odd_days.py 2012
Mon 0.49056603773584906
Tues 0.5192307692307693
Wed 0.4807692307692308
Thurs 0.5192307692307693
Fri 0.5
Sat 0.5
Sun 0.5094339622641509
$ python3 odd_days.py 2013
@alanbriolat
alanbriolat / 21-yubikey.conf
Created January 10, 2013 10:01
yubikey /etc/X11/xorg.conf.d/ snippet
Section "InputClass"
Identifier "yubikey"
MatchIsKeyboard "on"
MatchVendor "Yubico"
MatchProduct "Yubico Yubikey II"
Driver "evdev"
Option "XkbRules" "evdev"
Option "XkbModel" "pc105"
Option "XkbLayout" "us"
Option "XkbVariant" "basic"
@alanbriolat
alanbriolat / strings.f90
Created October 31, 2012 15:45
Horrible indistinguishable Fortran strings
program strings
implicit none
character(len=20) :: a, b
print *, "strings: ", a, b
if (a == b) then
print *, "strings are equal"
endif