Skip to content

Instantly share code, notes, and snippets.

@zoul
zoul / proxy.pl
Created November 15, 2011 18:41
Simple debugging HTTP proxy in Perl
#!/usr/bin/env perl
use Modern::Perl;
use HTTP::Proxy;
use HTTP::Proxy::HeaderFilter::simple;
my $proxy = HTTP::Proxy->new(host => undef, port => 3128);
my $filter = HTTP::Proxy::HeaderFilter::simple->new(sub
{
my ($self, $headers, $message) = @_;
@zoul
zoul / DetectDeallocations.h
Created November 11, 2010 15:33
Detects object deallocations. Good for testing.
// Runs given block. Returns YES if some object of class ‘c’
// was deallocated in the block. Not thread-safe.
BOOL classGetsDeallocated(Class c, void (^block)(void));
// Convenience interface that calls the function above.
// Releases object, returns YES if object was deallocated.
BOOL getsDeallocatedByReleasing(id object);
@zoul
zoul / UINavigationItemPlus.h
Created August 31, 2010 07:40
Multiple buttons in UINavigationItem
@interface UINavigationItem (Extensions)
- (void) setRightBarButtonItemsWithTotalWidth: (NSUInteger) width
items: (UIBarItem*) firstItem, ...;
@end
@zoul
zoul / UIDevice+Model.h
Created March 20, 2010 10:14
Detect specific iPhone/iPod/iPad model
typedef enum {
kDeviceTypeUnknown = 0,
kDeviceTypeSimulator,
kDeviceTypeiPhone1G,
kDeviceTypeiPhone3G,
kDeviceTypeiPhone3GS,
kDeviceTypeiPhone4,
kDeviceTypeiPod1G,
kDeviceTypeiPod2G,
kDeviceTypeiPad
@zoul
zoul / objc-varargs.m
Created March 19, 2010 13:36
Variable arguments in Objective-C
- (void) processStrings: (NSString*) str1, ...
{
va_list args;
va_start(args, str1);
NSString *arg = str1;
while (arg != nil) {
// do something with arg
arg = va_arg(args, NSString*);
}
va_end(args);
@zoul
zoul / crawler.pl
Created January 5, 2010 18:48
Simple web crawler in Perl
#!/usr/bin/perl
use Modern::Perl;
use WWW::Mechanize;
my $root = 'http://naima:3000/cs/';
my $domain = 'http://naima';
my $mech = WWW::Mechanize->new;
sub visit {
@zoul
zoul / rss-filter.pl
Created December 21, 2009 21:02
Filter RSS using an XSL template
#!/usr/bin/perl
use Modern::Perl;
use XML::RSS::Tools;
use Perl6::Slurp;
my $style = slurp \*DATA;
my $feed = XML::RSS::Tools->new;
#$feed->set_http_client('lite');
#$feed->debug(1);
@zoul
zoul / REPL.pm
Created October 4, 2009 07:51
How to write a simple REPL interface to a Perl module
package REPL;
use Modern::Perl;
use Moose;
sub foo
{
return "foo";
}
#!/usr/bin/perl
use Modern::Perl;
use Benchmark 'cmpthese';
sub with_eval
{
eval
{
my ($a, $b) = (2, 4);
@zoul
zoul / immutable-tree.pl
Created March 17, 2015 18:02
Building an immutable tree
#!/usr/bin/env perl
use v5.14;
use strict;
use warnings;
use Data::Dump 'pp';
{
package Node;
use Mouse;