Skip to content

Instantly share code, notes, and snippets.

Avatar

Maciej Smolinski maciejsmolinski

View GitHub Profile
@maciejsmolinski
maciejsmolinski / parser.hs
Last active May 4, 2021
Putting into practice lessons learned from "Write Yourself a Scheme in 48 hours" book https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours/Parsing
View parser.hs
module Main (main) where
import Prelude
import System.Environment
import Control.Monad
import Text.ParserCombinators.Parsec
main :: IO ()
main = do
(text:_) <- getArgs
View index.js
const daggy = require('daggy');
const Status = daggy.taggedSum('Status', {
Pending: [],
Done: [],
Failed: ['reason'],
});
const jobs = [
{ id: 1, status: Status.Pending },
View index.html
<!DOCTYPE html>
<html>
<head>
<title>A simple d3 chart</title>
<meta charset="UTF-8" />
</head>
<body>
<div id="app">
<svg id="viz"></svg>
View Main.purs
module Main where
import Prelude
import Effect (Effect)
import Data.Maybe (Maybe(..))
import React (ReactElement)
import React.DOM (text)
import ReactDOM (render)
import Web.HTML (window)
View Parser.purs
module Parser (Parser, item, digit, run) where
import Data.Int (fromString)
import Data.Maybe (fromJust, Maybe(..))
import Data.String.CodeUnits (charAt, drop, singleton)
import Data.Tuple (Tuple(..))
import Partial.Unsafe (unsafePartial)
import Prelude
newtype Parser a = Parser (String -> Array (Tuple a String))
@maciejsmolinski
maciejsmolinski / Main.purs
Created May 20, 2020
Simple EDSL in PureScript
View Main.purs
module Main where
import Data.Traversable (traverse_)
import Effect (Effect)
import Effect.Console (logShow)
import Prelude
data Expression
= Num Int
| Add Expression Expression
@maciejsmolinski
maciejsmolinski / purescript.md
Last active Jun 6, 2018
Create ES6 + PureScript application in 4 simple steps
View purescript.md
@maciejsmolinski
maciejsmolinski / mock.hs
Created May 26, 2018
Mocking in Haskell
View mock.hs
data Article = Article
{ title :: String
, body :: String
} deriving (Show)
articles :: IO [Article]
articles =
return
[ Article
{ title = "First article"
@maciejsmolinski
maciejsmolinski / morning.js
Created May 26, 2018
Good Morning Haskell
View morning.js
data Mood = Good | Bad
deriving (Show)
morning :: Mood -> String
morning mood = show mood ++ " Morning!"
main :: IO ()
main = putStrLn $ morning Good
View sanctuary-validations.js
const validations = {
address: (street, postcode, city) => {
if (street && postcode && city) {
return S.Right(`${street}, ${postcode}, ${city}`)
}
return S.Left(`Incorrect address provided (${street}, ${postcode}, ${city})`);
},
email: (email) => {
if (/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(email)) {