Skip to content

Instantly share code, notes, and snippets.

@cpelley
cpelley / random_duration_script.py
Last active November 7, 2022 16:16
Testing gnu parallel behaviour
#!/usr/bin/python3
import sys
from time import sleep
import random
for i in range(random.randint(3, 8)):
sleep(random.random() / 10)
print(f"{sys.argv[1]}, step {i}")
if i == 2 and ("arg1" in sys.argv[1] or "arg2" in sys.argv[1]):
raise ValueError(f"{sys.argv[1]} raised an exception")
@cpelley
cpelley / conda_tab_complete
Created April 27, 2018 10:23
conda tab complete
# command: source
# Allow autocomplete for conda environments
_complete_source_activate_conda(){
if [ ${COMP_WORDS[COMP_CWORD-1]} != "activate" ]
then
return 0
fi
local cur=${COMP_WORDS[COMP_CWORD]}
# ls $(path when conda root || path when conda environment activated)
@cpelley
cpelley / geo_debug_plot.py
Created March 8, 2018 12:16
Show coordinates under cursor for iris
...
iplt.pcolormesh(cube)
# https://matplotlib.org/gallery/api/image_zcoord.html
numrows, numcols = cube.shape
def format_coord(x, y):
#col = int(x + 0.5)
#row = int(y + 0.5)
row = int(abs(cube.coord(axis='y').points - y).argmin())
col = int(abs(cube.coord(axis='x').points - x).argmin())
@cpelley
cpelley / svn_get_renames.py
Created November 24, 2017 04:07
Fetch svn file renames/moves
#!/usr/bin/env python2.7
import argparse
from difflib import SequenceMatcher
import os
import subprocess
import tempfile
def main(old_url, new_url, threshold):
OLD_URL, OLD_REV = old_url.split('@')
@cpelley
cpelley / svn_branch_diff.sh
Created November 7, 2017 12:58
svn diff of file renames (moves)
REPO_BRANCH_PATH=<relative_url>
OLD_REV=<old_revision>
NEW_REV=<new_revision>
OLD_PATH=("<file_path>" \
"<file_path2>" \
)
NEW_PATH=("<file_path_new>" \
"<file_path2_new>" \
)
@cpelley
cpelley / inline_code_comment.py
Created October 20, 2017 19:22
Offline inline code commenter utility
#!/usr/bin/env python2.7
"""
The following script is used for writing code comments offline and writing
them in a format suitable for the given version control software and
potentially ticketing system. Example: svn + trac (edgewall).
Example usage
-------------
@cpelley
cpelley / transpose_aux_coord.ipynb
Created June 15, 2017 16:00
transpose with aux coords bug?
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cpelley
cpelley / regrid_help.ipynb
Last active June 11, 2017 02:57
Some guideance on regrid testing and regrid UI
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cpelley
cpelley / transform_points_esmf.ipynb
Created June 2, 2017 08:09
transforming cell corners for ESMF usage
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cpelley
cpelley / idle
Created December 14, 2016 10:45
Run IDLE within an alternative python environment
/path/to/python -c "from idlelib.PyShell import main; main()" &