Created
July 29, 2011 14:21
-
-
Save avar/1113894 to your computer and use it in GitHub Desktop.
Goose Goose Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.10; | |
use warnings; | |
use Dancer; | |
use URI::Escape qw(uri_escape_utf8); | |
# This is all the search engine does | |
get '/search' => sub { | |
given (param("q")) { | |
when (/^(?:!(?:ducky)?\s+|\\)(.*)/) { redirect 'http://www.google.com/search?btnI=1&q=' . uri_escape_utf8 $1 } | |
when (/^(!.*)/) { redirect 'http://duckduckgo.com/?q=' . uri_escape_utf8 $_ } | |
default { redirect 'http://www.google.com/search?q=' . uri_escape_utf8 $_ } | |
} | |
}; | |
# Irrelevant crap nobody cares about | |
get '/favicon.ico' => sub { | |
# Steal DuckDuckGo's favicon.ico | |
redirect 'http://duckduckgo.com/favicon.ico'; | |
}; | |
get '/*' => sub { | |
redirect '/'; | |
}; | |
get '/' => sub { | |
<<"MAIN_PAGE"; | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>GooseGooseGo - DuckDuckGo with saner defaults</title> | |
</head> | |
<body> | |
<h1>GooseGooseGo</h1> | |
<form name="search" method="GET" action="/search"> | |
<input type="text" autocomplete="off" name="q" autofocus tabindex="1" /> | |
<button title="Goose Go!">Search</button> | |
</form> | |
<h1>Source code and documentation</h1> | |
<script src="https://gist.github.com/1113894.js"></script> | |
</body> | |
</html> | |
MAIN_PAGE | |
}; | |
dance; | |
__END__ | |
=encoding utf8 | |
=head1 NAME | |
GooseGooseGo - A DuckDuckGo-like search engine with saner defaults | |
=head1 DESCRIPTION | |
GooseGooseGo reflects my use of L<DuckDuckGo|http://duckduckgo.com>. | |
=over | |
=item * | |
By default search queries will be sent to L<Google|http://google.com>, | |
not DuckDuckGo. | |
=item * | |
The L<!bang syntax|http://duckduckgo.com/bang.html> is handled by | |
DuckDuckGo, except C<!>. Which will get you the first Google result, | |
instead of the first DuckDuckGo result. | |
=back | |
That's it! | |
=head1 AUTHOR | |
Ævar Arnfjörð Bjarmason <[email protected]> | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment