Skip to content

Instantly share code, notes, and snippets.

@skalahonza
skalahonza / ExceptionMiddleware.cs
Created April 22, 2019 09:06
Middle for caching exceptions on .net core web API.
public class ErrorHandlingMiddleware
{
private readonly RequestDelegate _next;
public ErrorHandlingMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
@skalahonza
skalahonza / sm.hs
Last active January 3, 2019 14:59
State machine solving a language problem
-- http://math.feld.cvut.cz/demlova/teaching/jag/cjag812.pdf cviceni 12.1
automat :: String -> Bool
automat input = automat_h input 0 False
automat2 :: String -> Bool
automat2 input = automat_h2 input ['z'] 1
automat_h :: String -> Int -> Bool -> Bool
automat_h ('a':xs) count False = automat_h xs (count + 1) False
@skalahonza
skalahonza / gitlab.ps1
Last active October 12, 2018 16:55
Gitlab timetracking and issues loading (powershell script)
$apiKey = "your api key"
$gitlabhost = "https://gitlab.yourcompany.com"
$headers = @{
'PRIVATE-TOKEN'="$apiKey"
"Accept-Charset" = "utf-8"
"Accept" = "application/json"
"Content-Type" = "application/json; charset=utf-8"
}
@skalahonza
skalahonza / gist:dab9d86b3f6c067589c4c2b6431ba648
Created June 6, 2018 16:38
Basic statistic means in haskell.
harmonicMean :: [Double] -> Double
harmonicMean list = (doubleLength list) / sumo where
sumo = (sum twisted)
twisted = (map inv list)
geometricMean :: [Double] -> Double
geometricMean list = (product list) ** (1/(doubleLength list))
arithmeticMean :: [Double] -> Double
arithmeticMean list = (sum list) / (doubleLength list)
@skalahonza
skalahonza / queue.hs
Created June 6, 2018 16:37
Queue implementation in haskell using 2 stacks.
module QueueStacks where
type Stack v = [v]
push :: v -> Stack v -> Stack v
push value stack = value:stack
pop :: Stack v -> Stack v
pop [] = []
pop (_:newStack) = newStack
@skalahonza
skalahonza / queue.rkt
Created June 6, 2018 16:37
Queue implementation in scheme using 2 stacks.
(define first car)
(define second cadr)
(define rest cdr)
(define (third list) (car (cddr list)))
(define fourth cadddr)
(define (push v st)
(cons v st))
@skalahonza
skalahonza / map.hs
Created May 23, 2018 11:32
Map implementation in Haskell (trivia stupid and slow)
type KeyVal a b = (a, b)
type Map a b = [KeyVal a b]
test = initmap ["a","b","c"] [1,2,3]
myZip (k:ks) (v:vs) = [(k,v)] ++ myZip ks vs
myZip [] [] = []
get_key (a, b) = a
get_val (a, b) = b
@skalahonza
skalahonza / map.rkt
Last active May 23, 2018 11:30
Trivia map implementation in scheme (really stupid and slow)
(define first car)
(define second cadr)
(define rest cdr)
(define (third list) (car (cddr list)))
(define fourth cadddr)
(define initmap '())
(define test
(list (list 'a 1) (list 'b 3))
@skalahonza
skalahonza / hanoi.rkt
Created May 23, 2018 11:29
Hanoi tower solver for three towers, return list of tupples (actsions) --> (from, to)
; list of actions
; - n počet disků
; move tower to c
; last stage to 2
(define (hanoi n a b c)
(cond
((eq? n 1) (list(cons a b))) ; jedno patro dám rovnou na b
(#t (append (hanoi (- n 1) a c b) (list(cons a b))
@skalahonza
skalahonza / nim.hs
Created May 17, 2018 20:19
NIM game (5,4,3,2,1)
-- board type definition for game board
type Board = [Int]
initBoard :: Board
initBoard = [5,4,3,2,1]
-- player tpye definition
data Player = P1 | P2 deriving Show
nextP :: Player -> Player
nextP P1 = P2
nextP P2 = P1