Skip to content

Instantly share code, notes, and snippets.

View ao's full-sized avatar
😶‍🌫️

Andrew O ao

😶‍🌫️
View GitHub Profile
@ao
ao / gist:9ccacaf93b16482120790d05be3f626c
Created September 21, 2016 09:57
Python Zen - CLI output
python -c "import sys, random; stdout = sys.stdout; sys.stdout = type('BlackHole', (), {'write': (lambda self, string: '')})(); import this; sys.stdout = stdout; print random.choice(''.join([this.d.get(i, i) for i in this.s]).splitlines()[2:]);"
@ao
ao / gist:5d064a0f58e0c1eb8baae4385d62d54c
Created September 21, 2016 09:50
macosx commandline fun
fortune -s computers | cowsay -f dragon | lolcat
@ao
ao / gist:86f7f667bc968fbd59b9
Created February 5, 2016 14:36
Access.log. sort by occurrence
cat access.log | awk -F\" '{print $6}' | sort | uniq -c | sort -n
@ao
ao / gist:0dbc442579a8de514ddf
Created January 15, 2016 14:28
Commandline Speedtest - Bash/SH
#!/bin/bash
cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo )
cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo )
freq=$( awk -F: ' /cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo )
tram=$( free -m | awk 'NR==2 {print $2}' )
swap=$( free -m | awk 'NR==4 {print $2}' )
up=$(uptime|awk '{ $1=$2=$(NF-6)=$(NF-5)=$(NF-4)=$(NF-3)=$(NF-2)=$(NF-1)=$NF=""; print }')
echo "CPU model : $cname"
@ao
ao / gist:5c74cab3c7e40fad69ae
Created October 16, 2015 11:01
most common commandline commands
history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -r
@ao
ao / gist:b41d430861cf427cc749
Created January 19, 2015 12:55
ubuntu - check syntax of mysql my.cnf
/usr/sbin/mysqld <options> --help --verbose
@ao
ao / gist:084dba82635f04d67ac1
Created January 15, 2015 09:00
Test nginx configuration
/usr/sbin/nginx -t
@ao
ao / gist:b9c6a03782cc17b36554
Created November 24, 2014 09:46
Javascript $_GET variables
function $_GET(q, s) {
s = s ? s : window.location.search;
var re = new RegExp('&' + q + '(?:=([^&]*))?(?=&|$)', 'i');
return (s = s.replace(/^\?/, '&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined;
}
@ao
ao / gist:21eaf78b47e28ab65363
Created October 17, 2014 15:11
ChartJS - hide x-labels
If you want to hide the labels when there are too many, you can use the following extension. It just pushes the x-labels off the canvas so they are painted but not visible.
Chart.types.Line.extend({
name : "AltLine",
initialize : function(data) {
Chart.types.Line.prototype.initialize.apply(this, arguments);
this.scale.draw = function() {
if (this.display && (this.xLabelRotation > 90)) {
this.endPoint = this.height - 5;
function commafy( nStr ) {
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while( rgx.test( x1 )) {
x1 = x1.replace( rgx, '$1' + ',' + '$2');
}
return x1 + x2;