Skip to content

Instantly share code, notes, and snippets.

Matthew Zipay mzipay

View GitHub Profile
@mzipay
mzipay / arrays_of_structs.c
Created Jan 18, 2019
C arrays of structs
View arrays_of_structs.c
/*
* 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
@mzipay
mzipay / .bashrc
Created Jan 9, 2019
sqlplus with readline
View .bashrc
function sqlplus {
socat READLINE,history=$HOME/.sqlplus_history EXEC:"$ORACLE_HOME/bin/sqlplus $(echo $@ | sed 's/\([\:]\)/\\\1/g')",pty,setsid,ctty
status=$?
}
@mzipay
mzipay / Doxyfile
Last active Dec 23, 2018
Custom Doxygen license and licenseblock/endlicenseblock commands
View Doxyfile
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 / prettyjson.bashrc
Created Jul 27, 2016
BaSH function to validate & pretty-print JSON from a file or stdin
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')"
}
@mzipay
mzipay / pyfunctions.bashrc
Created Jul 27, 2016
Some BaSH functions I use for finding/viewing Python standard library modules easily
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)
@mzipay
mzipay / JDBCUtility.java
Created Jun 16, 2015
Simple JDBC console utility
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:
*
@mzipay
mzipay / independent-qall-parallel-promises_1.js
Last active Aug 29, 2015
INDEPENDENT parallel promises with AngularJS $q.all
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
@mzipay
mzipay / jsonp-proxy-request-interceptor.js
Last active Aug 29, 2015
AngularJS HTTP interceptor to work around CORS/JSONP problems
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
@mzipay
mzipay / pseudostruct.py
Created Mar 28, 2015
Fast, small-footprint Python data object template
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.
@mzipay
mzipay / lazy_descriptor.py
Created Mar 28, 2015
Python lazy non-data descriptor
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
You can’t perform that action at this time.