Skip to content

Instantly share code, notes, and snippets.

View kayvank's full-sized avatar
🏠
@127.0.0.1

Kayvan ≅ کیوان kayvank

🏠
@127.0.0.1
View GitHub Profile
@kayvank
kayvank / flake.nix
Created December 28, 2024 19:22
nix flake to create a simple shell script
{
description = "A better simple script flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {self, nixpkgs, flake-utils}:
flake-utils.lib.eachDefaultSystem (system:
let
@kayvank
kayvank / vector.hs
Created December 22, 2024 21:42
Haskell Vectors
#!nix-shell --pure -p "haskellPackages.ghcWithPackages(pkgs:[pkgs.text pkgs.bytestring pkgs.vector])" -i runghc
{- |
haskell vectors
-}
import qualified Data.ByteString.Lazy.Char8 as C8Lazy
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as MV
import qualified Data.Maybe as Maybe
@kayvank
kayvank / st-monad.hs
Created December 22, 2024 18:13
Monad/ST
#!/usr/bin/env nix-shell
#!nix-shell --pure -p "haskellPackages.ghcWithPackages(pkgs:[pkgs.text pkgs.bytestring])" -i runghc
{- |
Linked list using ST Monad
This is based on @Evgenity work, https://www.youtube.com/watch?v=MJscn-m4KIo
-}
{-#language RecordWildCards #-}

plutus-tx upgrade

Upgrade trustless-sidechain ghc and plutus-tx per code review from the plutus team.

Problem

We can not upgreade to newer versions of plutus-tx. Consequently, we can not upgrade to newer cardano-node. The nature of upgrade is very similar to this snipet of code:

import PlutusLedgerApi.Common (serialiseCompiledCode)
import Data.ByteString.Short (fromShort)
@kayvank
kayvank / brokenlinks.py
Last active August 1, 2024 12:47
find-broken-http-links
@kayvank
kayvank / signalHandler.hs
Last active June 24, 2024 17:09
Haskell Signal Handler
#!/usr/bin/env nix-shell
#!nix-shell --pure -p "haskellPackages.ghcWithPackages (pkgs: [])" -i "runghc"
{-
Installing unix signal handler
-}
import Control.Concurrent (threadDelay)
import Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar,
tryTakeMVar)
import System.Posix.Signals (Handler (CatchOnce), installHandler,
@kayvank
kayvank / leftJoin.sql
Last active March 21, 2023 23:56
left sql join
-- Sample left join
-- see for more detail, https://www.tutorialspoint.com/sql/sql-left-joins.htm
-- to execute:
-- sqlite3 ./db < leftjoin.sql
--
drop table if exists U;
drop table if exists S;
create table if not exists U (address text, txid text, txix int , unique (txid, txix) );
create table if not exists S (txid text, txix int, unique (txid, txix));
@kayvank
kayvank / cli.hs
Created November 8, 2022 14:45
optparse-applicative for cli params of Maybne NonEmptyList
#!/usr/bin/env stack
{- stack
script
--resolver lts-18.28
--package async
--package optparse-applicative
--package text
-}
import Data.List.NonEmpty (NonEmpty, fromList)
import Data.Semigroup ((<>))
@kayvank
kayvank / streamSqlite.hs
Last active October 27, 2022 12:47
streamSqlite.hs
#!/usr/bin/env stack
{- stack
script
--resolver lts-18.28
--package sqlite-simple
--package async
--package text
-}
{-
-- | the purpose of this code is to make sure sqlite maybe accessed concurrently
@kayvank
kayvank / defaultParams.sh
Last active October 27, 2022 12:48
node-cli query
## first node must sync:
#####################################
$ cardano-cli query tip --mainnet
{
"block": 7937358,
"epoch": 371,
"era": "Babbage",
"hash": "f580eb4778f57fc5dbbd138ebcb89341239447a9438b13dc2eaccf5bb1c34e17",
"slot": 75306292,
"syncProgress": "100.00"