Skip to content

Instantly share code, notes, and snippets.

View pjdietz's full-sized avatar

PJ Dietz pjdietz

View GitHub Profile
@pjdietz
pjdietz / AutomaticProperties.php
Last active December 11, 2015 15:39
Simple implementation of magic accessor methods (__get, __set, __isset, __unset) for PHP classes.
<?php
/*
* Use these methods to create automatic properties. When a property would be accessed,
* PHP will look for a function prefixed with get, set, isset, or unset followed by
* the property name with the first name capitalized. For example, the $this->name
* would be accessed as getName(), setName(), issetName(), and unsetName().
*/
/**
@pjdietz
pjdietz / stringFromTemplate.php
Last active December 11, 2015 23:08
Merge an associative array into a string template.
<?php
/**
* Merge an associative array into a string template.
*
* @param string $template
* @param array $mergeFields
* @return string
*/
function stringFromTemplate($template, $mergeFields)
@pjdietz
pjdietz / clean-table.css
Last active December 12, 2015 05:48
Styles for tables with minimal furniture.
table.clean {
margin-top: 20px;
border-collapse: collapse;
}
table.clean caption {
font-weight: bold;
font-size: 14px;
line-height: 18px;
margin-bottom: 10px;
@pjdietz
pjdietz / empty.html
Created March 31, 2013 17:40
HTML5 empty template
<!DOCTYPE html>
<html>
<head>
<title>Hello, World!</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
@pjdietz
pjdietz / compare.php
Last active June 13, 2018 11:52
Construct a PHP comparison function for use in usort() given an array of comparion functions.
<?php
/**
* Given an ordered array of comparison functions, return one function that
* starts with the first and uses the subsequent functions in order in the
* event of equal items.
*
* @param $sortFnArr
* @param int $index
* @return callable
@pjdietz
pjdietz / RequestHeaders.php
Last active December 15, 2015 20:29
Static class to facilitate looking up request headers. The class allows you to look up request headers case insensitively.
<?php
/**
* Class RequestHeaders
*
* Static class to facilitate looking up request headers.
*/
class RequestHeaders
{
/**
@pjdietz
pjdietz / DelayedRunOnUIThread.java
Created April 30, 2013 13:54
Snippet to show how to wait, then execute code on the UI thread. The example shown is part of an Activity.
// Create a new thread inside your Actvity.
Thread thread = new Thread() {
@Override
public void run() {
// Block this thread for 2 seconds.
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
@pjdietz
pjdietz / distance.java
Created May 8, 2013 13:38
Calculate distance between two points.
/** Return the distance between two points */
public static double distance(float x1, float y1, float x2, float y2) {
return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
}
@pjdietz
pjdietz / Android Multiple Density Export.jsx
Created May 14, 2013 20:11
Photoshop JavaScript to automate exporting Android resources at multiple densities using the 3:4:6:8:12 scaling ratio.
/*global alert, app, prompt, ExportOptionsSaveForWeb, ExportType, File, Folder, ResampleMethod, SaveDocumentType, SaveOptions */
///////////////////////////////////////////////////////////////////////////////
// Android Multiple Density Export.jsx
//
// Photoshop JavaScript to automate exporting Android resources at multiple
// densities using the 3:4:6:8:12 scaling ratio.
//
//
// Installation:
@pjdietz
pjdietz / Stupid Nix Trix.txt
Created June 11, 2013 19:29
Stupid Nix Trix A list of short Linux and Mac CLI commands that may come in handy. Adding to this as I find new things that I'll want to keep handy.
# Find External IP Address
curl icanhazip.com
# Install Composer
curl -sS https://getcomposer.org/installer | php