Skip to content

Instantly share code, notes, and snippets.

☕️
Caffeinating

Jesse Donat donatj

☕️
Caffeinating
Block or report user

Report or block donatj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@donatj
donatj / FixITunesPlayedCount.applescript
Created Nov 11, 2015
Fixes tracks with a last played but no played count.
View FixITunesPlayedCount.applescript
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 / mblen.php
Last active Oct 15, 2015
Gets byte length of characters read from stdin
View mblen.php
#!/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 / cp-branch
Last active Oct 20, 2016
Easily cherry pick one or more commits to a new branch
View cp-branch
#!/bin/zsh
set -e
if [ $# -lt 3 ]
then
echo "Not Enough Arguments"
return 1
fi
@donatj
donatj / fast-patch.php
Created Apr 1, 2015
Fast Patch Redux
View fast-patch.php
#!/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 Sep 12, 2018
Golang Basic Auth
View http.go
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 Dec 3, 2015
Gone Branch Be Gone
View branch-be-gone.php
#!/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 Dec 15, 2014
Dead Simple Query Sampler
View QuerySampler.php
<?php
$timeout = 1800; //seconds
$sleep = 100000; //microseconds
$start = time();
$link = mysql_connect('[[HOST]]', '[[USERNAME]]', '[[PASSWORD]]');
if( !$link ) {
die('Could not connect: ' . mysql_error());
}
View join2insert.php
#!/usr/bin/env php
<?php
$string = "";
$opt = getopt('r');
while( $line = fgets(STDIN) ) {
$string .= $line;
}
@donatj
donatj / ordmaker.php
Created Sep 25, 2014
Convert String to Escaped Hexadecimal Notation
View ordmaker.php
#! /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 Jul 22, 2014
Similar Array Checker - Regardless of Key Order
View arrays_are_similar.php
<?php
function arrays_are_similar( $aSide, $bSide ) {
$keys = array_unique(array_merge(
array_keys($aSide),
array_keys($bSide)
));
foreach( $keys as $key ) {
You can’t perform that action at this time.