Skip to content

Instantly share code, notes, and snippets.

-- docker run -i -t -v /Users/<<home>>/workspace/hask:/tmp/app debian
import Text.Parsec
import Text.Parsec.String (Parser)
import Data.Maybe
data Item = Item (String, Int) deriving Show
data RGB = RGB Int Int Int deriving Show
data Game = Game Int [RGB] deriving Show
puzzle :: (Int, Int, Int) -- RGB
@presci
presci / Dockerfile
Created February 9, 2024 15:29
Dockerfile for haskell
FROM debian:bullseye-slim
RUN mkdir -p /usr/share/man/man1
# Update packages and install dependencies
RUN apt-get update && apt-get -y install \
git \
ca-certificates \
bash \
vim \
gawk sed grep bc coreutils wget zip \
@presci
presci / parsinghask.hs
Created December 16, 2023 00:41
you need to consume all the whitespace after the match
-- Notes https://www.cs.utoronto.ca/~trebla/CSCC24-2023-Summer/08-parsing.html#token
import Text.Parsec
import Text.Parsec.String (Parser)
-- Parsec parser for a single integer
integerParser :: Parser Int
integerParser = (read <$> many1 digit) <* many space
module SudUtils(module SudUtils) where
import qualified Data.Vector as V
import Data.Maybe
import Data.List (sort, group)
-- sudoku
data Cell = Cell Int | Cells [Int] deriving Show
import SudUtils
import qualified Data.Vector as V
import Data.Maybe
import Data.List (sort, group)
-- / end initialization code
solve :: Board -> Board
solve vec = V.imap (\i rw -> update i rw) vec
import qualified Data.Vector as V
import Data.Maybe
data IsNew = N|O deriving (Show)
data Cell = Cell Int Int IsNew deriving (Show)
instance Eq Cell where
(==) (Cell x0 y0 _) (Cell x1 y1 _) = x0 == x1 && y0 == y1
@presci
presci / jaxbconverter.java
Created May 9, 2022 18:50
jaxb converter
public static final AcctProductMapGetResT util(String str) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(AcctProductMapGetResponseT.class,
AcctProductMapGetResT.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
JAXBElement<AcctProductMapGetResponseT> jresp = unmarshaller.unmarshal(
new StreamSource(new ByteArrayInputStream(str.getBytes())), AcctProductMapGetResponseT.class);
AcctProductMapGetResponseT resp = jresp.getValue();
Assert.assertNotNull(resp);
return resp.getResponse();
@presci
presci / gist:66cc9ee8452e612ae02f7983188f6aa3
Created April 22, 2022 18:21
List dependency from maven
mvn dependency:tree | grep jar | grep INFO | awk -F"-" '{print $2}' | grep jar | awk -F":" '{gsub (/\./, "\/", $1); print $1"/"$2"/"$4"/*.jar" }'
module Main where
import qualified Data.Vector as V
import Data.Maybe
import Data.Ord
-- manacher algorithm
-- $ ghci
-- $ :l manacher.hs
-- > manacher "aba"
manacher :: String -> String
@presci
presci / build.sh
Created February 18, 2022 01:02
Continuous build script
#!/bin/bash
SHASUM="HELLO WORLD"
while true; do
FILENAME=`ls -ltrap *.hs | grep -v / | awk '{print $9}' | tail -1`
tmp_SHASUM=`shasum $FILENAME`
# echo "$tmp_SHASUM"
if [ "$SHASUM" != "$tmp_SHASUM" ]; then
# echo "Strings are not equal"