Skip to content

Instantly share code, notes, and snippets.

View pjdietz's full-sized avatar

PJ Dietz pjdietz

View GitHub Profile
@pjdietz
pjdietz / randomString.php
Created June 12, 2013 17:51
Create a random string of a given length in PHP
<?php
/**
* Return a random string of a set number of characters.
*
* @param int $length The number of characters for the resulting string
* @param string $set The set of characters to use for the random string
* @param int $repeat Number of times a given character may be repeated in the random string
* @return string
*/
@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 / Virtual Box Host Only Static IP.md
Created June 12, 2013 19:01
VirtualBox Host-Only Adapter with Static IP

VirtualBox Host-Only Static IP

My typical setup for a development box in VirtualBox uses two NICs. The first uses NAT to allow the box to communicate with the outside world through my host computer’s network connection. (NAT is the default, so shouldn't require any setup.) The second is a "host-only" connection that allows my host and guest to interact.

To create a host-only connection in VirtualBox, start by opening the preferences in VirtualBox. Go to the "Network" tab, and addd a Host-only Network. Modify the host-only network, and disable DHCP. Make a note of the IP address. (Feel free to set the IP address as well, if you like.)

Next, assign this host-only adapter to the virtual machine. Select the VM and press "Settings". Go to the "Network" tab, and select "Adpater 2". Enable the adapter, set it to a "Host-only Adapter", and select the adpater you created above.

Temporary

@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>
@pjdietz
pjdietz / mod_deflate
Last active December 23, 2015 06:38
Boilerplate code for adding gzip support with mod_deflate
<VirtualHost *:80>
...
<IfModule mod_deflate.c>
# Automatically compress these mime types
AddOutputFilterByType DEFLATE text/plain text/html text/css text/xml applicaton/json
</IfModule>
</VirtualHost>