Skip to content

Instantly share code, notes, and snippets.

@plaster
plaster / abc.hs
Last active August 29, 2015 14:19
a :: Int
b :: Int
c :: Int
c = a + b
a = 5
b = 7
main = print c
-- 4回readしたいけどこれで正しいか?もしくはもっとシンプルな書き方があるか?
parse :: String -> (Int, Int, Int, Int)
parse s = (c1, p1, c2, p2) where
[(c1, s')] = readsPrec 10 s
[(p1, s'')] = readsPrec 10 s'
[(c2, s''')] = readsPrec 10 s''
[(p2, s'''')] = readsPrec 10 s'''
@plaster
plaster / factorize.hs
Created December 19, 2015 15:43
素直な素因数分解
factorize :: Integer -> [ Integer ]
factorize n = factorize' n $ takeWhile (\x -> x * x <= n) [ 2 .. n ] where
factorize' n [] = case n of
1 -> []
_ -> [n]
factorize' n ds@(d:ds') = case n `mod` d of
0 -> d : factorize' (n `div` d) ds
_ -> factorize' n ds'
main = interact $ show . factorize . read
[ plaster@cymbal:~ ]
% sudo apt-get build-dep dash
[sudo] plaster のパスワード:
パッケージリストを読み込んでいます... 完了
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 0 個。
[ plaster@cymbal:~ ]
% fakeroot
grep_2.25-6
[ plaster@cymbal:/tmp/debian-tutorial-exercise-1 ]
% dget http://ftp.debian.org/debian/pool/main/g/grep/grep_2.25-6.dsc
dget: retrieving http://ftp.debian.org/debian/pool/main/g/grep/grep_2.25-6.dsc
--2016-08-20 16:55:02-- http://ftp.debian.org/debian/pool/main/g/grep/grep_2.25-6.dsc
ftp.debian.org (ftp.debian.org) をDNSに問いあわせています... 130.89.148.12
ftp.debian.org (ftp.debian.org)|130.89.148.12|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 1969 (1.9K)
@plaster
plaster / coins.pl
Last active October 24, 2016 17:49
use strict;
use warnings;
no warnings 'recursion';
my @coins = qw( 500 100 50 10 5 1 );
my %freq = map { $_ => 0 } @coins;
sub emit_freq() {
print join(' + ', map {
sprintf('%d x %d', $_, $freq{$_})
@plaster
plaster / testtest.sh
Last active November 15, 2016 03:38
testtestb.sh, testtest_{3,4}.txt: Thanks to @hio
if test $1 = $2; then echo '='; else echo '!='; fi
if test "$1" = "$2"; then echo '='; else echo '!='; fi
if [ $1 = $2 ]; then echo '='; else echo '!='; fi
if [ "$1" = "$2" ]; then echo '='; else echo '!='; fi
@plaster
plaster / README.md
Last active December 4, 2016 09:29
screen: display&window encoding / settings&options

screen の -U を複数回指定してしまったとき

(WIP)

とある事情から .screenrc と .zshrc をスクラッチで書き直したところ、 「screen を再アタッチするときだけマルチバイト文字の表示が壊れる」というヘンテコな現象に遭遇してしまいました。

https://twitter.com/plaster/status/801431121082748928

@plaster
plaster / tee_pipe.txt
Last active December 21, 2016 17:38
tee pipe
ル╹ヮ╹ルɔ jolokia:~
% (yes | tee /tmp/yes.txt | while read; do sleep 1; done) &
[1] 303
ル╹ヮ╹ルɔ jolokia:~
% while true; do sleep 1; ls -lh /tmp/yes.txt; done
-rw-r--r-- 1 plaster plaster 64K Dec 22 02:20 /tmp/yes.txt
-rw-r--r-- 1 plaster plaster 64K Dec 22 02:20 /tmp/yes.txt
-rw-r--r-- 1 plaster plaster 64K Dec 22 02:20 /tmp/yes.txt
-rw-r--r-- 1 plaster plaster 64K Dec 22 02:20 /tmp/yes.txt
-rw-r--r-- 1 plaster plaster 64K Dec 22 02:20 /tmp/yes.txt
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\WindowsUpdate\AU]
"NoAutoRebootWithLoggedOnUsers"=dword:00000001