Skip to content

Instantly share code, notes, and snippets.

@cpelley
cpelley / imgdiff
Last active November 4, 2016 08:44
Commandline image diff utility
#!/bin/sh
# Function to diff an image using imagemagick, displaying the original images
# and the diff.
#
# Add this file to your PATH to make available and ensure that it has
# executable privileges.
#
# Example usage:
# imgdiff <image1> <image2>
# http://askubuntu.com/questions/209517/does-diff-exist-for-images
@cpelley
cpelley / splitext
Last active November 4, 2016 08:45
Commandline utility to split the extension from the given file.
#!/bin/bash
# Function to return the extension of a file
# Returning the extension as a string (e.g. ".txt") or false otherwise.
#
# Add this file to your PATH to make available and ensure that it has
# executable privileges.
#
# Example usage:
# splitext <file>
[[ "${1}" = *.* ]] && echo ".${1##*.}" || false
@cpelley
cpelley / istext
Last active November 4, 2016 08:45
Commandline utility to determine whether the given file is text/binary.
#!/bin/bash
# Function to return whether the specified file is text/binary.
# Returning true/false
#
# Add this file to your PATH to make available and ensure that it has
# executable privileges.
#
# Example usage:
# istext <file>
[[ "$(file -b $1)" == *"text"* ]]
@cpelley
cpelley / pyflakes_noqa.py
Created November 14, 2016 12:17
pyflakes noqa monkeypatch
# Monkey-ptch pyflakes to respect lines with flake8 methods of ignoring
# lines and files.
def _report_with_ignore(self, messageClass, *args, **kwargs):
with open(self.filename, 'r') as code:
cont = code.readlines()
lineno = args[0].lineno
if '# noqa' in cont[lineno-1]:
return
elif '# flake8: ' + 'noqa' in ''.join(cont):
return
@cpelley
cpelley / json_loader.py
Last active November 17, 2016 10:52
Json loader
import json
class JLoader(object):
def __init__(required=None):
self._required = required
def _check_arguments(self, keys):
keys = set(keys)
if required:
@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()" &
@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 / 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 / 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 / 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
-------------