Skip to content

Instantly share code, notes, and snippets.

View pstuifzand's full-sized avatar

Peter Stuifzand pstuifzand

View GitHub Profile
@pstuifzand
pstuifzand / twitter.pl
Created July 31, 2009 13:40
Command line Twitter
# Simple commandline twitter script.
# Reads a line from STDIN and updates twitter.
# This doesn't work anymore, because of OAuth.
# Net::Twitter does support OAuth so it could be rewitten to make it work
# Created by Peter Stuifzand <peter.stuifzand@gmail.com>
use strict;
use warnings;
use Net::Twitter;
@pstuifzand
pstuifzand / just-one-space.vim
Created August 5, 2009 09:29
Just one space function for vim
" Replace many spaces with one in Vim
" With help from Al: http://stackoverflow.com/questions/1228100/substituting-zero-width-match-in-vim-script
function JustOneSpace()
" Get the current contents of the current line
let current_line = getline(".")
" Get the current cursor position
let cursor_position = getpos(".")
@pstuifzand
pstuifzand / gist:916575
Created April 12, 2011 22:22
I got this on the same request
127.0.0.1:5000
Start Time: Wed Apr 13 2011 00:20:59 GMT+0200 (CEST)
t=1302646859860 [st=0] +SOCKET_ALIVE [dt=4]
--> source_dependency = {"id":210,"type":4}
t=1302646859860 [st=0] +TCP_CONNECT [dt=0]
--> address_list = ["127.0.0.1:5000"]
t=1302646859860 [st=0] TCP_CONNECT_ATTEMPT [dt=0]
--> address = "127.0.0.1:5000"
@pstuifzand
pstuifzand / accesslog-parser.pl
Created April 13, 2011 10:33
Accesslog parser in Perl using Parse::RecDescent.
use Data::Dumper;
use Parse::RecDescent;
$Parse::RecDescent::skip = '';
my $grammar = q{
line: ip ws '-' ws user ws datetime ws request ws status ws responsesize
ws referrer ws useragent "\n"
{ $return = {
ip => $item[1],
@pstuifzand
pstuifzand / logfile.pl
Created April 13, 2011 14:32
Shows the HTTP status of the last few requests in the logfile
#!/usr/bin/perl -w
# Name: logtail.pl
# Description Shows the HTTP status of the last few requests in the logfile
# Usage: tail -f apachelogfile.log | perl logtail.pl
# Date: Wed Apr 13 16:31:35 CEST 2011
# Author: Peter Stuifzand
# License: GPL3+
use strict;
use Parse::AccessLogEntry;
@pstuifzand
pstuifzand / parser.pl
Created March 14, 2012 21:34
Parser built with Marpa::XS
use 5.10.1;
use strict;
use Marpa::XS;
my $grammar = Marpa::XS::Grammar->new({
actions => 'Action',
start => 'Parser',
rules => [
{ lhs => 'Parser', rhs => [ qw/Expression/ ], action => 'Parser' },
@pstuifzand
pstuifzand / scribe_parser.pl
Created March 15, 2012 00:39
(Partial) Parser for Scribe built with Marpa::XS
#!/usr/bin/perl -w
use 5.10.1;
use strict;
use File::Slurp 'read_file';
use Marpa::XS;
my %tokens = (
AT => qr/^\@/,
LP => qr/^\(/,
@pstuifzand
pstuifzand / tree_structure_test.pl
Created March 30, 2012 18:10
Using Marpa with a tree structure
use Marpa::XS;
use Data::Dumper;
my $grammar = Marpa::XS::Grammar->new(
{ start => 'Expression',
actions => 'My_Actions',
rules => [
# This rebuilds the tree
{ lhs => 'Expression', rhs => [qw/Term/], action => 'Return_0' },
@pstuifzand
pstuifzand / counted_rule.pl
Created April 7, 2012 09:28
BNF generator for counted rule X{N}
use 5.14.2;
use List::Util 'sum';
# power a n = a if n == 1
# power a n = power (power a 2) (n/2) if n is even
# power a n = (power (power a 2) (n/2)) * a if n is odd
sub power {
my ($op, $a, $n) = @_;
if ($n == 1) {
@pstuifzand
pstuifzand / testcase1.pl
Created April 7, 2012 11:22
Testcase parser, lexer exhausted
use Marpa::XS;
use MarpaX::Simple::Lexer;
use IO::String;
my $grammar = Marpa::XS::Grammar->new( {
start => 'Parser',
rules => [
[ 'Parser' => [ 'X' ] ],
],
terminals => [qw/X/],