Skip to content

Instantly share code, notes, and snippets.

@vxf
vxf / gist:6366347
Last active December 21, 2015 21:09
retrieve spamassassin scores of a set of mailboxes over time
cat */Maildir/.Junk/*/* | awk '/Delivery-date/ {d = $2" "$3" "$4" "$5} /Spam_score_int/ {print d" "$2}'
@vxf
vxf / apachelogs.sh
Last active December 21, 2015 21:18
# total apache hits by vhost on a log
cat other_vhosts_access.log | awk '{ print $1 }' | sort | uniq -c | sort -nr
# total apache hits by day on a log
cat other_vhosts_access.log | awk '{ print substr($5, 2, 11) }' | uniq -c
# total apache hits by month on every other_vhosts_access.log*
zcat other_vhosts_access.log.*.gz | cat - other_vhosts_access.log other_vhosts_access.log.1 | awk '{ print substr($5, 5, 8) }' | sort | uniq -c
@vxf
vxf / gist:6597760
Last active December 23, 2015 06:59
One liner webservers
awk 'BEGIN { host = "/inet/tcp/8080/0/0"; while (1) { print "HTTP/1.1 200 OK" |& host; print "\r\nHello World" |& host; close(host); } }'
while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html; } | nc -l 8080; done
@vxf
vxf / emilhoes.sh
Last active December 23, 2015 11:59
numeros do euromilhoes
curl -s https://www.jogossantacasa.pt/web/SCRss/rssFeedCartRes | xml2 | awk -F'=' '/Euromilhões/ {c=0;e=1} e&&++c==3{print $2}' | sed -r 's/<\/?b>//g'
@vxf
vxf / ip2geo.py
Created October 21, 2013 01:16
python script to quickly geolocate ip addresses en masse with libgeoip ( cat ips.txt | python ip2geo.py )
import os, GeoIP, fileinput
geo = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
for line in fileinput.input():
try:
print(geo.country_code_by_addr(line.strip()))
except IOError:
break
@vxf
vxf / graphspam.sh
Created October 21, 2013 19:53
prepares the data coming from an apache log to highcharts graph segmented by country http://jsfiddle.net/PXa2Q/9/embedded/result/
topc=( US CN FR SE RU UA CA MD A1 PL )
rm derp.json
for c in "${topc[@]}"
do
echo $c
echo ", {" >> derp.json
echo " name: '$c'," >> derp.json
echo " data: [" >> derp.json
@vxf
vxf / magic.py
Last active August 29, 2015 14:00
python magic
# flaten a list of lists
[y for x in list for y in x]
# transform month to int
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Oct', 'Sep', 'Nov', 'Dec'].index(m) + 1
# generate part of a slug from a name
slug = re.sub('[^\w\d]+', '-', name).strip('-').lower()
# check if it's a sequence (of numbers)
@vxf
vxf / gist:c35be32aa622824e4542
Created May 8, 2014 12:30
Sumarized configuration
egrep -v "^#|^$" file.cfg
@vxf
vxf / gist:fef72cb63eb6368e2b5c
Last active August 29, 2015 14:04
Top 10 hours in the apache log with 500 errors
cat other_vhosts_access.log | awk '$10 == 500 { print $5 $6}' | grep -o -e "../.../....:.." | sort | uniq -c | sort -r -n -k 1,1 | head -n 10
@vxf
vxf / pe.py
Last active April 13, 2016 16:43
""" vxf
Funcoes uteis para estudar Probabilidades e Estatistica
Exemplos de uso:
S(0, 5, lambda i: Bin(n=7, p=(4/6), x=i))
"""
from math import factorial
from functools import reduce