Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / confirm
Last active November 4, 2016 08:44
Commandline utility to request confirmation before running a command.
#!/bin/sh
# Function to verify user want to run the commant.
#
# Add this file to your PATH to make available and ensure that it has
# executable privileges.
#
# Example usage:
# confirm && <command>
# http://stackoverflow.com/questions/3231804/in-bash-how-to-add-are-you-sure-y-n-to-any-command-or-alias
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"metadata": {
"name": "",
"signature": "sha256:05f4a43c46ca589337d846930f349fcde8b87fa125b344c972943419fd6f2999"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@cpelley
cpelley / svn_vimdiff.sh
Last active April 21, 2017 15:13
svn conflcit resolution (vimdiff + graphical diff)
#!/bin/sh
# Configure your favorite diff program here.
DIFF="/usr/bin/vimdiff"
# Subversion provides the paths we need as the sixth and seventh
# parameters.
LEFT=${6}
RIGHT=${7}
# Call "svn diff --force" to end up here with binary files.
@cpelley
cpelley / svn_merge_vimdiff.sh
Last active October 13, 2016 07:18
svn diff (vimdiff)
#!/bin/sh
# Add the following to the [helpers] section of ~/.subversion/config
# merge-tool-cmd = /path/to/svn_merge_vimdiff.sh
BASE=${1}
THEIRS=${2}
MINE=${3}
MERGED=${4}
WCPATH=${5}