Skip to content

Instantly share code, notes, and snippets.

@simonwistow
simonwistow / gist:786609
Created January 19, 2011 18:35
Testing
extend ThinkingSphinx::ActiveRecord::ClassMethods
class << self
attr_accessor :sphinx_index_blocks
def set_sphinx_primary_key(attribute)
@sphinx_primary_key_attribute = attribute
end
def primary_key_for_sphinx
@simonwistow
simonwistow / Infobot.pm
Created March 18, 2012 16:30
Updated Bot::BasicBot::Pluggable::Module::Infobot
package Bot::BasicBot::Pluggable::Module::Infobot;
{
$Bot::BasicBot::Pluggable::Module::Infobot::VERSION = '0.96';
}
use strict;
use warnings;
use base qw(Bot::BasicBot::Pluggable::Module);
use Data::Dumper;
use LWP::UserAgent ();
@simonwistow
simonwistow / Infobot.pm.diff
Created March 18, 2012 16:57
Infobot.pm.diff
--- Infobot.pm.orig 2012-03-18 09:13:26.000000000 -0700
+++ Infobot.pm 2012-03-18 09:29:08.000000000 -0700
@@ -14,6 +14,58 @@
eval { require XML::Feed };
our $HAS_XML_FEED = $@ ? 0 : 1;
+our %AUXILLARY_VERBS = (
+ "am" => { tense => 'present' },
+ "are" => { tense => 'present' },
+ "aren't" => { tense => 'present', negative_of => "are" },
% cat error.pl
use strict;
use Dancer;
get '/' => sub {
send_error('foo');
};
dance;
@simonwistow
simonwistow / hf2k
Created October 19, 2012 16:50
Yahoo's old proprietary front end scripting language - HTML Form Two Thousand
# HF2K Example
<!-- if $^r.uri !="/search/dir_ukie" && $|req[r] && $|req[y] == "n" -->
##redirect http://uk.search.yahoo.com/search/dir_ukie?$^r.args
exit
<!-- endif -->
@simonwistow
simonwistow / slavorg2.pl
Created January 9, 2013 15:42
Version 2 (?) of the Slavorg op bot
#!/usr/bin/perl
use warnings;
use strict;
use POE;
use POE::Component::IRC;
use IO::Handle;
open DEBUG, ">>slavorg.log" or die "Can't open log file: $!\n";
DEBUG->autoflush(1);
@simonwistow
simonwistow / tracking.pl
Last active August 29, 2015 14:01
Tracking cookies
sub vcl_recv {
if (req.http.Cookie ~ "mycookie=") {
# The request does have a tracking cookie so store it temporarily
set req.http.Tmp-Set-Cookie = req.http.Cookie;
unset req.http.Cookie;
} else {
# The request doesn't have a tracking cookie so force a miss
set req.hash_always_miss = true;
}
package SchemaLoader;
use strict;
sub schema {
my $class = shift;
my $table = shift;
my $dbh = shift;
my $db_type = $dbh->{'Driver'}{'Name'} or die 'Cannot determine DBI type';
my $sub = lc($db_type);
@simonwistow
simonwistow / tracking_create.pl
Last active August 29, 2015 14:01
Tracking cookie create
sub vcl_recv {
if (req.http.Cookie ~ "mycookie=") {
# The request does have a tracking cookie so store it temporarily
set req.http.Tmp-Set-Cookie = req.http.Cookie;
unset req.http.Cookie;
} else {
# The request doesn't have a tracking cookie so create one
set req.http.Tmp-Set-Cookie = if(req.http.Cookie, req.http.Cookie "; ", "") "mycookie=" digest.hash_md5(now randomstr(32) client.ip);
}
@simonwistow
simonwistow / caching_like_buttons.vcl
Last active August 29, 2015 14:04
Caching Like Buttons
#
# All of this can be done easily via the Fastly API but we present it here in VCL for brevity
# Simply create a new "Content" object and attach a request condition with the condition
# req.url ~ "^/like" && req.request == "POST"
# (or whatever your "like" API endpoint is).
#
# Then create a new Logging object and attach the same condition to it.
#
sub vcl_recv {