#!/usr/bin/perl use strict; use warnings; my @CHARS = split(//, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); my %CHAR2NUM = map {$CHARS[$_] => $_} (0..$#CHARS); my @AIUEO = split(//, "aiueoAIUEO_"); my %AIUEO2NUM = map {$AIUEO[$_] => $_} (0..$#AIUEO); foreach my $asin ("4844322893", "B000EQHU6M", "0123450000") { my $e = aiueo_encode(asin_encode($asin)); my $d = asin_decode(aiueo_decode($e)); print "$asin =>(encode)=> $e =>(decode)=> $d\n"; } sub asin_encode { my ($asin) = @_; my $sum = 0; foreach (reverse split(//, $asin)) { $sum *= @CHARS; $sum += $CHAR2NUM{$_}; } return $sum; } sub asin_decode { my ($n) = @_; my $asin; for (1..10) { my $r = $n % @CHARS; $n = ($n - $r) / @CHARS; $asin .= $CHARS[$r]; } return $asin; } sub aiueo_encode { my ($n) = @_; my $c; while ($n > 0) { my $r = $n % @AIUEO; $n = ($n - $r) / @AIUEO; $c .= $AIUEO[$r]; } return $c; } sub aiueo_decode { my ($c) = @_; my $sum = 0; foreach (reverse split(//, $c)) { $sum *= @AIUEO; $sum += $AIUEO2NUM{$_}; } return $sum }
% perl encode.pl 4844322893 =>(encode)=> uuoEIAuEI_aoIO =>(decode)=> 4844322893 B000EQHU6M =>(encode)=> oaUIAeAUeoOae_A =>(decode)=> B000EQHU6M 0123450000 =>(encode)=> ueAuOAOoi =>(decode)=> 0123450000
### YouTube # usage: {{youtube('ID', 'size:1<2<3<4<5(default)<6<7<...')}} # Ex. {{youtube("e9-L68H0AHU", 2)}} sub youtube { my ($id, $size) = @_; $size = 5 if (not defined $size or $size < 1); my $url = "http://www.youtube.com/v/$id"; my ($w, $h) = (85 * $size, 70 * $size); return qq(<object width="$w" height="$h">). qq(<param name="movie" value="$url"></param>). qq(<embed src="$url" type="application/x-shockwave-flash" ). qq(width="$w" height="$h"></embed></object>\n); }
{{youtube("Xv_ftbVzU1o", "", 1)}}
{{youtube("We8e3YrnDzg", "", 3)}}
{{youtube("e9-L68H0AHU")}} (size=5)