Skip to content

Instantly share code, notes, and snippets.

View mca-gif's full-sized avatar

Matthew Andersen mca-gif

View GitHub Profile
@mca-gif
mca-gif / diff_series
Created March 12, 2015 23:22
Run diff on set of files which possibly changed over time
#!/bin/bash
if [[ $# -lt 2 ]]; then
echo "$0 <file1> <file2> <file3> [file4]"
echo "This script is meant to run on 3 or more files, to see the changes over time."
exit 1
fi
while [[ $# -ge 2 ]]; do
TEST=$(diff -q $1 $2)
@mca-gif
mca-gif / gist:9adfb23f1b97c8313f84
Created February 17, 2015 21:35
Regular Expression : Date in MM/DD/YYYY
<?php
/**
* Match the following formats:
* mm/dd/yyyy
* m/d/yyyy
* mm/d/yyyy
* m/dd/yyyy
*/
$date_regex = "/^(1[0-2]|0{0,1}[1-9])\/(3[0-1]|[0-2]{0,1}[1-9])\/[0-9]{4,4}$/";
@mca-gif
mca-gif / debug.php
Created May 9, 2014 18:45
General purpose Debug logger, with multiple levels and file level disabling
<?php
/**
* Debug provides an API to save to common log file throughout the entire application
* All effort should be made to keep this file as portable to any application as possible
*
* Currently 4 levels of log entries exist: Errors, Warnings, Info, Trace.
* Errors = Conditions which occur and are possibly not recoverable from a user perspective. (i.e. Database will not connect)
* Warnings = Conditions which may not be favorable, but are recoverable. (i.e. Session information not available)
* Info = Any other information which does not indicate an issue to fix. (i.e. Early terminiation of script due to redirect)
* Trace = Position information and programmer fluff. These should be inserted during coding, and removed when done. (i.e. Entered function xyz() )
@mca-gif
mca-gif / SortableSelectable.html
Created March 26, 2014 05:38
Example of using JQuery UI Selectable with Sortable. Supports dragging multiple selected items at once.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/cupertino/jquery-ui.css" />
<style>
#list {
@mca-gif
mca-gif / stathat.php
Created March 25, 2014 18:45
StatHat Class
<?php
// An simplified version of StatHat's own PHP code, wrapped in a class, with a lower timeout threshold.
class StatHat {
private static function ez_key() {
return "Your_StatHat_Key_Here"
//return $_SERVER['STATHAT_KEY'];
}
// StatHat's original code is very much _not_ asynchronous.
// In the event of DNS issues, this will lock your app for TIMEOUT seconds.
@mca-gif
mca-gif / gist:3520207
Created August 29, 2012 23:18
Perl function for parsing a CSV into an array of elements
This is much slower than a RegEx, however it handles commas inside of quoted string values.
sub ParseCSVLine($line) {
chomp($line);
@myChars = split(//, $line);
@myFields = ();
$newField = "";
$inQuote = 0;