Skip to content

Instantly share code, notes, and snippets.

Avatar
Caffeinating

Jesse Donat donatj

Caffeinating
View GitHub Profile
@donatj
donatj / subtitles.php
Last active Jul 10, 2020
Crappy .srt helper
View subtitles.php
#!/usr/bin/env php
<?php
date_default_timezone_set('UTC');
$stderr = fopen('php://stderr', 'wb');
$shift = 0.0;
switch( $argv[1] ?? '' ) {
case 'shift':
@donatj
donatj / get-dependencies.sh
Created Apr 14, 2020
Recursively get every dependency and version from package-lock.json
View get-dependencies.sh
cat package-lock.json | jq -r '.. | select(.>={}) | .dependencies | select(. != null) | to_entries[] | .key + ": " + .value.version' | sort | uniq
@donatj
donatj / ColorCLI.php
Created Oct 26, 2011
Simple CLI color class
View ColorCLI.php
<?php
class ColorCLI {
static $foreground_colors = array(
'bold' => '1', 'dim' => '2',
'black' => '0;30', 'dark_gray' => '1;30',
'blue' => '0;34', 'light_blue' => '1;34',
'green' => '0;32', 'light_green' => '1;32',
'cyan' => '0;36', 'light_cyan' => '1;36',
@donatj
donatj / ascii.php
Created Nov 9, 2011
Damn Simple PHP Ascii Art Generator
View ascii.php
#!/usr/bin/php -q
<?php
if(isset($argv[1]) && strlen($argv[1])) {
$file = $argv[1];
}else{
echo 'Please Specify a File';
exit(1);
}
@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\"")
View examples.md

TypeScript

class MyLogicContainer {
    constructor(private x: number) { }
    
    add(y: number) {
        return this.x + y;
    }
}
@donatj
donatj / prblame
Created Jun 21, 2017
Find the pull request a line of a file was added with
View prblame
#!/bin/bash
set -e
blame=$(git blame "$1" -L "$2,$2" -p)
open "https://github.com/search?type=Issues&q=${blame:0:40}"
View preg_replace-bug.php
<?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 Sep 22, 2010
PHP Flavored Lorem Ipsum Generator
View lorem.php
<?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 = '';
View selector_string2array
/**
* 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
You can’t perform that action at this time.