Skip to content

Instantly share code, notes, and snippets.

=head1 NAME
Plack::Loader - (auto)load PSGI/Plack Servers
=head1 SYNOPSIS
#!/usr/bin/env perl
# printenv-like app in PSGI, F?CGI, AnyEvent, Coro, POE or Danga::Socket
use strict;
use warnings;
@dankogai
dankogai / freebsd.yml
Created January 9, 2012 08:03
mirrorget.pl
master: http://ftp.freebsd.org/pub/FreeBSD/
mirrors:
- http://ftp.iij.ad.jp/pub/FreeBSD/
- http://ftp.riken.jp/pub/FreeBSD/
- http://ftp.sakura.ad.jp/pub/FreeBSD/
- http://ftp.jaist.ac.jp/pub/FreeBSD/
@dankogai
dankogai / bucketSort.js
Created January 10, 2012 21:55
General-purpose bucket sort in JS
bucketSort = function(src, k2i, v2k) {
if (src.length <= 1) return src;
k2i = k2i || function(k, d){ return (''+k).charCodeAt(d) || 0 };
v2k = v2k || function(v){ return v };
/* first we bundle elements with same keys */
var valOf = Object.create(null), concat = Array.prototype.concat;
src.forEach(function(v){
var k = v2k(v);
if (valOf[k]) valOf[k].push(v);
else valOf[k] = [v];
@dankogai
dankogai / extract-dqt.pl
Created January 23, 2012 08:26
Quick and Dirty JPEG DQT Extractor
use 5.012;
my @zigzag = qw{
0 1 5 6 14 15 27 28
2 4 7 13 16 26 29 42
3 8 12 17 25 30 41 43
9 11 18 24 31 40 44 53
10 19 23 32 39 45 52 54
20 22 33 38 46 51 55 60
21 34 37 47 50 56 59 61
35 36 48 49 57 58 62 63
@dankogai
dankogai / gist:4958651
Last active December 13, 2015 18:58
How to factor large integers in python

sympy is the module of choice so far

% /opt/local/bin/python2
Python 2.7.3 (default, Oct 23 2012, 00:39:45) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy.ntheory import primefactors
>>> primefactors(280671392065546467397265294532969672241810318954163887187279320454220348884327)
[162425297, 215940091, 358456949, 369941863, 479871607, 706170617, 481362815814826159]

>>>

@dankogai
dankogai / alternative to msgpack-update-proposal2.md
Last active December 14, 2015 05:39 — forked from frsyuki/msgpack-update-proposal2.md
I found the original proposal too ugly.

Overview

See https://gist.github.com/frsyuki/5028082 Before reading further.

Changes on the type system

Instead of filling empty slots with a bunch of Extended types, I propose adding just one type.

  • Typed: a tuple of type and byte array.
@dankogai
dankogai / gist:5054170
Last active December 14, 2015 07:59
How a very long subject line gets MIME-Encoded by Web mailers

Original String:

Subject: 漢字、カタカナ、ひらがなとasciiの混じったとてもとてもとても長いSubjectを含んだヘッダーがどうencodeされるかのテスト

###gmail

Subject: =?ISO-2022-JP?B?GyRCNEE7eiEiJSslPyUrJUohIiRSJGkkLCRKJEgbKEJhc2NpaRskQiROOi4bKEI=?=
\t=?ISO-2022-JP?B?GyRCJDgkQyQ/JEgkRiRiJEgkRiRiJEgkRiRiRDkkJBsoQlN1YmplY3QbJEIkcjReJHMbKEI=?=
@dankogai
dankogai / gist:5064444
Last active December 14, 2015 09:19
Lock file generation benchmark
#!/usr/bin/env perl
use v5.16;
use Fcntl qw/:DEFAULT/;
use Benchmark qw/:all/;
my $tmp_ssd = "$ENV{HOME}/$$";
my $tmp_hdd = "$ENV{HOME}/\@HDD/$$";
sub touch {
my $fn = shift;
@dankogai
dankogai / bench.pl
Last active December 14, 2015 11:29
Encode vs. Unicode::UTF8 vs. utf8
#!/usr/bin/env perl
use strict;
use warnings;
use Encode qw();
use Unicode::UTF8 qw();
use Benchmark qw/:all/;
my $bytes = do {
local $/;
open my $fh, '<', $0 or die "$0:$!";
@dankogai
dankogai / bench.pl
Last active December 14, 2015 11:38
Encode vs. Unicode::UTF8 vs. '<:utf8'
#!/usr/bin/env perl
use strict;
use warnings;
use Encode qw();
use Unicode::UTF8 qw();
use Benchmark qw/:all/;
my $enc = Encode::find_encoding('utf8');
# Decode file