Skip to content

Instantly share code, notes, and snippets.

View hansifer's full-sized avatar

Hans Meyer hansifer

View GitHub Profile
@hansifer
hansifer / .bash_functions
Last active June 27, 2018 15:04
searchable bash command history with results selection
function chop-first-column { awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}' ; }
function strip-colors { sed "s/\x1B\[\([0-9]\{1,2\}\(;[0-9]\{1,2\}\)\?\)\?[mGK]//g" ; }
function h {
local cyan='\e[0;36m'
local cyan2='\e[1;36m'
local NC='\e[0m' # No Color
if [ $# -gt 0 ]; then
REGEXP="$1"
@hansifer
hansifer / lib-inject.js
Last active August 16, 2016 02:25
Manually inject a JS lib into a web page with load status feedback, either via devtools or a bookmarklet. Handy use case: facilitate devtools-based ad hoc scrapes with jQuery.
// N: lib name (eg, 'jQuery', 'Lodash')
// P: lib window property (eg, 'jQuery', '_')
// U: lib URL (eg, '//code.jquery.com/jquery-3.1.0.min.js', '//cdn.jsdelivr.net/lodash/4.15.0/lodash.min.js')
// for bookmarklet, prepend with "javascript:"
/*javascript:*/((w,d,e,N,P,U)=>{N='jQuery';P='jQuery';U='//code.jquery.com/jquery-3.1.0.min.js';if(w[P]){m(N+' already loaded','#c8af00')}else{m('Waiting on '+N+' load...');(e=d.createElement('script')).src=U;w._llt_script=w.setTimeout(()=>{m(N+' load failed','#d80e0e');delete w._llt_script},2e3);e.onload=()=>{w.clearTimeout(w._llt_script);delete w._llt_script;if(w[P]){m(N+' loaded','#117e61')}else{m(N+' load failed','#d80e0e')}};d.getElementsByTagName('head')[0].appendChild(e)}function m(t,c,i,e,s){w.clearTimeout(w._llt_status);if(!(e=d.getElementById(i='_ll_load_status'))){(e=d.createElement('div')).id=i;(s=e.style).position='fixed';s.right=s.bottom='5px';s.zIndex='2147483647';s.padding='20px 30px';s.opacity='0.9';s.color='#fff';s.fontSize='20px';(d.body||d.documentE
@hansifer
hansifer / URL regex for JS
Created June 24, 2015 01:19
JavaScript port of URL regex from http://stackoverflow.com/a/190405/384062, including a bug fix and some performance refactoring
/^[a-z](?:[-a-z0-9\+\.])*:(?:\/\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\._~!\$&'\(\)\*\+,;=:\xA0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[\uD800-\uD83E\uD840-\uD87E\uD880-\uD8BE\uD8C0-\uD8FE\uD900-\uD93E\uD940-\uD97E\uD980-\uD9BE\uD9C0-\uD9FE\uDA00-\uDA3E\uDA40-\uDA7E\uDA80-\uDABE\uDAC0-\uDAFE\uDB00-\uDB3E\uDB44-\uDB7E][\uDC00-\uDFFF]|[\uD83F\uD87F\uD8BF\uD8FF\uD93F\uD97F\uD9BF\uD9FF\uDA3F\uDA7F\uDABF\uDAFF\uDB3F\uDB7F][\uDC00-\uDFFD])*@)?(?:\[(?:(?:(?:[0-9a-f]{1,4}:){6}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|::(?:[0-9a-f]{1,4}:){5}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:[0-9a-f]{1,4}:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}(?:[