Skip to content

Instantly share code, notes, and snippets.

View Andrewpk's full-sized avatar
🐶
wat

Andrew Kehrig Andrewpk

🐶
wat
  • wat
  • Royal Oak, Michigan
View GitHub Profile
@Andrewpk
Andrewpk / addnvpair.xsl.diff
Created July 30, 2012 20:43
addnvpair.xsl diff - what IBM gives you, and what you probably want.
diff addnvpair.xsl.bak addnvpair.xsl
19c19,26
< <xsl:value-of select="normalize-space($value)"/>
---
> <xsl:choose>
> <xsl:when test="@name = 'Identifier'">
> <xsl:value-of select="$value"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="normalize-space($value)"/>
@Andrewpk
Andrewpk / codeLOLpt1.php
Last active December 15, 2015 05:19
codeLOLpt1. This is funny because in order to adequately catch errors of this function, you either need to register a new error handler and check within your handler, or parse $php_errormsg. Simply checking if unserialize returned false is not adequate, since false is an acceptable value to be serialized. IMO: unserialize should probably throw a…
<?php
$origErrorTrackVal = ini_set('track_errors',1);
$oldReportingLevel = error_reporting(E_ALL); //least reporting necessary is E_NOTICE
$mixedUnserializedVal = unserialize(($someArr['someIndex']));
/**
* This next conditional is fun. At this point $mixedUnserializedVal can legally be any value except "unset"
* You still have to check the error messages though :-/
*/
if(isset($mixedUnserializedVal) && preg_match('/Undefined\sindex:\ssomeIndex/', $php_errormsg) === 0) {
//do work
@Andrewpk
Andrewpk / iSeries_DB2 - FindForeignKeys.sql
Last active December 16, 2015 23:19
ridiculous query to grab foreign keys for a given table name and/or schema name
SELECT
child.CONSTRAINT_NAME As constraint_name,
coninfo.CONSTRAINT_TYPE as constraint_type,
parent.TABLE_NAME As parent_table_name,
parent.COLUMN_NAME As parent_column_name,
child.TABLE_NAME As child_table_name,
child.COLUMN_NAME As child_column_name,
child.TABLE_SCHEMA As child_table_schema
FROM
QSYS2.SYSKEYCST child
#!/usr/bin/env ruby
#
# This script can be used to check the in-store availability of the iPhone 5S.
# By default, it searches for all AT&T models. You can change this by editing
# the MY_DEVICES array below. While the Apple API supports searching for
# multiple devices at once, there is a limit.
#
# Once you have properly configured the MY_DEVICES array, you can run this script
# from the terminal. It takes a single parameter, which should be the zip code you
# wish to use for your search.
@Andrewpk
Andrewpk / Gruntfile.js
Last active December 25, 2015 17:39
gruntfile with some modifications to run PHP and enable livereload with the grunt-contrib-watch component and lots of cruft. Originally based off the gruntfile included with generator-webapp.
// Generated on 2013-10-16 using generator-webapp 0.4.3
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
@Andrewpk
Andrewpk / Time Machine SMB mount via Automator
Last active December 27, 2015 21:48
Create a new automator application that has a single action of 'Run Shell Script' and add this as the script, replacing 'MOUNTNAME' with what you want the network share mounted as, 'USERNAME' and 'PASSWORD' respectively (if you have neither set on your SMB share [seriously?] remove from 'USERNAME' to '@' from that line), 'HOST/PATH/TO/TIMEMACHIN…
mkdir /Volumes/MOUNTNAME; mount_smbfs //USERNAME:PASSWORD@HOST/PATH/TO/TIMEMACHINE/SPARSEBUNDLE /Volumes/MOUNTNAME; /usr/bin/hdiutil attach /Volumes/MOUNTNAME/YOURTIMEMACHINE.sparsebundle;
@Andrewpk
Andrewpk / OSX-junos_pulse_listenToMe.sh
Last active April 16, 2022 03:01
wtf juniper. Anyone else find it irritating that junos pulse services and pulse tray must always running in OS X regardless of whether or not you're currently connected? Yeah, me too. I added the following as aliases to my shell to fix this problem. Be sure to change your /Library/LaunchAgents/net.juniper.pulsetray.plist file to reflect the `Kee…
#################################################################################
# start and stop the vpn from the command line from now on with these two commands
# or rename the aliases as you see fit.
#################################################################################
alias startvpn="sudo launchctl load -w /Library/LaunchDaemons/net.juniper.AccessService.plist; open -a '/Applications/Junos Pulse.app/Contents/Plugins/JamUI/PulseTray.app/Contents/MacOS/PulseTray'"
alias quitvpn="osascript -e 'tell application \"PulseTray.app\" to quit';sudo launchctl unload -w /Library/LaunchDaemons/net.juniper.AccessService.plist"
@Andrewpk
Andrewpk / autoload.php
Last active August 29, 2015 14:00
Simple php autoloader. Checks for constant 'CLASS_DIR' that specifies base directory for classes, otherwise will simply look in PSR-0 style directory structure in current directory.
<?php
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// From all I can find on it - PSR states class methods must have opening brace on new line - not plain ol' functions //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function autoload($className) {
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
@Andrewpk
Andrewpk / Template.php
Last active January 8, 2017 04:46
Simple PHP templates. Remember when PHP was a hypertext preprocessor? You don't need twig, mustache, smarty, etc., to do simple templating.
<?php
namespace AKUtils;
/**
* A simple template class for PHP. Allows you to create templates in pure PHP.
* There are many template systems like it, but this one is simple.
*/
class Template
{
private $_templateDir="";
@Andrewpk
Andrewpk / Monolog\Handler\PDOHandler.php
Last active August 29, 2015 14:03
A PDO monolog handler implementation. Almost done (it needs tests). It also works with Postgres' json data type.
<?php
namespace AK\Monolog\Handler;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;
use Monolog\Formatter\JsonFormatter;
class PDOHandler extends AbstractProcessingHandler
{