Skip to content

Instantly share code, notes, and snippets.

View jhrcek's full-sized avatar

Jan Hrcek jhrcek

View GitHub Profile
@jhrcek
jhrcek / SpeechSynthesisDemo.html
Last active December 21, 2016 07:02
Google chrome Speech synthesis API demo
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Chrome Speech Synthesis API Demo</title>
<script>
var utterance
function readText() {
var text = document.getElementById('textInput').value;
utterance = new SpeechSynthesisUtterance(text);
@jhrcek
jhrcek / bookmarklet.js
Last active January 30, 2017 20:47
Include elm-generated JS on 3rd party web page
javascript:(function() {
var elmDiv = document.createElement("div");
elmDiv.id="elm";
var elmJs = document.createElement("script");
elmJs.src="//bit.ly/2eMDpH9";
elmJs.onload=function() {
var node = document.getElementById('elm');
Elm.Main.embed(node);
};
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Test where
import Data.Aeson
import Data.ByteString.Lazy (ByteString)
import Data.ByteString.Lazy.Char8 (pack)
import HAR.Entry
import Text.RawString.QQ (r) -- raw-strings-qq
main :: IO ()
@jhrcek
jhrcek / Tree.elm
Created May 10, 2017 17:04
Tree labeling using State monad
module Tree
exposing
( Tree(Node)
, NodeId
, CollapsibleTree
, makeTree
)
--Using http://package.elm-lang.org/packages/folkertdev/elm-state/2.1.0
@jhrcek
jhrcek / DecodeExample.elm
Last active June 9, 2017 09:57
How to remove union type parsing boilerplate?
---- BOILER-PLATEY version I'd like to make more succint - I've got 15 simple union types like this and don't want to declare decoder for each of them like this..
type Severity
= INFO
| WARN
| ERROR
decodeSeverity : Decoder Severity
decodeSeverity =
@jhrcek
jhrcek / TooVerbose.elm
Last active September 7, 2017 03:20
How to get info about which of the cases is currently "selected" more conscisely?
type LoanTerm
= LessThan Int
| Between Int Int
| MoreThan Int
isLess : LoanTerm -> Bool
isLess amt =
case amt of
LessThan _ ->
True
@jhrcek
jhrcek / InteractiveWebDriver.hs
Created October 24, 2017 00:49
Demonstration of how Haskell's WebDriver library can be used Interactively in GHCi
{-# LANGUAGE OverloadedStrings #-}
import Test.WebDriver.Commands (Selector (ById, ByName), click, closeSession,
findElem, openPage, sendKeys)
import Test.WebDriver.Config (defaultConfig)
import Test.WebDriver.Monad (runSession, runWD)
import Test.WebDriver.Session (getSession)
-- These commands can be executed one by one in GHCi
-- (! Note that this is not a recommended way to use webdriver library
-- normally you'd use runSession to hide explicit session handling !)
@jhrcek
jhrcek / servant-basic-auth-example.hs
Last active April 5, 2019 05:48
servant-client basic auth example, calling httpbin.org
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
module Main where
import Data.Aeson (FromJSON, ToJSON)
import Data.Proxy (Proxy (Proxy))
import Data.Text (Text)
#!/usr/bin/env stack
-- stack script --resolver lts-10.8 --package http-client-tls,http-conduit,bytestring
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Lazy.Char8 as L8
import Network.HTTP.Client.TLS (setGlobalManager)
import Network.HTTP.Conduit (newManager, tlsManagerSettings)
import Network.HTTP.Simple (getResponseBody, getResponseHeader,
getResponseStatusCode, httpLBS,
setRequestManager)
main :: IO ()
@jhrcek
jhrcek / WatchDir.hs
Last active May 17, 2018 10:35
Haskell script using fsnotify to watch for filesystem events in given dir
#!/usr/bin/env stack
-- stack script --resolver lts-10.9 --package fsnotify
{-# LANGUAGE OverloadedStrings #-}
import Control.Concurrent (threadDelay)
import Control.Monad (forever)
import System.Environment (getArgs)
import System.FSNotify (watchTree, withManager)
main :: IO ()