Skip to content

Instantly share code, notes, and snippets.

View mrmanc's full-sized avatar

Mark Crossfield mrmanc

View GitHub Profile
@mrmanc
mrmanc / gist:b1c9cd4f7a45412c2c71
Created June 6, 2014 14:38
Find corrupt whisper files
find /usr/local/graphite/storage/whisper/ -name "*.wsp" | xargs -I {} whisper-info.py {} 2>&1 | grep "whisper.CorruptWhisperFile:" | sed -e "s/^.*(//" -e "s/).*$//"
@mrmanc
mrmanc / xargs-apostrophe
Created November 24, 2014 15:16
Problem caused by apostrophe’s special meaning in xargs
In response to http://askubuntu.com/questions/80244/how-do-i-sort-by-human-readable-sizes-numerically/552976?noredirect=1#answer-552976
mark:~/dutest $ touch "a'b"
mark:~/dutest $ du -s * | sort -n | cut -f2
a'b
mark:~/dutest $ du -s * | sort -n | cut -f2 | xargs du -sh
xargs: unterminated quote
@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 / whisper-calculator.py
Last active October 6, 2015 15:40 — forked from jjmaestro/whisper-calculator.py
whisper-calculator.py:Calculates the size of the whisper storage for the given retention (in frequency:history format)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def archive_to_bytes(archive):
def to_seconds(s):
SECONDS_IN_A = {
's': 1,
'm': 1 * 60,
'h': 1 * 60 * 60,
@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 / 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 / ImmutableMap.java
Created November 10, 2015 20:05
ImmutableMap with mapOf()
import java.util.Map;
public abstract class ImmutableMap {
private ImmutableMap() {}
public static <K, V> Map<K, V> mapOf(K k1, V v1) {
return com.google.common.collect.ImmutableMap.of(k1, v1);
}
public static <K, V> Map<K, V> mapOf(K k1, V v1, K k2, V v2) {
@mrmanc
mrmanc / sample-jstat-output
Last active December 15, 2015 17:26
Some jstat output from ‘jstat -gc PID 1s’
S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT
271360.0 268800.0 0.0 215492.3 5035520.0 1933309.9 11184640.0 2746005.2 524288.0 126285.0 11511 1654.373 181 185.540 1839.913
271360.0 268800.0 0.0 215492.3 5035520.0 2185976.4 11184640.0 2746005.2 524288.0 126285.0 11511 1654.373 181 185.540 1839.913
271360.0 268800.0 0.0 215492.3 5035520.0 2304618.9 11184640.0 2746005.2 524288.0 126285.0 11511 1654.373 181 185.540 1839.913
271360.0 268800.0 0.0 215492.3 5035520.0 2366035.2 11184640.0 2746005.2 524288.0 126285.0 11511 1654.373 181 185.540 1839.913
271360.0 268800.0 0.0 215492.3 5035520.0 2488908.0 11184640.0 2746005.2 524288.0 126285.0 11511 1654.373 181 185.540 1839.913
271360.0 268800.0 0.0 215492.3 5035520.0 2644544.6 11184640.0 2746005.2 524288.0 126285.0 11511 1654.373 181 185.540 1839.913
271360.0 268800.0 0.0 215492.3 5035520.0 2746552.0 11184640.0 2746005.2 524288.0 126285.0 115