Skip to content

Instantly share code, notes, and snippets.

@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`
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 / 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
$_;
@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 / 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 / gist:1053219
Created June 29, 2011 05:33
decode_punycode
use IDNA::Punycode;
use Encode;
idn_prefix('xn--');
decode_punycode('xn--cho'); #=> '䑵'
decode_punycode('xn--motemen'); #=> '嵡嵣嵫嵧嵨'
decode_punycode('xn--hitode'); #=> '岴岊岲'
decode_punycode('xn--hakobe932'); #=> IDNA::Punycode が落ちて abort
@onishi
onishi / mysqldiff
Created August 19, 2011 07:57
mysqldiff - mysql scheme diff
#!/usr/bin/env perl
use strict;
use warnings;
# TODO
# - drop key
@ARGV == 2 or die 'Usage: mysqldiff dbname1 dbname2';
my @tables = map {
@onishi
onishi / set_uninterrupted_count
Created October 4, 2011 06:50
uninterrupted day count by MySQL Stored Procedure
CREATE TABLE entry (
blog_id INT,
created datetime
);
DROP PROCEDURE IF EXISTS set_uninterrupted_count;
DELIMITER //
CREATE PROCEDURE set_uninterrupted_count(IN id INT, OUT uninterrupted_count INT)
BEGIN
DECLARE done INT DEFAULT 0;
@onishi
onishi / gist:1630307
Created January 18, 2012 01:55
Media queries for Hatena Group
@media screen and (max-device-width: 480px) {
* {
font-size: 48px;
line-height: 64px;
word-break: break-all;
}
table#banner, div#simple-header, div.sidebar, div.caption {
display:none
}
img.hatena-star-comment-button, img.hatena-star-add-button, img.hatena-star-star {
@onishi
onishi / hello.pl
Created March 17, 2012 06:26
Hello World
#!/usr/bin/env perl
print "Hello, World!!";