This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SlicerClass(object): | |
''' | |
slicerClass allows the creation of a slicer object. | |
A slicer, when indexed with square brackets, will return a slice object. | |
This allows a slice to be created and neatly passed as an argument. | |
''' | |
def __getitem__(self,val): | |
return val | |
def __len__ (self): | |
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import os, time, argparse | |
from subprocess import call, check_call, check_output | |
def stop_cmd(name): | |
return ['docker', 'stop', name], False | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def online_mean(): | |
""" | |
Return an initialised generator for online mean (next() has been called). | |
""" | |
omean = _online_mean() | |
next(omean) | |
return omean | |
def _online_mean(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
An example of using the `yield from` syntax in python 3 and a generator expression than mimics this. | |
""" | |
def yield_only_odd(i): | |
''' | |
Yield i if and only if i is odd. | |
This is a generator that yields zero or one times. | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IPython magic to check for PEP8 compliance. | |
# Author: Juan Luis Cano <juanlu001@gmail.com> | |
"""IPython magic to check for PEP8 compliance. | |
To use it, type | |
```%load_ext pep8magic``` | |
and then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def get_haiku(n_adj=1, sep='-'): | |
''' | |
return short haiku, seperated by sep. | |
Original from https://gist.github.com/afriggeri/1266756 | |
''' | |
adjs = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alpha | country | numerical | |
---|---|---|---|
BEL | Belgium | 056 | |
BLZ | Belize | 084 | |
BEN | Benin | 204 | |
BMU | Bermuda | 060 | |
BTN | Bhutan | 064 | |
BOL | Bolivia (Plurinational State of) | 068 | |
BES | Bonaire, Saint Eustatius and Saba | 535 | |
BIH | Bosnia and Herzegovina | 070 | |
BWA | Botswana | 072 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def num_fmt(num): | |
i_offset = 24 # change this if you extend the symbols!!! | |
prec = 3 | |
fmt = '.{p}g'.format(p=prec) | |
symbols = ['Y', 'Z', 'E', 'P', 'T', 'G', 'M', 'k', '', 'm', 'u', 'n'] | |
e = math.log10(abs(num)) |
NewerOlder