Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexey Kuleshevich lehins

View GitHub Profile
View get-stack.sh
#!/bin/sh -e
#
# Stack installation script.
#
# This script is meant for quick & easy install via:
# 'curl -sSL https://get.haskellstack.org/ | sh'
# or:
# 'wget -qO- https://get.haskellstack.org/ | sh'
#
# By default, this installs 'stack' to '/usr/local/bin'.
@lehins
lehins / git-modtime.hs
Last active Mar 19, 2020
Restore file and directory modification time to the commit time
View git-modtime.hs
{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ < 802
main :: IO ()
main = do
let (ghcMaj, ghcMin) = divMod (__GLASGOW_HASKELL__ :: Int) 100
ghcVer = show ghcMaj ++ "." ++ show ghcMin
putStrLn $ "GHC version: " ++ ghcVer ++ " is not supported by git-modtime script."
#else
import Data.Time.Format (parseTimeM, iso8601DateFormat, defaultTimeLocale)
import System.Directory (setModificationTime)
@lehins
lehins / safe-decimal.hs
Created Feb 10, 2020
Example usage of safe-decimal package
View safe-decimal.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NumericUnderscores #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Lib where
import Control.Monad.State.Strict
import Control.Exception
@lehins
lehins / TypeLevelMoney.hs
Created Jan 16, 2020
Currency and money at type level
View TypeLevelMoney.hs
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
View fail-vs-case.hs
name <- atomically $ do
readTVar (currentUpdate ctxt) >>= \case
name:names <- readTVar (queuedUpdates ctxt)
writeTVar (queuedUpdates ctxt) names
return name
name <- atomically $ do
readTVar (currentUpdate ctxt) >>= \case
Just _ -> retry
Nothing -> readTVar (queuedUpdates ctxt) >>= \case
@lehins
lehins / safe-decimal.md
Last active Jan 24, 2019
Performance of safe-decimal backed by Int64 and Word64
View safe-decimal.md

Addition

Name 1 10 100 1000 10000 100000 1000000
Int 6.712 ns 11.81 ns 0.066 μs 0.606 μs 11.19 μs 0.112 ms 1.118 ms
Double 13.95 ns 29.11 ns 0.247 μs 2.272 μs 22.35 μs 0.224 ms 2.233 ms
Integer 46.33 ns 251.5 ns 1.296 μs 12.71 μs 126.4 μs 1.309 ms 19.36 ms
@lehins
lehins / stack-build-loop.hs
Created Nov 24, 2018
An infinite loop that runs `stack build` periodically killing it and restarting it again until either finished or build error occurs.
View stack-build-loop.hs
#!/usr/bin/env stack
{- stack
--resolver lts-12.2 script
--package filepath
--package rio
--package bytestring
--package time
--package random
--package process
--package unix
@lehins
lehins / Lib.hs
Last active Jun 27, 2018
Make QuickCheck instances optional, but part of the library.
View Lib.hs
{-# LANGUAGE CPP #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Lib
( someFunc
, Foo(..)
) where
-- In practice instead of CPP possibly use a separate module for optional instances
#ifdef QuickCheck_Instances
import Test.QuickCheck
@lehins
lehins / change.tf
Last active Mar 13, 2018
ELK ELB/ALB switch
View change.tf
# elasticsearch_external_alb = "${module.kibana-elasticsearch-alb.alb}"
elasticsearch_external_alb = {
"security_group_id" = "${aws_security_group.es-external-lb.id}"
"deploy_elb" = true
"deploy_elb_internal" = false
"certificate_arn" = "${data.aws_acm_certificate.wildcard-cert.arn}"
}
@lehins
lehins / cache-s3-ec2.tf
Last active Jan 8, 2019
Setting up EC2 instance and S3 bucket for cache-s3
View cache-s3-ec2.tf
terraform {
backend "s3" {
encrypt = "true"
bucket = "my-remote-tfstate-bucket"
key = "my-remote-tfstate/ec2/terraform.tfstate"
region = "us-east-1"
}
}