Skip to content

Instantly share code, notes, and snippets.

@kgadek
kgadek / step1-host.sh
Last active Feb 28, 2021
Debian on ZFS root on Raspberry Pi 4
View step1-host.sh
### Prepare SD card or USB disk for first boot.
### Executed as `root` on some host.
### -------------------------------------------
### Customize:
export DISKNAME=sda
export RASPI_IMG=20201112_raspi_4
### -------------------------------------------
@kgadek
kgadek / zdb.sh-session
Last active Feb 5, 2021
ZoL RPi4 debugging
View zdb.sh-session
root@spongebob:~# zdb -l /dev/mmcblk1
failed to unpack label 0
failed to unpack label 1
------------------------------------
LABEL 2
------------------------------------
version: 5000
name: 'rpool'
state: 1
txg: 78726
View boot0.sh
#!/usr/bin/env sh
# vim: foldmethod=marker
# ------------------------------------------------------------------------------
# Run in cloud-init.
# ------------------------------------------------------------------------------
# {{{ Configuration
: "${user:=konrad}"
# }}}---------------------------------------------------------------------------
#{{{ users: add $user
View bumpme
Wed Jan 16 16:30:53 UTC 2019
@kgadek
kgadek / kata_brainfuck.hs
Created May 1, 2015
Brainfuck interpreter with handcrafted lenses. Catamorphism not included though :<
View kata_brainfuck.hs
{-# LANGUAGE RankNTypes, RecordWildCards #-}
import Data.Char
import Data.Functor.Identity
import Control.Applicative
{-
Inspired from real-world Brainf**k, we want to create an interpreter of that language which will
support the following instructions (the machine memory or 'data' should behave like a potentially
infinite array of bytes, initialized to 0):
@kgadek
kgadek / FunSetSuite.scala
Created Oct 5, 2012
Scala: bughunting in assignment from Coursera's course
View FunSetSuite.scala
package funsets
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
/**
* This class is a test suite for the methods in object FunSets. To run
* the test suite, you can either:
View core.hs
stuff :: Maybe Int
stuff = return (456 :: Int)
main :: IO ()
main = do
let Just x = stuff
print x
View harrop_ghc.hs
-- stack --resolver nightly-2017-02-08 ghc --package hashtables -- -O2 harrop_ghc.hs
import Control.Monad
import qualified Data.HashTable.IO as H
type HashTable k v = H.BasicHashTable k v
main = do
m <- H.new :: IO (HashTable Int Int)
forM_ [1..10000000] $ \n -> H.insert m n n
v <- H.lookup m 100
View stuff.hs
runWithMock :: MockDirectoryTree -> FSops r -> [String]
runWithMock mockTree = cata eval
where
eval :: TF.FreeF FSopsF r [String] -> [String]
eval (TF.Free x@ListDir{}) = msg : cont
where
msg = printf "LISTDIR: %s\n RESULT: %s\n" (x ^. dirName) (show dirListing)
dirListing = DirectoryListing immediateDirs immediateFiles
immediateDirs = mockTree ^.. unFix2 . mDirs . each . rootDirName
immediateFiles = mockTree ^. unFix2 . mFiles
View imad.sh
# Przygotowanie
xcode-select --install # akceptacja licencji Xcode
curl -sSL https://get.haskellstack.org/ | sh # alternatywnie: brew install haskell-stack
git clone https://github.com/kgadek/novelist.git
cd novelist
stack setup # instalacja kompilatora lokalnie, w ~/.stack
stack build --bench --no-run-benchmarks # kompilacja programu
# Uruchamianie testów
stack bench