Skip to content

Instantly share code, notes, and snippets.

Avatar
Caffeinating

Jesse Donat donatj

Caffeinating
View GitHub Profile
@donatj
donatj / ghopen.php
Created Jan 12, 2016
Open current project on Github. OS X only.
View ghopen.php
#!/usr/bin/env php
<?php
$cwd = getcwd();
$dirs = explode(DIRECTORY_SEPARATOR, $cwd);
$opened = [ ];
for( $i = count($dirs); $i >= 1; $i-- ) {
$set = array_slice($dirs, 0, $i);
$path = implode(DIRECTORY_SEPARATOR, $set);
View day7.go
package main
import (
"fmt"
"strconv"
"strings"
)
var input = `bn RSHIFT 2 -> bo
lf RSHIFT 1 -> ly
@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;
}
You can’t perform that action at this time.