Skip to content

Instantly share code, notes, and snippets.

View donatj's full-sized avatar
🥽
Getting back to business

Jesse Donat donatj

🥽
Getting back to business
View GitHub Profile
@donatj
donatj / fast-patch.php
Created April 1, 2015 17:47
Fast Patch Redux
#!/usr/bin/env php
<?php
if( count($argv) < 3 ) {
echo "Requires at least two arguments\n";
die(1);
}
$dir = realpath($argv[1]);
if( !is_dir($dir) ) {
@donatj
donatj / http.go
Last active September 12, 2018 19:34
Golang Basic Auth
package utils
import (
"net/http"
)
func BasicAuth(handler http.Handler, username, password string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if u, p, ok := r.BasicAuth(); !ok || !(u == username && p == password) {
w.Header().Set("WWW-Authenticate", "Basic realm=\"ZorkIrc\"")
@donatj
donatj / branch-be-gone.php
Last active December 3, 2015 19:12
Gone Branch Be Gone
#!/usr/bin/env php
<?php
`git fetch -p --all`;
$branches = `git branch -vv`;
preg_match_all('%^\ +(?P<branch>[\w/=\-.#]+)\ +(?P<hash>[0-9a-fA-F]+)\ \[[\w/=\-.#]+:\sgone\]%smx', $branches, $result, PREG_PATTERN_ORDER);
foreach( $result['branch'] as $index => $branch ) {
$output = [ ];
@donatj
donatj / QuerySampler.php
Created December 15, 2014 23:37
Dead Simple Query Sampler
<?php
$timeout = 1800; //seconds
$sleep = 100000; //microseconds
$start = time();
$link = mysql_connect('[[HOST]]', '[[USERNAME]]', '[[PASSWORD]]');
if( !$link ) {
die('Could not connect: ' . mysql_error());
}
@donatj
donatj / ordmaker.php
Created September 25, 2014 00:34
Convert String to Escaped Hexadecimal Notation
#! /usr/bin/env php
<?php
$data = $argv[1];
$split = str_split($data);
foreach($split as $ord) {
echo "\\x" . dechex(ord($ord));
}
@donatj
donatj / arrays_are_similar.php
Created July 22, 2014 22:16
Similar Array Checker - Regardless of Key Order
<?php
function arrays_are_similar( $aSide, $bSide ) {
$keys = array_unique(array_merge(
array_keys($aSide),
array_keys($bSide)
));
foreach( $keys as $key ) {
@donatj
donatj / _ScaledSpriteMap.scss
Last active August 29, 2015 14:02
SCSS Scaled Sprite Map
@mixin scaled-sprite-background($name, $scale, $spritemap) {
background: $spritemap;
$spritePath: sprite-path($spritemap);
@include background-size(image-width($spritePath) * $scale);
$position: sprite-position($spritemap, $name);
background-position: (nth($position, 1) * $scale) (nth($position, 2) * $scale);
height: image-height(sprite-file($spritemap, $name)) * $scale;
@donatj
donatj / getinfo.sh
Created September 20, 2013 16:52
Displays the OS X Finder "Get Info" dialog.
#!/bin/sh
# Requires a POSIX-ish shell.
#
# Originally From: http://hayne.net/MacDev/Bash/show_getinfo
#
# show_getinfo
# This script opens the Finder's "Get Info" window
# for the file or folder specified as a command-line argument.
@donatj
donatj / index.php
Last active December 22, 2015 18:19
Turn the Penny Arcade DLC page into a *real* podcast.
<?php
date_default_timezone_set('America/Chicago');
$subject = file_get_contents("http://penny-arcade.com/dlc");
preg_match_all('%<li[ >].*?<h4>(?P<title>.*?)</h4>.*?class="paDLCLink"[^>]href="(?P<file>.*?)".*?</li%si', $subject, $result, PREG_SET_ORDER);
header('Content-Type: application/rss+xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
@donatj
donatj / a_gearnan.log
Last active December 18, 2015 18:29
Gearman Compile Issue
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by gearmand configure 1.1.7, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ ./configure --prefix=/usr/local/Cellar/gearman/1.1.7 --with-mysql
## --------- ##
## Platform. ##