Skip to content

Instantly share code, notes, and snippets.

View hkoba's full-sized avatar

Kobayasi, Hiroaki hkoba

View GitHub Profile
@hkoba
hkoba / .gitignore
Last active August 29, 2015 14:01
Paragraph reading example in OCaml. (Not enough tested)
/_build
*.native
@hkoba
hkoba / perl-build-thisdir
Last active August 29, 2015 14:01
Custom perl-build for given directory (usually blead-perl git checkout)
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib/"
, "$FindBin::Bin/../lib/perl5"; # To make happy with plenv directory structure.
use Perl::Build;
use Getopt::Long;
use Pod::Usage;
use File::Spec;
@hkoba
hkoba / test_readline.ml
Last active August 29, 2015 14:03
How can I get line-by-line input from terminal, in OCaml? (Solved)
open Core.Std
module U = UnixLabels
try
let in_fd = U.descr_of_in_channel stdin in
let default = U.tcgetattr in_fd in
let cooked = {default with U.c_icanon = true} in
U.tcsetattr in_fd ~mode:U.TCSANOW cooked;
while true do
let line = input_line stdin in
@hkoba
hkoba / do_vs_prepare.pl
Created July 17, 2014 08:03
A benchmark to compare DBI->do and DBI->prepare+execute
#!/usr/bin/perl
use strict;
use warnings FATAL => qw/all/;
sub MY () {__PACKAGE__}
use DBI;
sub usage {
die <<END;
Usage: $0 [--do | --dbsub] DBFILE [N-RECORDS] [LEN-of-STR]
@hkoba
hkoba / mojoyatttest.pl
Last active August 29, 2015 14:04
dev-embedded test
#!/usr/bin/env perl
use Mojolicious::Lite;
use YATT::Lite::Embed;
foreach my $name ($YATT->list_public_items) {
get "/$name" => sub {
my ($self) = @_;
# $self->render(text => 'Hello!');
$self->render(text => $YATT->render($name));
@hkoba
hkoba / nseqrun.zsh
Last active August 29, 2015 14:05
Sample for "for loop" in Zsh
#!/bin/zsh
set -eu
progname=$0:a
function usage {
cat 1>&2 <<EOF; exit 1
Usage: ${progname:t} SRCFN [N-copies]
EOF
}
@hkoba
hkoba / bash_ld_preload.c
Last active August 29, 2015 14:06
Preciser(?) version of bash_ld_preload.c (originally found in access.redhat.com/articles/1200223)
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
/*
# Originally found at: https://access.redhat.com/articles/1200223
https://access.redhat.com/sites/default/files/attachments/bash_ld_preload.c
# This version checks '()' just after first occurrence of '=', so that it will not do overkill.
@hkoba
hkoba / ghc-doc-index.patch
Created September 25, 2014 10:49
To remove bash-ism from ghc-doc-index.
--- ghc-doc-index.orig 2014-09-25 19:47:00.000000000 +0900
+++ ghc-doc-index 2014-09-25 19:47:28.000000000 +0900
@@ -34,5 +34,5 @@
fi
if [ -f $PKGDIRCACHE.new ]; then
- mv -f $PKGDIRCACHE{.new,}
+ mv -f $PKGDIRCACHE.new $PKGDIRCACHE
fi
@hkoba
hkoba / prod-summary.zsh
Created October 27, 2014 14:57
How to use associative array to calculate summary in Zsh
#!/bin/zsh
# Rewrite of http://www.atmarkit.co.jp/ait/articles/1208/17/news110_2.html
# unset summary;
typeset -A summary;
while read prod amt; do
((summary[$prod]+=$amt))
done
for prod in ${(ko)summary}; do
@hkoba
hkoba / .Xmodmap
Created October 29, 2014 08:08
Xmodmap for JP106 -> US, with better placed tilde, backslash, ESC, Control and ALT
!
! Xmodmap for JP106 -> US
!
remove Lock = Eisu_toggle
add Control = Eisu_toggle
keysym Eisu_toggle = Control_L
! add mod1 = Muhenkan
! keysym Muhenkan = Alt_L