Skip to content

Instantly share code, notes, and snippets.

View mrmanc's full-sized avatar

Mark Crossfield mrmanc

View GitHub Profile
@mrmanc
mrmanc / gist:2892153
Created June 7, 2012 22:43
Pig On Wheels
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsSAAALEgHS3X78AAAACXZwQWcAAAAwAAAAMADO7oxXAAAObklEQVRo3r1aa2wcVZb+zq1XVz9sx3bHr3ZiYidxnIkDIZBkwSQQCIlmmCEwCAmkFdrdH/BjJdjfaFestBLSSmj4sT+Y3dXsrjQz2mgYBCKgmQDZyImzyGuCH0lMguMMcdyO3R33w13dXY979kdVOx0nTmwec6VSucvVdc93vu/cc86tJmZ+Cn/mwYD0TwABwj99u6H+8LYC8A0GAHgAyidPbgpNTj6Ajo5h7Np1nnRdBiBWDeSHAFAxGlJK9jwvRkQtRBQjIteyrLT88sunwrncYzwz82NMTByXu3Ydpe7uJBFhtSDoe5IQA2AGmJmJy2XNLpUiwjT/QlXVx4QQCQAGACmZc3J83FA//7wGMzMAEcMwpri9/UPq6zuBpqb8amT1XQEwA9IrlXROJpswN9cl8vlOx/NasG3bWqO5uZ2ItNtSlMkAn3wCXLwIIgITuYhExri7+z166KFhmKZLK5DVSgFwEHiVoIMEpJtOxzAxsV1cv/6wKJe3EPMaz/MUd9MmGFu3goS480Pn54EPPwSmp/0ZAECIAurrT/L9939A27f/KXjGsg9aCQD2CgWVjh/fQ0J42L//fx3XVeTZszvVubmfKI7TDWadADAzrEgERl8f1HD47l4BgEuXgFOngOvXgVIJxOxf17Rr3Nr6MT388Cdob59fTlZ3C2KWgHQ//XSXPj7+tyBybGaTNK1bt6x9gjnku8F/rud5kPE4lCXGMzOklBBCIAhUBGyCm5qApibANIFMxmfF80CO04RvvvlLvPfebu7qeg99ff9HsZi9FMRdAdjnzzepExM/JylNBkLa5OTL1Nqqk2/NTTe7zKCamptmmJ+fx/vvv4+xsTG0trbimWeeQUdHx40bDA
@mrmanc
mrmanc / label-fix-regexs
Created June 14, 2012 22:07
Regexs to fix forms disconnected labels
I've been irritated with the hundreds of label tags in our sites with no 'for' attribute. This leads to forms where clicking the label does not put focus into that field. So I've written these operations to bulk fix this problem.
There are two steps, because if you've not used 'for' attributes, you probably don't have 'id' attributes on your form fields. So I've extracted the 'name' attribute from the form field and name-spaced it. Caution: if you have more than one form on the page you might end up with two elements with the same 'id' attribute, which would be improper.
So this:
<label>Forename</label>
<input name="forename">
becomes:
<label for="auto-generated-id-forename">Forename</label>
@mrmanc
mrmanc / gist:3048201
Created July 4, 2012 16:34
summary of outbound connections netstat
netstat -n -A inet | grep -v "127\.0\.0\.1" | egrep -v "\w\s*\w\s*\w\s*[0-9.]*:(80|8080)" | awk '/tcp/ {statuses[$6]++; hosts[$5]++} END{for (status in statuses) {print status,statuses[status]}; for (host in hosts) {if(hosts[host] > max_per_host_port) {max_per_host_port = hosts[host]}}; print "max_per_host",max_per_host_port}'
@mrmanc
mrmanc / safe data URI
Created July 31, 2012 10:15
safe data URI
function safeGetDataAttribute(element, dataName){
if (element.dataset){
return element.dataset[dataName];
}
return element.getAttribute('data-' + dataName);
}
@mrmanc
mrmanc / parsesudoers
Last active February 20, 2022 23:27
sudoers parser (awk). This should be the contents of an executable script. Reads from stdin, expands all aliases, and writes to stdout. This parser will not work where you have defined multiple aliases per line.
#!/bin/gawk -f
/Cmnd_Alias/ {
value = substr($0, index($0, "=")+1,length($0))
for (command in commands) gsub(command,commands[command],value)
sub(/^ */,"",value)
commands[$2]=value
print $0
}
@mrmanc
mrmanc / go-bash-secret-sauce
Created November 9, 2012 14:58
Using environment vars in Go bash tasks
<exec command="/bin/bash" args="-c 'commandwhichusesvars'" />
@mrmanc
mrmanc / Find notes in an iOS backup
Last active December 16, 2015 04:49
If, like me, you have deleted a note on your iPhone and want to restore it you can find it by searching the sqlite3 notes databases contained within your iOS backups. Be sure to do this before reconnecting the device, as this would erase the backup. You'll need - to be comfortable using the command line - to be using a mac (although this would w…
find ~/Library/Application\ Support/MobileSync/Backup/ -name ca3bc056d4da0bbf88b5fb3be254f3b7147e639c -exec sqlite3 {} "select zcontent from znotebody where zcontent like '%Music%';" \; | sed -e "s/<div>/\\
/g" -e "s/<[^>]*>//g" "-e s/&nbsp;/ /g"
@mrmanc
mrmanc / excel-notepad-plus-plus-udl
Created May 23, 2013 11:27
A user defined language file to do syntax highlighting in Notepad Plus Plus for Excel functions.
<NotepadPlus>
<UserLang name="Excel" ext="" udlVersion="2.0">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="no" forceLineCommentsAtBOL="no" foldCompact="no" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments" id="0"></Keywords>
<Keywords name="Numbers, additional" id="1"></Keywords>
<Keywords name="Numbers, prefixes" id="2"></Keywords>
@mrmanc
mrmanc / gist:6712805
Created September 26, 2013 11:18
Measure Graphite metrics received by all Carbon cache instances over time
ls /usr/local/graphite/storage/whisper/carbon/agents/*/metricsReceived.wsp | xargs -I {} whisper-dump.py {} | sed -e "s/,//" | awk '$1 ~ /^[0-9]/ && $3 > 0 {day=strftime("%Y-%m-%d", $2); if ($3 > sizes[day]) {sizes[day]=int($3)}} END {for(day in sizes) {print day " " sizes[day]}}' | sort
@mrmanc
mrmanc / ssh host tab complete
Last active January 2, 2016 13:59
This will allow you to tab complete any hostname you've previously ssh'd to.
Taken from http://hints.macworld.com/article.php?story=20080317085050719
Put the below line in your .profile, .bash_profile or .bashrc file (whichever you use).
If you don't know which file to put it in, read this explanation:
http://stackoverflow.com/questions/415403/whats-the-difference-between-bashrc-bash-profile-and-environment#answer-415444
complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ssh