Skip to content

Instantly share code, notes, and snippets.

View HirotoShioi's full-sized avatar
🎯
Focusing

Hiroto Shioi HirotoShioi

🎯
Focusing
View GitHub Profile
@HirotoShioi
HirotoShioi / validity.hs
Created March 1, 2019 07:07
Working example of validity library
{-|
-- dependencies:
-- - base >= 4.7 && < 5
-- - validity
-- - hspec
-- - genvalidity
-- - genvalidity-hspec
-}
{-# LANGUAGE DeriveGeneric #-}
import Control.Exception
import Control.Monad (forever, void)
import Data.Char (toUpper)
import GHC.IO.Handle.FD (fdToHandle)
import Prelude
import System.Exit
import System.IO (BufferMode (..), hGetLine, hPrint,
hPutStrLn, hSetBuffering, hClose)
import System.Posix.Process (exitImmediately, forkProcess)
import System.Process (createPipe, createPipeFd)
@HirotoShioi
HirotoShioi / IPC.hs
Created February 21, 2019 04:12
IPC
module IPC where
import Control.Monad (forever)
import Data.Char (toUpper)
import GHC.IO.Handle.FD (fdToHandle)
import Prelude
import System.IO (BufferMode (..), hGetLine, hPrint,
hPutStrLn, hSetBuffering)
import System.Posix.Process (forkProcess)
import System.Process (createPipeFd)
module Parser.Test where
import RIO hiding (try, (<|>))
import Text.ParserCombinators.Parsec
data Block = List [Block] | ListItem String
deriving Show
-- | Parser for 'BulletPoint'
@HirotoShioi
HirotoShioi / inlineparser.hs
Created January 17, 2019 05:42
(WIP) parser
{-# LANGUAGE OverloadedStrings #-}
module TestScrapbox where
import Data.Maybe (isJust)
import Data.String (fromString)
import Data.Text (Text)
import qualified Data.Text as T
import Text.ParserCombinators.Parsec
@HirotoShioi
HirotoShioi / table.hs
Created December 25, 2018 05:23
Markdown table parser
{-# LANGUAGE OverloadedStrings #-}
module Table where
import Control.Monad
import Data.Attoparsec.Text as P
import Data.Text (Text)
import qualified Data.Text as T
data Table = Table [Column]
@HirotoShioi
HirotoShioi / V2
Created December 13, 2018 04:44
Made some visual improvements so that the structure can be somewhat readable
Markdown
[ Document ( ScrapText [ Context NoStyle [ SimpleText "Get started" ] ] )
, Thumbnail ( Url "https://gyazo.com/5f93e65a3b979ae5333aca4f32600611" )
, Document ( ScrapText [ Context NoStyle [ SimpleText "Welcome to your new Scrapbox project!" ] ] )
, BreakLine
, Header ( HeaderSize 2 ) [ SimpleText "📝 Everything is editable" ]
, BreakLine
, BulletLine ( BulletSize 1 ) ( ScrapText [ Context NoStyle [ SimpleText "Click on any line and start typing to edit. " ] ] )
, BreakLine
, BulletLine ( BulletSize 2 ) ( ScrapText [ Context NoStyle [ SimpleText "Press tab at the beginning of a line to indent and add a bullet point." ] ] )
@HirotoShioi
HirotoShioi / getStartedData
Created December 12, 2018 07:51
Current idea of structuring Scrapbox content data sample: https://scrapbox.io/toSrapbox/Get_started
Markdown
{ getMarkdown =
[ Simple
( ScrapText
{ getScrapText =
[ Scrap
{ scrapStyle = NoStyle
, scrapContent = [ PlainText "Get started" ]
}
]
@HirotoShioi
HirotoShioi / dhall.hs
Created November 29, 2018 02:13
Done!!!!
import Dhall (Interpret (..), Inject(..))
import qualified Dhall as D
import Dhall.Core (pretty)
import qualified Data.Text as T
import GHC.Generics
import Control.Monad.Trans.State.Strict (evalState)
import Data.Functor.Contravariant
data Person = Person {
pName :: !Text
@HirotoShioi
HirotoShioi / Trie.hs
Created September 15, 2018 03:17
Trie tree arbitrary instance
-- |A @'Trie' a b@ is a map with keys of type @[a]@ and values of type @b@.
data Trie a b = Fork (Maybe b) (Map a (Trie a b))
deriving (Show, Eq)
instance (Ord a, Arbitrary a, Arbitrary b) => Arbitrary (Trie a b) where
arbitrary :: Gen (Trie a b)
arbitrary = sized $ \n -> if n == 0 -- We interpret the size n as maximum number of values
-- stored in the trie.
then return empty -- If the n == 0, the trie must be empty.