Skip to content

Instantly share code, notes, and snippets.

@metalrufflez
metalrufflez / count_conns.sh
Last active August 29, 2015 14:00
Count all TCP connections for a given port
function count_conns() {
if [[ $# -eq 0 ]]; then
echo "Usage: $FUNCNAME <port>"
return
fi
ss -t -n "src :$1" | awk '{print $5}' | sed 1d | sort | cut -d: -f1 | uniq -c | sort -k1,1nr -t. -k2,2n -k3,3n -k4,4n -k5,5n
}
@metalrufflez
metalrufflez / unblock-us_updater
Created December 16, 2013 12:57
Updates your current IP on Unblock-US
username=""
password=""
curl -k -q https://api.unblock-us.com/login?$username:$password

Pereira

O Pereira (Homo pereirensis) é uma criatura de hábitos diurnos, muito comum nas regiões sul-sudeste brasileiras.

Caracterização

Pereiras se caracterizam por suas vestimentas: uma camisa social (preferencialmente branca ou azul-clara) desconfortavelmente enfiada em sua calça de sarja (frequentemente cáqui), "sapa-tênis" marrom e, por muitas vezes, uma gravata (cujo custo raramente ultrapassa 20 reais). Pelas suas vestimentas, nota-se que os Pereiras tem uma fraca percepção de cores, pois eles não as sabem combinar; especula-se que os Pereiras são daltonicos.

Habitat

@metalrufflez
metalrufflez / recent_ip.sh
Last active December 21, 2015 14:29
Count the number of ip requests on an nginx logfile during one minuteYou can use regex filtering for specific requests.
function recent_ip() {
helper_file="/tmp/ips"
log_file=$1
pattern=$2
if [[ $# -eq 0 ]]; then
echo "Usage: $FUNCNAME <log file> [pattern]"
return
fi
@metalrufflez
metalrufflez / count_ip.sh
Last active December 21, 2015 14:29
Count the number of ip requests in a nginx log.By default it greps an entire log, or you can use regex filtering for specific requests or timeframe
function count_ip() {
log_file=$1
pattern=$2
helper_file="/tmp/helperip"
if [[ $# -eq 0 ]]; then
echo "Usage: $FUNCNAME <log file> [pattern]"
return
fi
@metalrufflez
metalrufflez / tuxedo.sh
Last active December 18, 2015 04:39
A script that will grep your ~/.ssh/config for a certain expression, then creates a tmux session with a ssh session for each host matched. It's not pretty, there's lots of room for improvement, but it does the job.
#!/bin/bash
#
# tuxedo
# Creates a tmux session with hosts grepped from your ~/.ssh/config
#
# Created by: Caio Correa <caio@batatas.org>
# Named by: @xfer
# Last Updated: 2013/06/06
#
@metalrufflez
metalrufflez / gist:5555216
Last active December 17, 2015 05:08
highlight nginx config lines that you forgot to add a semicolon to the end
au BufRead,BufNewFile /etc/nginx/conf.d/* set ft=nginx
autocmd FileType nginx highlight missingsemicolon ctermbg=red | match missingsemicolon /^[^#;{}]\+$/
@metalrufflez
metalrufflez / wallpaper_organizer.sh
Last active October 11, 2015 17:38
Organize wallpapers according to aspect ratio
#!/bin/bash
# Set all stderr output to /dev/null
exec 2> /dev/null
WALLPAPERDIR="$HOME/Dropbox/Photos/Wallpapers"
while read file; do
WIDTH=$(sips -g pixelWidth "$file" | tail -1 | cut -d" " -f4)
HEIGHT=$(sips -g pixelHeight "$file" | tail -1 | cut -d" " -f4)
@metalrufflez
metalrufflez / chmodnoob.sh
Created October 8, 2012 19:04
Chmod protection
#!/bin/bash
if [ "$#" -eq 0 ]; then
chmod
exit 1
fi
if [ "$1" -eq "777" ]; then
exit 1
else
@metalrufflez
metalrufflez / monitordirect.sh
Created October 2, 2012 21:30
Script to parse and mail DirectLog tracking updates
#!/bin/bash
# This script requirest 2 parameters
# $1 = Tracking Number
# $2 = Your mail address
# Didn't do a if check because I'm fat and lazy, deal with it
URL="http://www.directlog.com.br/track_individual/index.asp?flagOC=&fase=0&tipo=0&numtracking=$1"
BULK="$(curl -s "$URL" | egrep '<b>.*<br></b><br>' | tail -1 | sed -r "s/<(br|\/?b)>//g")"
CTLFILE=/tmp/ctldirect