Skip to content

Instantly share code, notes, and snippets.

View symbiont-eric-torreborre's full-sized avatar
🏠
Working from home

Eric Torreborre symbiont-eric-torreborre

🏠
Working from home
View GitHub Profile
@symbiont-eric-torreborre
symbiont-eric-torreborre / global.scala
Created August 2, 2019 06:45
api for global resources in specs2
// This describe a more or less ideal API for global resources management
// This trait allows to insert setup/teardown actions guaranteed to execute only once
// and making sure that the teardown action will always happen at the end of the
// specification execution
trait GlobalBeforeAfter extends SpecificationStructure with FragmentsFactory {
def globalBefore: Fragment
def globalAfter: Fragment
override def map(fs: =>Fragments): Fragments = super.map(fs).prepend(
import qualified System.Console.Concurrent as Concurrent
trace :: [Char] -> a -> a
trace string expr =
unsafePerformIO $ do
traceIO string
return expr
traceIO :: [Char] -> IO ()
traceIO string = do
@symbiont-eric-torreborre
symbiont-eric-torreborre / pull-images.sh
Created August 28, 2019 13:36
Pull images for given tag
# for example
TAG=dade6249f8206e13150f464ad2b0df4cc1a07bd5
for i in 'sailfish' 'smartlog' 'epilog' 'apollo' 'api-server' 'txe' 'txe-postgres' 'api-server'; do docker pull us.gcr.io/development-148212/$i:$TAG; done
@symbiont-eric-torreborre
symbiont-eric-torreborre / log-files.sh
Last active April 8, 2020 14:42
Process log files
# find all txe log files from pod logs and copy them locally with an incrementing number
# 0.log, 1.log, 2.log, 3.log
# this uses:
# - https://github.com/sharkdp/fd (fast alternative to find)
# - https://github.com/BurntSushi/ripgrep (fast alternative to rg)
fd 0.log | rg txe | cat -n | while read n f; do cp -n "$f" "$n.log"; done
# extract the 'message' field from each log file and write it to txe-1.log,
# txe-2.log, txe-3.log, txe-4.log
for i in 1 2 3 4; do cat ~/Downloads/symbiont/logs/$i.log | jq '.log | fromjson | .message' > txe-$i.log; done
@symbiont-eric-torreborre
symbiont-eric-torreborre / snapshots-jq.sh
Created April 13, 2020 11:19
update snapshot files with jq
# remove publish payloads for versions 1-5
for i in {1..5}; do cat $i.json | jq -c '.channelActionAndSequencedTransaction |= map(select(.[1].contents[4].tag != "Publish"))' | jq --indent 4 . > $i-x.json; rm $i.json; mv $i-x.json $i.json; done
# remove publish payloads for version 6
for i in {6..6}; do cat $i.json | jq -c '.channelActionAndSequencedTransaction |= map(select(.[2][4].tag != "Publish"))' | jq --indent 4 . > $i-x.json; rm $i.json; mv $i-x.json $i.json; done
# remove publish payloads for versions 7-8
for i in {7..8}; do cat $i.json | jq -c '.channelActionAndSequencedTransaction |= map(select(.[2].wcaChannelAction.tag? != "Publish"))' | jq --indent 4 . > $i-x.json; done
DROP DATABASE IF EXISTS state_db;
DROP ROLE IF EXISTS datadog;
DROP ROLE IF EXISTS txe;
DROP ROLE IF EXISTS sailfish;
DROP ROLE IF EXISTS api_server;
CREATE DATABASE state_db;

testSpec "testing lists" $describe "Prelude.head" $ do it "returns the first element of a list" $ do head [23 ..]shouldBe` (23 :: Int)

it "throws an exception if the list is empty" $
  head [] `shouldThrow` anyException

testCase "Example test case" $ do assertBool "arithmetic is still sane" $ 2 + 2 == 4

testCase "Example test case" $ do
assertBool "arithmetic is still sane" $ 2 + 2 == 4
@symbiont-eric-torreborre
symbiont-eric-torreborre / concurrent-map.hs
Created December 4, 2020 07:32 — forked from Gabriella439/concurrent-map.hs
Low-tech concurrent hashmap
module ConcurrentMap where
import Control.Concurrent.STM.TVar (TVar)
import Control.Concurrent.STM (STM)
import Data.Hashable (Hashable)
import Data.HashMap.Strict (HashMap)
import Data.Vector (Vector)
import qualified Control.Concurrent.STM.TVar as TVar
import qualified Data.Hashable as Hashable