This file contains hidden or 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
| #!/usr/bin/perl | |
| $ip = $ARGV[0] or $ip=<STDIN>; | |
| chomp($ip); | |
| @ip=split(/\./,$ip); | |
| if ($#ip != 3 or scalar grep {/[^0-9]/ or $_ > 255} @ip) { | |
| die "$ip not in IPV4 format\n"; | |
| } |
This file contains hidden or 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 logging | |
| """ | |
| Logging wrapper which allows a library ("mylib") to use python logging while giving | |
| some control to the calling code over which logger it should use. | |
| Code within the library should call mylib_logging.get_logger where it would | |
| otherwise call logging.getLogger. Calling code can call mylib_logging.set_logger | |
| before using the library to tell it which logger to use, but if this is not | |
| done, then it will fall back to using logging.getLogger. |
This file contains hidden or 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 time | |
| import random | |
| try: | |
| import builtins as bi | |
| except ImportError: | |
| import __builtin__ as bi | |
| bi.__import2__ = bi.__import__ |
This file contains hidden or 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 write(self, filename, arcname=None, compress_type=None, | |
| fp=None, mtime=None, size=None, isdir=None, | |
| mode=None): | |
| """Put the bytes from filename into the archive under the name | |
| arcname.""" | |
| if not self.fp: | |
| raise RuntimeError( | |
| "Attempt to write to ZIP archive that was already closed") | |
| if isdir: |
This file contains hidden or 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 explore(l, c, t): # l = 2d list of connections; c = current node; t = target node | |
| if c == t: # base case | |
| return [[c]] | |
| else: # recursive case | |
| conns = [] | |
| if c in i: | |
| conns.extend([[c] + conn | |
| for conn in explore([k for k in l if i != k], | |
| (i[0] if c == i[1] else i[1]), | |
| t) |
This file contains hidden or 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
| # example usage: | |
| # | |
| # this runs the following commands simultaneously, each in different areas of the screen: | |
| # 1) echo hello | |
| # 2) cal | |
| # 3) for i in 1 2 3 4 5 ; do date; sleep 1; done | |
| # | |
| # it waits for 2 seconds after they have all finished, before clearing the screen | |
| # | |
| ./run_in_panes.py -s 2 'echo hello' 'cal' 'for i in 1 2 3 4 5 ; do date; sleep 1; done' |
This file contains hidden or 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 numpy as np | |
| import scipy.stats | |
| from scipy.interpolate import interp1d | |
| #import matplotlib as mpl | |
| from matplotlib import pyplot as plt | |
| def cints(n, levels): | |
| ci_out = np.zeros((len(levels), 1 + n)) |
This file contains hidden or 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 commented_pprint(obj, name='obj', indent=4): | |
| """ | |
| Pretty-print object obj, which can contain nested dictionaries, lists and tuples, | |
| with comment lines showing how to index it. | |
| """ | |
| pairs = list(_yield_pprint_lines(obj, name=name, indent=indent)) | |
| max_len = max(len(line) for line, _ in pairs) | |
| for line, comment in pairs: | |
| print(f'{line:{max_len}} {comment}') |
This file contains hidden or 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 MyIter: | |
| def __init__(self, iterable): | |
| self._iterator = iter(iterable) | |
| self.at_end = False | |
| self._prefetch_next() | |
| def __next__(self): | |
| if self.at_end: | |
| raise StopIteration |
This file contains hidden or 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
| #!/usr/bin/env python | |
| help = ("Compresses a netCDF file by compressing time slices and " | |
| "concatenating them. Requires NCO utilities.") | |
| import os | |
| import sys | |
| import subprocess | |
| import argparse | |
| import shutil |