Skip to content

Instantly share code, notes, and snippets.

@onishi
onishi / statuscode.py
Created February 16, 2011 03:35
statuscode
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import httplib
class StatusCode(webapp.RequestHandler):
def get(self, code):
self.response.headers['Content-Type'] = 'text/html'
content = 'statuscode : ' + code + '<br>'
for c, m in httplib.responses.iteritems():
@onishi
onishi / indent_html
Created January 27, 2011 03:56
indent_html
sub indent_html {
my $html = shift;
my $indent = 0;
return join "\n", grep { $_ !~ /^\s*$/ } map {
s{(^\s+|\s+$)}{}g;
if (m{</}) {
$indent--;
}
$indent = 0 if $indent < 0;
my $res = ' ' x $indent . $_;
@onishi
onishi / gist:668857
Created November 9, 2010 08:22
cpanm
#!/usr/bin/perl
use strict;
use warnings;
system(
"$ENV{HOME}/perl5/bin/cpanm",
map {
s/\.pm$// and s{/}{::}g; # Can't locate
s/^perl-// and s{-}{::}g; # yum
$_;
use Benchmark 'cmpthese';
my $tagname = shift;
cmpthese(
1_000_000,
{
regexp => sub { regexp($tagname) },
lc_eq => sub { lc_eq($tagname) },
regexp_subst => sub { regexp_subst($tagname) },
@onishi
onishi / blamerate
Created June 22, 2010 03:16
check your responsibility
#!/bin/sh
if [ $# -eq 2 ]
then
i=$2
else
i=`whoami`
fi
declare -i mine=`git blame $1 | grep -i $i | wc -l`