Skip to content

Instantly share code, notes, and snippets.

View kazu-yamamoto's full-sized avatar
💭
QUIC and TLS 1.3

Kazu Yamamoto kazu-yamamoto

💭
QUIC and TLS 1.3
View GitHub Profile
@kazu-yamamoto
kazu-yamamoto / gist:9266343
Created February 28, 2014 06:31
errno is Haskell thread local
{-# LANGUAGE ForeignFunctionInterface #-}
import Control.Concurrent
import Foreign.C.Types
import Foreign.C.Error
main :: IO ()
main = do
s <- c_socket 2 1 0
forkIO $ do
@kazu-yamamoto
kazu-yamamoto / gist:8951304
Last active August 29, 2015 13:56
autoupdate2
{-# LANGUAGE DeriveDataTypeable, RankNTypes #-}
-- FIXME: should we replace Data with System?
module Data.AutoUpdate where
import Control.Applicative ((<$>))
import Data.IORef
import Control.Concurrent (threadDelay, forkIOWithUnmask)
import Control.Monad (forever, void)
import Control.Exception (Exception, SomeException(..), handle, catches, throwIO, assert, Handler(..), mask)
import Data.Typeable (Typeable)
@kazu-yamamoto
kazu-yamamoto / gist:8949722
Last active August 29, 2015 13:56
autoupdate
{-# LANGUAGE DeriveDataTypeable #-}
-- FIXME: should we replace Data with System?
module Data.AutoUpdate where
import Control.Applicative ((<$>))
import Data.IORef
import Control.Concurrent (threadDelay, forkIO, ThreadId, myThreadId)
import Control.Monad (forever)
import Control.Exception (throwTo, Exception, handle, fromException, throwIO, assert, SomeException)
import Data.Typeable (Typeable)
@kazu-yamamoto
kazu-yamamoto / gist:8298153
Created January 7, 2014 11:41
Text as euc-jp
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.Text as T
import qualified Data.Text.IO as T
import System.IO
main :: IO ()
main = do
{-# LANGUAGE DeriveDataTypeable #-}
module A where
import Data.Typeable (Typeable)
import Data.Generics (everywhere, mkT, Data)
data T = Tree [U] deriving (Show,Data,Typeable)
data U = I Int | T T deriving (Show,Data,Typeable)
@kazu-yamamoto
kazu-yamamoto / gist:8120392
Created December 25, 2013 05:21
Simple JSON parser in Haskell
-- | This JSON package retains the order of array elements.
-- JSON: http://www.ietf.org/rfc/rfc4627.txt
module JSON (
JSON(..)
, parseJSON
) where
import Control.Applicative ((<*),(*>),(<$>),(<$))
import Control.Monad (void)
@kazu-yamamoto
kazu-yamamoto / gist:7763892
Last active December 30, 2015 02:39
Memoized longest common subsequence
module LCS where
import Data.Function.Memoize
data Z = A | B | C | D | G | T | X deriving (Eq,Enum,Show)
x1 :: [Z]
x1 = [A,B,C,B,D,A,B]
y1 :: [Z]
y1 = [B,D,C,A,B,A]
@kazu-yamamoto
kazu-yamamoto / gist:7480057
Created November 15, 2013 06:28
Yesod: returning a static file if path for dynamic contents is wrong. This code set Status to 200.
{-# LANGUAGE OverloadedStrings, QuasiQuotes, TemplateHaskell, TypeFamilies #-}
import Yesod
import Network.HTTP.Types (status200)
data App = App
mkYesod "App" [parseRoutes|
/home HomeR GET
|]
@kazu-yamamoto
kazu-yamamoto / gist:7461668
Created November 14, 2013 05:01
ELisp configuration for Haskell
(load "haskell-site-file")
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(add-hook 'haskell-mode-hook 'turn-on-font-lock)
(defun haskell-style ()
"Sets the current buffer to use Haskell Style. Meant to be
added to `haskell-mode-hook'"
(setq tab-width 4
haskell-indentation-layout-offset 4
haskell-indentation-left-offset 4
@kazu-yamamoto
kazu-yamamoto / gist:6290998
Last active December 21, 2015 10:19
Dynamic programming from Algorithm Introduction (stations)
-- Dynamic programming from Algorithm Introduction
module Stations where
import Control.Arrow
import Data.Array
import Data.Function.Memoize
data Line = Line {
_size :: Int
, _e1 :: Int