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 / 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 / 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 / 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 / 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 / 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 / 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 / cp-branch
Last active October 20, 2016 18:12
Easily cherry pick one or more commits to a new branch
#!/bin/zsh
set -e
if [ $# -lt 3 ]
then
echo "Not Enough Arguments"
return 1
fi
@donatj
donatj / mblen.php
Last active October 15, 2015 20:58
Gets byte length of characters read from stdin
#!/usr/bin/env php
<?php
mb_internal_encoding('UTF-8');
$string = '';
if( count($argv) > 1 ) {
$string .= implode(' ', array_slice($argv, 1));
} else {
while( $line = fgets(STDIN) ) {
@donatj
donatj / FixITunesPlayedCount.applescript
Created November 11, 2015 21:44
Fixes tracks with a last played but no played count.
tell application "iTunes"
(* this prevents an error on no tracks being found on the set below *)
set played count of first track where played count = 1 to 0
(* sometimes it leaves this if we don't wait *)
delay 1
set played count of every track where played count = 0 and played date ³ (date "Thursday, June 1, 2000 at 12:00:00 AM") to 1
end tell
@donatj
donatj / day7.go
Last active December 17, 2015 18:23
package main
import (
"fmt"
"strconv"
"strings"
)
var input = `bn RSHIFT 2 -> bo
lf RSHIFT 1 -> ly