Skip to content

Instantly share code, notes, and snippets.

View pjdietz's full-sized avatar

PJ Dietz pjdietz

View GitHub Profile
@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 / 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
@pjdietz
pjdietz / stringToBool.php
Created June 12, 2013 17:53
Interpret a human-readable string as a boolean in PHP
<?php
/**
* Convert a human-readable string to a boolean.
*
* Case insensitively treats true, t, yes, y, and 1 as true.
* Anything else is false.
*
* @param string $str
* @return bool
@pjdietz
pjdietz / Ubuntu 13.04 Setup.md
Created June 20, 2013 13:50
Ubuntu 13.04 Setup Notes

Ubunutu Setup

I put this little guide together as I installed Ubuntu 13.04.

Installing

  • Apache
  • MySQL
  • PHP 5.4
    • PHP-FPM
@pjdietz
pjdietz / normalize_line_endings.py
Created August 4, 2013 15:41
Normalize Line Endings
def normalize_line_endings(string, eol):
"""Return a string with consistent line endings."""
string = string.replace("\r\n", "\n").replace("\r", "\n")
if eol != "\n":
string = string.replace("\n", eol)
return string
@pjdietz
pjdietz / OverrideableSettings.py
Created August 4, 2013 19:56
Class for making overridable settings in Sublime Text
class OverrideableSettings():
"""
Class for adding a layer of overrides on top of a Settings object
The class is read-only. If a dictionary-like _overrides member is present,
the get() method will look there first for a setting before reading from
the _settings member.
"""
def __init__(self, settings=None, overrides=None):
@pjdietz
pjdietz / fencedCodeBlocksToHtml.php
Last active December 21, 2015 22:09
Convert GFM-style codeblocks to HTML for use with SyntaxHighlighter (http://alexgorbatchev.com/SyntaxHighlighter/)
<?php
/**
* Convert GFM-style code blocks to HTML for use with SyntaxHighlighter
*
* @param string $text
* @return string
*/
function fencedCodeBlocksToHtml($text)
{
@pjdietz
pjdietz / autoload.php
Created September 11, 2013 19:21
PSR Autoloader
<?php
/**
* Autoload function adapted from from PSR-0 standard.
* https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md#splclassloader-implementation
*/
function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
@pjdietz
pjdietz / redirect.conf
Created September 11, 2013 19:46
Redirect with a simple Apache virtual host. No re-writing required.
<VirtualHost *:80>
ServerName bad-domain.com
ServerAlias www.bad-domain.com
Redirect / http://www.good-domain.com
</VirtualHost>