Skip to content

Instantly share code, notes, and snippets.

@dankogai
dankogai / voorhees.js
Last active December 15, 2015 16:58
VERSION 0.0.2
#!/usr/bin/env node
/*
* $Id: voorhees.js,v 0.2 2013/04/03 07:11:17 dankogai Exp dankogai $
*
* (c) 2013 Dan Kogai
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license
*
*/
@dankogai
dankogai / camcontrol devlist
Created April 2, 2013 05:46
zfs raidz2 の例。ヘテロ構成が必ずしも悪いわけではない http://blog.livedoor.jp/dankogai/archives/51702535.html
<WDC WD20EARS-00MVWB0 51.0AB51> at scbus0 target 0 lun 0 (pass0,ada0)
<WDC WD20EARS-00MVWB0 51.0AB51> at scbus0 target 1 lun 0 (pass1,ada1)
<WDC WD20EARX-00PASB0 51.0AB51> at scbus0 target 2 lun 0 (pass2,ada2)
<WDC WD20EARX-00PASB0 51.0AB51> at scbus0 target 3 lun 0 (pass3,ada3)
<Port Multiplier 0325197b 000e> at scbus0 target 15 lun 0 (pass4,pmp0)
<WDC WD20EARX-00PASB0 51.0AB51> at scbus2 target 0 lun 0 (pass5,ada4)
<WDC WD20EARX-00PASB0 51.0AB51> at scbus2 target 1 lun 0 (pass6,ada5)
<WDC WD20EARS-00MVWB0 51.0AB51> at scbus2 target 2 lun 0 (pass7,ada6)
<WDC WD20EARS-00MVWB0 51.0AB51> at scbus2 target 3 lun 0 (pass8,ada7)
<Port Multiplier 0325197b 000e> at scbus2 target 15 lun 0 (pass9,pmp1)
@dankogai
dankogai / gist:5284015
Created April 1, 2013 09:35
boolean best practice
#!/usr/bin/env perl
use v5.12;
use boolean -truth;
use JSON;
sub boolean::TO_JSON() { !$_[0] ? \0 : \1 }
my $json = JSON->new->convert_blessed;
my $bools = { false => ( 0 == 1 ), true => ( 1 == 1 ) };
eval { say encode_json($bools) };
@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
@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 / 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 / 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 / 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: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 / 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