Skip to content

Instantly share code, notes, and snippets.

Avatar

Dino Morelli dino-

View GitHub Profile
@dino-
dino- / promises.js
Created Oct 7, 2021
A JavaScript promises cheat-sheet
View promises.js
// A JavaScript promises cheat-sheet
// an immediately resolved promise
const p1 = Promise.resolve('foo');
// can get it after the fact, unlike events
p1.then((res) => console.log('p1 got:', res));
// => p1 got: foo
@dino-
dino- / haskell-symbols.md
Last active Dec 30, 2022
Haskell symbols
View haskell-symbols.md

Haskell symbols

When starting out with Haskell, I found it difficult to read a lot of the symbols. I made this document explaining the names of some symbols and how I read them.

:: "has type"

x :: Int

@dino-
dino- / Playground.hs
Last active Mar 23, 2021
Plutus Playground Smart Contract
View Playground.hs
import Control.Monad ( void )
import Data.Aeson ( FromJSON, ToJSON )
import qualified Data.Text as T
import GHC.Generics ( Generic )
import Language.Plutus.Contract
import Language.PlutusTx as PlutusTx
import Language.PlutusTx.Prelude
import Ledger
import Ledger.Ada as Ada
import Ledger.Constraints as Constraints
@dino-
dino- / keybase.md
Created Jul 29, 2019
Keybase proof
View keybase.md

Keybase proof

I hereby claim:

  • I am dino- on github.
  • I am dino733 (https://keybase.io/dino733) on keybase.
  • I have a public key ASCV2424hXHoyxWn_lBsR3WEbtttYO4BTEUHwjNPPupxxQo

To claim this, I am signing this object:

View mtlex.hs
#! /usr/bin/env stack
-- stack --resolver lts-13.15 runghc --package mtl
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad.Except
main :: IO ()
main = do
@dino-
dino- / string-conversions.hs
Last active Jan 14, 2023
A handy illustration of converting between String, Text and ByteString in Haskell
View string-conversions.hs
#! /usr/bin/env stack
-- stack --resolver lts-18.8 script
{-# LANGUAGE OverloadedStrings #-}
{-
This is a handy illustration of converting between five of the commonly-used
string types in Haskell (String, ByteString, lazy ByteString, Text and lazy
Text).
@dino-
dino- / state-is-simple.hs
Created Dec 24, 2018
State in Haskell is simple
View state-is-simple.hs
#!/usr/bin/env stack
-- stack --resolver lts-12.24 script
-- If stack isn't installed on your system and you can't/won't get it, install
-- a reasonably-modern GHC and use this instead of the above two lines:
-- #! /usr/bin/env runhaskell
import Control.Monad.State
View SetNoBuffering.md

In Haskell, it's sometimes useful to turn off buffering when writing code that uses the standard input/output file handles. That can be done to the three commonly-used handles in one line like this:

  import System.IO

  mapM_ (flip hSetBuffering NoBuffering) [ stdout, stderr, stdin ]

It's kind of terse though, let's go through what's happening in it.

@dino-
dino- / haskell-flip-id.md
Last active Jul 23, 2016
The interesting type of `foldl (flip id)`
View haskell-flip-id.md

The interesting type of foldl (flip id)

System.Console.GetOpt

Going through the example code for System.Console.GetOpt got me thinking about the type of foldl (flip id)

Specifically, the second example Interpreting flags as transformations of an options record. The code is using this to combine all of the command-line args into a record of the args as a whole.

I was confused about how foldl (flip id) has the type it does

View kowey-xml.hs
#! /usr/bin/env runhaskell
import Text.HTML.TagSoup
main :: IO ()
main = do
tags <- fmap parseTags $ readFile "foo.xml";
let names = sections (~== "<name>") $ tags
mapM_ (\t -> putStrLn $ "saw: " ++ t ) $ map fromTagText
$ map (flip (!!) 1) names