Skip to content

Instantly share code, notes, and snippets.

View aerohit's full-sized avatar

Rohit Saxena aerohit

View GitHub Profile
@aerohit
aerohit / Playground.hs
Created December 10, 2021 09:23
Plutus Playground Smart Contract
-- Vesting scheme as a PLC contract
import Control.Lens (view)
import Control.Monad (void, when)
import Data.Default (Default (def))
import Data.Map qualified as Map
import Data.Text qualified as T
import Ledger (Address, POSIXTime, POSIXTimeRange, PubKeyHash, Validator)
import Ledger.Ada qualified as Ada
import Ledger.Constraints (TxConstraints, mustBeSignedBy, mustPayToTheScript, mustValidateIn)
@aerohit
aerohit / StringTextByteString.hs
Created September 26, 2020 05:31
Convert between String Text And ByteString
-- Reference: Ecky Putrady, Practical Web Development with Haskell, Table 2-1
String Text fromString
String LText fromString
String ByteString fromString
String LByteString fromString
Text LText fromStrict
Text ByteString encodeUtf8
Text LByteString (fromStrict . encodeUtf8)
Text String unpack
@aerohit
aerohit / TaglessFinalMockDataKinds.hs
Created August 21, 2020 06:01
Unit testing Tagless Final approach using DataKinds for mocking
import Control.Monad.Reader
import Control.Monad.Identity
import Test.Hspec
-- Reference: https://chrispenner.ca/posts/mock-effects-with-data-kinds
newtype UserName = UserName String deriving (Eq, Show, Ord)
newtype Data = Data String deriving (Show, Eq)
newtype AppConfig = AppConfig String deriving Show
newtype LogMsg = LogMsg String deriving Show
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
module HZK202007080846
()
where
import Control.Monad.Identity
import Test.Hspec
-- TAGS :tagless-final:
@aerohit
aerohit / TaglessFinalEg.hs
Last active July 9, 2020 05:36
Unit testing Tagless Final
-- Reference: https://jproyo.github.io/posts/2019-03-17-tagless-final-haskell.html
newtype UserName = UserName String deriving Show
newtype DataResult = DataResult String deriving (Show, Eq)
newtype AppConfig = AppConfig String deriving Show
newtype LogMsg = LogMsg String deriving Show
class Monad m => Cache m where
getFromCache :: UserName -> m (Maybe DataResult)
@aerohit
aerohit / argonaut.scala
Created February 23, 2018 15:35
argonaut sum types
import com.vimpelcom.ep.common.Msisdn
import org.scalatest.FunSpecLike
import org.scalatest.Matchers
import argonaut._
import Argonaut._
sealed trait ChallengeProof2FAOutcome
case class ChallengeProof2FAFailure(status: String, meta: String) extends ChallengeProof2FAOutcome

Keybase proof

I hereby claim:

  • I am aerohit on github.
  • I am aerohit (https://keybase.io/aerohit) on keybase.
  • I have a public key whose fingerprint is 9E92 688A 437A CE34 9B38 ACA6 B11A 9D6E 1EAE 35CB

To claim this, I am signing this object:

<html>
<body>
<script src="https://blockexplorer.com/socket.io/socket.io.js"></script>
<script>
eventToListenTo = 'tx'
room = 'inv'
var socket = io("https://blockexplorer.com/");
socket.on('connect', function() {
// Join the room.
@aerohit
aerohit / Communicator.scala
Last active July 2, 2017 09:32
The Communicator
// Taken from this blog post:
// http://ane.github.io/2016/10/14/communicator-functional-actors.html
import akka.actor.Actor
import akka.actor.ActorRef
import scala.concurrent.Future
trait Communicator[State, Input, Output] extends Actor {