Skip to content

Instantly share code, notes, and snippets.

View akiradeveloper's full-sized avatar

Akira Hayakawa akiradeveloper

View GitHub Profile
int main(void)
{
return 0;
}
@akiradeveloper
akiradeveloper / Single.hs
Created August 7, 2011 01:48
The simplest Monad instance
-- Single value must be Monad.
-- Akira Hayakawa, 2011
import Control.Applicative
import Control.Monad
data Single a = Single a deriving (Eq, Show, Ord)
instance Functor Single where
-- fmap :: (a->b) -> Single a -> Single b
@akiradeveloper
akiradeveloper / While.hs
Created August 9, 2011 02:58
While Functor prototype failure
newtype While a = While { get :: (a, Bool) }
instance Functor While where
fmap f (While (a, True)) = let (a', b) = f a in While (a', b)
fmap _ (While (a, False)) = While (a, False)
countDown :: Int -> (Int, Bool)
countDown i =
let i' = i - 1
in
@akiradeveloper
akiradeveloper / ApplicativeGetLine.hs
Created August 11, 2011 13:15
The power of Applicative Functor
Prelude Control.Applicative> let x = (++) <$> getLine <*> getLine
Prelude Control.Applicative> x
akira
developer
"akiradeveloper"
@akiradeveloper
akiradeveloper / Solver.hs
Created August 14, 2011 11:48
Siritori solver in Haskell.
-- Still under development but I will show you my code.
-- Haskell is beautiful.
import Control.Monad
import Data.List
type Elem = (Int, Int)
-- Either Monad is not defined yet in ghc of 6.x
instance Monad (Either a) where
@akiradeveloper
akiradeveloper / Solver.hs
Created August 14, 2011 12:34
Siritori solver in Haskell.
import Control.Monad
import Data.List
type Elem = (Int, Int)
-- Either Monad is not defined yet in ghc of 6.x
instance Monad (Either a) where
Right a >>= f = f a
Left a >>= _ = Left a
return = Right
@akiradeveloper
akiradeveloper / gist:1380162
Created November 20, 2011 11:21
OCamlの対話モードで上キーを押してもこのようになって履歴が見れない. irbでも同じ. なぜ??
# let f x = x;;
val f : 'a -> 'a = <fun>
# ^[[A
@akiradeveloper
akiradeveloper / gist:1697818
Created January 29, 2012 08:08
Is tag diff copy existing?
# Example of tag diff copy
$ cat file_a
unko
#START_TAG_DIFF_COPY mydiff
hoge
hage
hige
#END_TAG_DIFF_COPY
chinko
@akiradeveloper
akiradeveloper / ssh_internal_guess_psuedo
Created August 4, 2012 11:05
My Guess: How ssh command works
class SSHServer
def accept?(client)
authorized_keys.each do |public_key|
return true if client.has?( private_key_of(public_key) )
end
return false unless permit_password_authentification
return true if client.respond(password)
return false
end
end
@akiradeveloper
akiradeveloper / gist:3309738
Created August 10, 2012 00:51
inadequate exit
zshpath=`which zsh`
if [ $? -ne 0 ]
then
exit
fi
if [ $SHELL = $zshpath ]
then
exit
fi