Skip to content

Instantly share code, notes, and snippets.

@waffle2k
waffle2k / yahoo_cidr.pl
Created September 26, 2012 15:11
This little script pulls a list of IPs from the homepage of a Yahoo! product manager, and creates a list of CIDR ranges that cover the mailserver IPs provided
#!/usr/bin/perl
use strict;
use Net::CIDR::Lite;
# pull the IPs from the following
my @lines = `wget -O- http://public.yahoo.com/~vineet/ip.txt 2>/dev/null`;
# Remove the newline from each row
chomp for @lines;
@waffle2k
waffle2k / cachedtime.pl
Created September 19, 2012 20:08
Example of caching a result within a file to be pulled later
#!/usr/bin/perl
use strict;
use Attribute::Handlers;
my $cachettl = 30;
sub write_to_cache {
my ($v) = @_;
open CACHE, '>/tmp/cache';
use Data::Dumper;
@waffle2k
waffle2k / pid_age.pl
Created August 28, 2012 17:08
Age of a process in seconds on the Linux proc system
#!/usr/bin/perl
$pid = shift || die "You must specify a pid\n";
die "Pid $pid does not exist\n" unless -e "/proc/${pid}/";
my $s = `cat /proc/${pid}/stat`;
my @a = split( /\s+/, $s );
my $jiffies = int( $a[22] / 1000 );
@waffle2k
waffle2k / cidr2regex.py
Created April 3, 2012 18:04
Convert CIDR notation to regex
#!/usr/bin/python
''' Not my script, found on the Internet, and rediscovered on my hard drive
'''
import sys
def cidr_to_regex(cidr):
ip, prefix = cidr.split('/')
base = 0
for val in map(int, ip.split('.')):
@waffle2k
waffle2k / perl-decorators.pl
Created March 14, 2012 05:36
An example of creating decorators in Perl
package Profiler::Decorator;
use IO::Socket::INET;
use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep clock_gettime clock_getres clock_nanosleep clock stat );
use Data::Dumper;
# flush after every write
# We call IO::Socket::INET->new() to create the UDP Socket
# and bind with the PeerAddr.
@waffle2k
waffle2k / extract_ip
Created February 27, 2012 15:18
vimrc snipped
" Strip down to just the IP address in the highlighted region
function! ExtractIP()
'<,'>perldo $_ = $1 if /((?:\d+\.){3}\d+)/;
endfun
vmap <silent> <C-i> <Esc>:call ExtractIP()<CR>
function! SortUniq()
'<,'>sort
'<,'>g/^\(.*\)$\n\1$/d
endfun
#!/usr/bin/perl
#use strict;
use Net::DNS::Async;
use NetAddr::IP;
my %map;
my %resultmap;
my $c = new Net::DNS::Async( );
my $debug = 0;
@waffle2k
waffle2k / stripper.c
Created January 27, 2012 17:34
Simple HTML stripper
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
char * stripper_dup( const char * str ){
char * ptr = strdup( str );
char * inptr = (char * )str;
int intag = 0;
char buffer;
char *p = ptr;
#!/usr/bin/perl
while( <> ){
if( /^(.*?),(.*)/ ){
for( my $count = 0; $count < 1000; $count++ ){
printf "%s%.3d,%s\n", $1, $count, $2;
}
}
}
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
class AuthenticationException < StandardError ; end
module RequireAuth
def requireauth ( *args )
args.each do |field|
old_method = instance_method(field)