Instantly share code, notes, and snippets.

View prettyjson.bashrc
function ppjson {
test -f "${1}" && src="open('${1}')" || src="sys.stdin"
python -c "import json,sys;sys.stdout.write(json.dumps(json.load(${src}),indent=2)+'\n')"
}
View pyfunctions.bashrc
# show the location of a Python module's .py
# usage: pyfn module.name [pyversion]
# example: "pyfn hashlib", "pyfn hashlib 3.5", "pyfn hashlib 2"
function pyfn {
test -z "${1}" && return 1
fn=$(python${2} -c "import ${1},sys;sys.stdout.write(getattr(${1},'__file__').rsplit('.',1)[0]+'.py')")
test -f "${fn}" && echo "${fn}"
}
# open a Python module's .py in vi (read-only)
View JDBCUtility.java
/*
* Copyright (c) 2009 Matthew Zipay
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
View independent-qall-parallel-promises_1.js
/*
* @license CC0 1.0 (http://creativecommons.org/publicdomain/zero/1.0/)
*
* Angular's $q.all works great for cases where a rejection of any one promise
* SHOULD cause all parallel promises to be rejected... but it's not so great
* when you've got a number of promises that need to run in parallel and you
* don't want a single rejection to reject the entire $q.all promise.
* (One example: think aggregating data from multiple APIs.)
*
* This gist shows one way to "partially resolve" parallel processes when at
View jsonp-proxy-request-interceptor.js
/**
* @license CC0 1.0 (http://creativecommons.org/publicdomain/zero/1.0/)
*
* The problem:
* You need to make a cross-domain request for JSON data, but the remote
* server doesn't send the necessary CORS headers, and it only supports
* simple JSON-over-HTTP GET requests (no JSONP support).
*
* One possible solution:
* Use 'jsonp-proxy-request-interceptor' to proxy the request through
View pseudostruct.py
# -*- coding: utf-8 -*-
# Copyright (c) 2010, 2015 Matthew Zipay <mattz@ninthtest.net>.
# All rights reserved.
# Licensed under the MIT License <http://opensource.org/licenses/MIT>.
class PseudoStruct:
"""Base class for structure-like data objects.
View lazy_descriptor.py
# -*- coding: utf-8 -*-
# Copyright (c) 2015 Matthew Zipay <mattz@ninthtest.net>. All rights reserved.
# Licensed under the MIT License <http://opensource.org/licenses/MIT>.
class lazy:
r"""Decorate a no-arg getter to have lazy initialization behavior.
The first time the property is accessed on an instance, the computed