Skip to content

Instantly share code, notes, and snippets.

@mzipay
mzipay / lazy_descriptor.py
Created March 28, 2015 06:48
Python lazy non-data descriptor
# -*- 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
@mzipay
mzipay / pseudostruct.py
Created March 28, 2015 07:51
Fast, small-footprint Python data object template
# -*- 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.
@mzipay
mzipay / jsonp-proxy-request-interceptor.js
Last active May 19, 2021 09:34
AngularJS HTTP interceptor to work around CORS/JSONP problems
/**
* @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
@mzipay
mzipay / independent-qall-parallel-promises_1.js
Last active August 29, 2015 14:18
INDEPENDENT parallel promises with AngularJS $q.all
/*
* @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
@mzipay
mzipay / JDBCUtility.java
Created June 16, 2015 21:13
Simple JDBC console utility
/*
* 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:
*
@mzipay
mzipay / pyfunctions.bashrc
Created July 27, 2016 01:00
Some BaSH functions I use for finding/viewing Python standard library modules easily
# 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)
@mzipay
mzipay / prettyjson.bashrc
Created July 27, 2016 01:15
BaSH function to validate & pretty-print JSON from a file or stdin
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')"
}
@mzipay
mzipay / Doxyfile
Last active February 29, 2024 14:33
Custom Doxygen license and licenseblock/endlicenseblock commands
ALIASES += license="\par License^^"
ALIASES += license{1}="\par \1\n"
ALIASES += licenseblock="\par License^^\parblock^^"
ALIASES += licenseblock{1}="\par \1^^\parblock^^"
ALIASES += endlicenseblock="\endparblock^^"
@mzipay
mzipay / .bashrc
Created January 9, 2019 18:29
sqlplus with readline
function sqlplus {
socat READLINE,history=$HOME/.sqlplus_history EXEC:"$ORACLE_HOME/bin/sqlplus $(echo $@ | sed 's/\([\:]\)/\\\1/g')",pty,setsid,ctty
status=$?
}
@mzipay
mzipay / arrays_of_structs.c
Created January 18, 2019 23:45
C arrays of structs
/*
* Populate and process arrays of structs in C, with error handling.
*
* Zero-Clause BSD (0BSD)
* ---------------------------------------------------------------------
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED