Skip to content

Instantly share code, notes, and snippets.

View j08lue's full-sized avatar

Jonas j08lue

View GitHub Profile
# -*- coding: utf-8 -*-
"""A module for various utilities and helper functions"""
import numpy as np
#cimport numpy as np
#cimport cython
DTYPEf = np.float64
#ctypedef np.float64_t DTYPEf_t
@j08lue
j08lue / maximum_rectangle.py
Created February 13, 2014 10:03
Maximum Rectangle algorithms
"""Maximum rectangle algorithm
Main source: [1]
[1] http://stackoverflow.com/questions/8663079/maximum-rectangle-algorithm-implementation
"""
from collections import namedtuple
import numpy as np
@j08lue
j08lue / nbody.py
Created February 24, 2014 14:57
nbody physics exercise
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Non-interactive command line front end to NBody implementation"""
import time
import numpy as np
import matplotlib.pyplot as plt
import itertools
@j08lue
j08lue / stickplot1.py
Last active August 29, 2015 13:56
Matplotlib stick plot recipes
"""
Credits
-------
Stephane Raynaud
http://permalink.gmane.org/gmane.comp.python.matplotlib.general/24155
"""
import matplotlib.pyplot as plt
import numpy as np
import datetime as dtime
from matplotlib.dates import date2num
@j08lue
j08lue / basemap_cartopy_irregular_grid.ipynb
Created March 13, 2014 12:26
Basemap Cartopy irregular grid
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@j08lue
j08lue / st_archive.sh
Last active August 29, 2015 14:05
CESM post-run short-term archiving
#!/bin/bash
CASE=$1
DATA_ROOT=${DATA_ROOT:-$(pwd)}
RUNDIR="$DATA_ROOT/$CASE/run"
DOUT_S="TRUE"
DOUT_S_ROOT=${DOUT_S_ROOT:-"$DATA_ROOT/$CASE"}
@j08lue
j08lue / nclook.py
Created October 7, 2014 10:55
Quickly open a (multi-file) netCDF dataset into ipython from command line
#!/usr/env python
"""
This script can be executed as is or via an alias, e.g.
alias nclookipy='ipython -i ~/path/to/nclook.py'
to quickly open a NetCDF file in Python.
"""
import netCDF4
import argparse
@j08lue
j08lue / extradds.py
Created November 6, 2014 09:04
extract email addresses from some string
import re
def extract_email_addresses(adds):
adds = ''.join(adds.split())
adds = re.sub(r'(\"|\,)', ' ', adds)
adds = re.split(r'\<(.*?\@.*?)\>', adds)
#adds = re.findall(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$", ''.join(adds))
adds = [a for a in adds if '@' in a]
return adds
@j08lue
j08lue / findadds.py
Created June 16, 2015 09:46
Find email addresses in some text (e.g. html) file
import re
with open('cic.html', 'r') as f:
raw = f.read()
r = r"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"
add = re.findall(r, raw)
unique = sorted(set(add))
@j08lue
j08lue / lt_archive.sh
Created June 17, 2015 14:56
CESM 1.2.2 data archiving scripts
#!/bin/bash
msls () {
rd=$1
ssh_loc=$2
scp_loc=$3
if [ "${ssh_loc}" != "" ] && [ "${scp_loc}" != "" ]; then
ssh -q ${ssh_loc} "ssh -q ${scp_loc} ls -l ${rd}"
fi