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
import Control.Monad (forM_)
import Data.List.Split (splitOn)
import qualified Data.Map as M
import Data.Maybe (maybe)
import System.Environment (getArgs)
import System.IO (readFile)
parseLine :: String -> (String, Int)
parseLine str = let (key:count:_) = splitOn "\t" str
in (key, read count)
@hiratara
hiratara / monkey.pl
Created October 12, 2018 02:55
An example of monkey patch
use strict;
use warnings;
use Time::Piece;
{
no warnings 'redefine';
my $orig_strptime = \&Time::Piece::strptime;
*Time::Piece::strptime = sub {
my @warns;
my $result = do {
@hiratara
hiratara / dummy
Created February 1, 2018 23:43
dummy
dummy
use strict;
use warnings;
use Benchmark qw(cmpthese);
use Iterator::Simple qw(iter islice imap list);
my $n = 1000;
my $size = 10000;
my $start = $ARGV[0] // die;
my $end = $ARGV[1] // die;
my @list = (1 .. $size);
@hiratara
hiratara / use-sort.t
Created March 25, 2016 07:15
A scope of `sort` pragma
use strict;
use warnings;
use Test::More;
use sort '_quicksort';
sub test_sort () {
my @sorted = sort { $a->[1] <=> $b->[1] } map { [$_, $_ % 2] } 1 .. 100;
is_deeply \@sorted, [(map { [$_ * 2, 0] } 1 .. 50), (map { [$_ * 2 - 1, 1] } 1 .. 50)];
}
@hiratara
hiratara / Main.hs
Created February 6, 2016 05:04
The TOP 100 packages on hackage
module Main where
import Control.Monad (forM_)
import qualified Data.Map as M
import qualified Distribution.PackDeps as PD
import GHC.Exts (sortWith)
main :: IO ()
main = do
ns <- PD.loadNewest
use strict;
use warnings;
use Exporter qw(import);
our @EXPORT_OK = qw(solve);
my @fee_system = (
[995, 400, 60],
[845, 350, 50],
);
package Answer;
use strict;
use warnings;
use Exporter qw(import);
our @EXPORT_OK = qw(solve);
sub directions ($$$$$) {
my ($n, $e, $s, $w, $t) = @_;
my @directions = (
@hiratara
hiratara / Main.hs
Last active August 29, 2015 14:14
An implementation of lax monoidal functor with strength
module Main (main) where
import Control.Applicative
class Functor f => LaxMonoidalWithStrength f where
unit :: () -> f ()
phi :: (f a, f b) -> f (a, b)
st :: (a, f b) -> f (a, b)
{-