Skip to content

Instantly share code, notes, and snippets.

View hiratara's full-sized avatar
🇯🇵
born in Japan

Masahiro Honma hiratara

🇯🇵
born in Japan
View GitHub Profile
package Seg;
use strict;
use warnings;
use Exporter qw(import);
our @EXPORT = qw(solve);
sub parse_char ($) {
my $c = shift;
(!! ($c & 04), !! ($c & 02), !! ($c & 01));
}
package Solver;
use strict;
use warnings;
use Exporter qw(import);
our @EXPORT = qw(solve);
sub hex_to_bin ($) { unpack 'B8', (pack 'C', hex $_[0]) }
sub split_bytes ($) {
@hiratara
hiratara / sample-stream.hs
Last active December 26, 2015 20:19
My own sample implementation of a stream library.
module Main (main) where
import Control.Monad
import Control.Monad.Free
main :: IO ()
main = print . runStream $ sourceString |==| reverseString |==| waitString
data Void
data StreamF i o next =
@hiratara
hiratara / test.pl
Created October 22, 2013 05:14
A sample of `left outer join' and `null'
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect("dbi:mysql:OREDB", "ORE", "OREPASS");
$dbh->do('create temporary table if not exists x (id int primary key, y int not null) engine=innodb');
$dbh->do('create temporary table if not exists y (id int primary key, name varchar(123)) engine=innodb');
$dbh->do("insert x values (1, 1)");
$dbh->do("insert x values (2, 2)");
$dbh->do("insert x values (3, 3)");
module Monster(solve) where
import Prelude hiding (drop)
weak :: Char -> Maybe Char
weak 'B' = Just 'a'
weak 'D' = Just 'c'
weak 'F' = Just 'e'
weak 'H' = Just 'g'
weak 'J' = Just 'i'
weak 'L' = Just 'k'
@hiratara
hiratara / Test.java
Last active December 23, 2015 17:48
A trivial sample of Java's regex.
public class Test {
static final private boolean looksLikeTel (String maybeTel) {
return maybeTel.matches("^[0-9]+(-[0-9]+)*$") ? true : false;
}
static final public void main (String args[]) {
String tels[] = {"090-9012-3234", "0.123", "ABCDE"};
for (String maybeTel: tels) {
System.out.println(
maybeTel +
use strict;
use warnings;
use List::Util qw(sum);
use Exporter qw(import);
our @EXPORT = qw(solve);
sub max_pos {
die "Found an empty list" unless @_;
my ($pos, $cur) = (0, $_[0]);
for (1 .. $#_) {
@hiratara
hiratara / lvalue_name.pl
Last active December 21, 2015 17:09
A sample of perl lvalue subroutine
package Dog;
use strict;
use warnings;
sub new { bless {}, shift }
sub name : lvalue { $_[0]->{name} }
package main;
use strict;
use warnings;
my $mydog = Dog->new;
@hiratara
hiratara / typed_perl_sampl.pl
Created August 12, 2013 10:59
A sample code of which type can be inferred by TypedPerl. https://github.com/hiratara/TypedPerl
1;
package Hira;
sub hello {
my $name = $_[0]->{name};
print("hello" . $name . "world");
}
package Dan;
sub hello {
package Dice;
use strict;
use warnings;
use List::Util qw(reduce);
use Exporter qw(import);
our @EXPORT = qw(solve);
sub N{$_[2],$_[1],7-$_[0]}sub S{N N N @_}sub W{7-$_[1],$_[0],$_[2]}sub E{W W W @_}