Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / one-liner
Last active December 15, 2015 19:19
Perl hash iteration order
% perl -E 'system qw[perl -E], q[say %{{"a".."z"}}] for 1..100'
#!/usr/bin/env perl
use strict;
use warnings;
use File::Spec;
our $VERSION = sprintf "%d.%02d", q$Revision: 0.1 $ =~ /(\d+)/g;
sub usage { exec 'pod2usage', $0 or die "pod2usage: $!" }
my $cmd = '/usr/bin/osascript';
die "$0 : $cmd nonexistent" unless -x $cmd;
my @paths = grep { -e $_ } map { File::Spec->rel2abs($_) } @ARGV;
@dankogai
dankogai / gist:5896195
Created June 30, 2013 18:04
bsfilter bsfilter-1.0.18.ruby1.9.rc5 workaround that dies with "ArgumentError: invalid byte sequence"
--- bsfilter.1.0.18rc5 Sun Mar 10 03:03:03 2013
+++ bsfilter Mon Jul 1 02:52:54 2013
@@ -933,24 +933,27 @@
if (str.force_encoding('ASCII-8BIT') =~ reg_gb18030_possible)
gb18030_possible = true
end
-
- if (str.encode('UTF-8', 'UTF-8') =~ reg_utf8)
- @options["message-fh"].printf("lang ja utf8\n") if (@options["debug"])
- return ["ja", "utf8"]
@dankogai
dankogai / gist:11215062
Created April 23, 2014 13:24
bash-4.3.11_1 in FreeBSD ports
% cat /usr/ports/shells/bash/pkg-message
======================================================================
bash requires fdescfs(5) mounted on /dev/fd and procfs(5) mounted on
/proc.
If you have not done it yet, please do the following:
mount -t fdescfs fdesc /dev/fd
mount -t procfs proc /proc
@dankogai
dankogai / fetch.swift
Created June 7, 2014 20:24
fetch url and dump its content to stdout
import Foundation
if C_ARGC < 2 {
println("\(C_ARGV[0]) url")
exit(-1)
}
let url = NSURL.URLWithString(String.fromCString(C_ARGV[1]))
var enc:NSStringEncoding = NSUTF8StringEncoding
var err:NSError?
let content =
NSString.stringWithContentsOfURL(url, usedEncoding:&enc, error:&err)
@dankogai
dankogai / json.swift
Last active August 29, 2015 14:02
fetch json via URL and dumps it
import Foundation
if C_ARGC < 2 {
println("\(C_ARGV[0]) url")
exit(-1)
}
let url = NSURL.URLWithString(String.fromCString(C_ARGV[1]))
var enc:NSStringEncoding = NSUTF8StringEncoding
var err:NSError?
let content =
NSString.stringWithContentsOfURL(url, usedEncoding:&enc, error:&err)
@dankogai
dankogai / church.swift
Created June 15, 2014 09:44
Lambda Calculus in Swift
//
// main.swift
// church
//
// Created by Dan Kogai on 6/15/14.
// Copyright (c) 2014 Dan Kogai. All rights reserved.
//
/* Operators */