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 / 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\"")

TypeScript

class MyLogicContainer {
    constructor(private x: number) { }
    
    add(y: number) {
        return this.x + y;
    }
}
@donatj
donatj / prblame
Created June 21, 2017 14:46
Find the pull request a line of a file was added with
#!/bin/bash
set -e
blame=$(git blame "$1" -L "$2,$2" -p)
open "https://github.com/search?type=Issues&q=${blame:0:40}"
<?php
$content ='
"${folder}\\\\";
if (!isset($data[\'file\'])) { die("This doesn\'t appear to be a language constant file".nl); }
$translation = trim($value,"\' \\t\\n\\r\\0\\x0B");
\'es_ni\'=>\'Spanish (Nicaragua)\',
\'es_pa\'=>\'Spanish (Panama)\',
\'es_pe\'=>\'Spanish (Peru)\',
\'es_pr\'=>\'Spanish (Puerto Rico)\',
@donatj
donatj / lorem.php
Created September 22, 2010 19:55
PHP Flavored Lorem Ipsum Generator
<?php
include('words_example.php'); //Our Datasetm $data
$patSize = 5;
foreach( $data as $word ) {
for( $i = 0; $i <= strlen( $word ) - 2; $i++ ) {
$j = 0;
$str = '';
/**
* Method for taking a string formatted as a css selector and breaking it down into id/classes/attributes/in-line styles
* to use in the creatin of an element. I.E. "#id.class.class2[attribute=value]{ border: 1px solid blue; }"
*
* @ignore this is the original regex i wrote, which was awesome, but broke on some edge cases ...
* "!(\#(.+?)(\.|\[|\{)){1,}!" => ' id="$2" $3', //ID
* "!(\.(.*?)(\[|\{)){1,}!" => ' class="$2" $3', //CLASS
* "!\[(.*?)=([^\[]*)\]!" => ' $1="$2" ', //ATTRS
* "!\{(.*)\}!" => ' style="$1" ', //INLINE STYLE
* "!\.([a-zA-Z_]+[\w\-]*)!" => ' $1', //SPECIFIC CLASSES
@donatj
donatj / matlock.php
Created February 23, 2012 20:46
Slow Query Log Parser
#!/usr/bin/php
<?php
$file = false;
$defaults = array(
'maxQueryTime' => pow(2,32),
'minQueryTime' => 0,
'maxLockTime' => pow(2,32),
'minLockTime' => 0,
'maxRowsSent' => pow(2,32),
'minRowsSent' => 0,
@donatj
donatj / debug.css
Created April 20, 2012 21:38
Pure CSS Debuggery
*[class]:before {
position: absolute;
background: rgba(10,10,10,.6);
padding: 10px;
border-radius: 4px;
color: white;
font-size: 10px;
display: block;
content: "[" attr(class) "] " ;
}
@donatj
donatj / 256color.php
Created April 4, 2013 20:17
Nearest Terminal Color Calculator
<?php
$CLUT = array(
'00' => array( 0, 0, 0 ), '01' => array( 128, 0, 0 ),
'02' => array( 0, 128, 0 ), '03' => array( 128, 128, 0 ),
'04' => array( 0, 0, 128 ), '05' => array( 128, 0, 128 ),
'06' => array( 0, 128, 128 ), '07' => array( 192, 192, 192 ),
'08' => array( 128, 128, 128 ), '09' => array( 255, 0, 0 ),
'10' => array( 0, 255, 0 ), '11' => array( 255, 255, 0 ),
'12' => array( 0, 0, 255 ), '13' => array( 255, 0, 255 ),
@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 ) {