This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# hexdate.sh | |
# Gives the hexadecmial representation of time_t | |
# If the hexadecimal representation of time_t is given as an argument, will print the date that time represented. | |
# | |
# Joel Franusic, 49ff6dcc | |
if [ $# -eq 0 ]; then | |
echo "obase=16;`date +%s`" | bc | tr '[A-Z]' '[a-z]' | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# How to exit if any command in a bash subshell fails. | |
exitIfFailed () | |
{ | |
rv=$?; | |
if [ $rv -ne 0 ]; then | |
exit $rv; | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find all files that you can read in /tmp | |
find /tmp/ -type f -perm -004 | xargs ls -l |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to automatically backup a git repository (via cron for example). | |
REPOSITORY="/path/to/repository/" | |
# Redirect STDIO and STDERR to /dev/null | |
exec 1> /dev/null | |
exec 2> /dev/null | |
cd $REPOSITORY | |
git add . | |
git commit -a -m "Automatic commit - `date`" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Makes test vectors for prolog. | |
use Data::Dumper; | |
use Digest::MD5 qw(md5 md5_hex md5_base64); | |
my @testcases = qw( | |
291546831b9f9975c4b9d80b8a83fa75 | |
b959f348cd1ea2cd4c9845656e87e256 | |
ec696acce6fc9a57bccb4bd070bb3ab0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# Proof of concept for implementing boolean AND and OR logic in Nginx. | |
use strict; | |
my @truth_table = ( | |
['0', '0', '1', '0'], | |
['0', '1', '0', '0'], | |
['0', '1', '1', '0'], | |
['1', '0', '0', '0'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to redirect HTTP to HTTP and HTTPS to HTTPS | |
RewriteEngine On | |
RewriteCond %{SERVER_PORT} 80 | |
RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [R=302,L] | |
RewriteCond %{SERVER_PORT} 443 | |
RewriteRule ^(.*)$ https://www.DOMAIN.com/$1 [R=302,L] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# input: email address in pasteboard. | |
# output: url for gravatar of that email address to pasteboard | |
# (wavatar default if no gravatar exists) | |
md=$(echo -n `pbpaste` | md5); echo "http://gravatar.com/avatar/${md}?d=wavatar" | pbcopy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 'one liner' to parse the pingdom rss feed and generate a list of IP's sutable for use in an nginx configuration file. | |
curl -s https://www.pingdom.com/rss/probe_servers.xml|perl -ne 'next unless$_=~/>(I[^<]+)/;$i=$1;$i=~s/: /"=>"/g;$i=~s/; /","/g;%h=%{eval qq{{"$i"};}};print qq{ $h{IP}/32 "yes"; #$h{Hostname} $h{City}, $h{Country}\n};'|tr \" \' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ip_to_netblock(ip) | |
reverse_ip = ip.split('.').reverse.join('.') | |
lookup = `dig +short #{reverse_ip}.origin.asn.cymru.com TXT` | |
lookup.chomp.gsub('"','').split(' | ')[1] | |
end |