Skip to content

Instantly share code, notes, and snippets.

@waffle2k
waffle2k / gist:866463
Created March 11, 2011 19:51
notify-perl.pl
$handle = sub {
my $ref = shift;
my $sender = $ref->{'user'}->{'id'};
my $sender = $ref->{'user'}->{'screen_name'};
my $text = &descape($ref->{'text'});
`echo "$sender $text" | /home/pblair/bin/twitter-notify >/dev/null 2>&1`;
print &standardtweet( $ref );
return 1;
};
#!/bin/bash
read line
SENDER=$(echo $line | awk '{print $1}')
if [ ! -f "/tmp/twit-profile/${SENDER}.jpg" ]; then
URL="http://twitter.com/users/${SENDER}.xml"
PROFILE_URL=$(wget -O - $URL 2>/dev/null | grep profile_image_url | perl -lane 'print $1 if /profile_image_url\>(\S+?)\<\/profile_image_url/' -)
echo "Profile url: $PROFILE_URL"
#!/usr/bin/perl -w
use strict;
use Date::Parse;
use Getopt::Long;
my $goback = "15m";
my $initial = undef;
# Options
my ( $reverse, $length, $searchterm, $help ) = ( 0, $goback, '.*', 0 );
#!/usr/bin/perl
use strict;
use lib ( "." );
use Policy::Memcache;
use Data::Dumper;
my $mc = Policy::Memcache->new;
my $ip = shift;
my $cmd = shift || 'get';
chomp( $ip );
@waffle2k
waffle2k / gist:956029
Created May 4, 2011 21:02
vimrc extract IP
" Strip down to just the IP address in the highlighted region
function! ExtractIP()
'<,'>perldo $_ = $1 if /((?:\d+\.){3}\d+)/;
endfun
vmap :call ExtractIP()
function! SortUniq()
'<,'>sort
'<,'>g/^\(.*\)$\n\1$/d
endfun
@waffle2k
waffle2k / smtp.pl
Created May 17, 2011 00:21
Colourized SMTP tester script
#!/usr/bin/perl
use strict;
use IO::Socket;
use Term::ANSIColor;
sub get_file( $ ){
my ($filename) = @_;
open FD, "<$filename" || die( "Cannot open $filename: $!\n" );
my $text = do { local $/; <FD>; };
@waffle2k
waffle2k / epol.cc
Created May 18, 2011 16:55
Threaded + epoll server
// Compile with: $ g++ epoll.cc -o epoll1 -lboost_thread
#include <iostream>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
@waffle2k
waffle2k / stats.pl
Created May 18, 2011 17:25
Run some simple stats on a bunch of integers
[prod.b]pblair@b009:/mail/log/log01/smtprelay/20110518$ cat ~/stats.pl
#!/usr/bin/perl
use strict;
use warnings;
use lib("/home/pblair/lib");
use Statistics::Descriptive;
my $stat = Statistics::Descriptive::Full->new();