Skip to content

Instantly share code, notes, and snippets.

@benjaminweb
benjaminweb / string-conversions.hs
Created November 14, 2023 14:07 — forked from dino-/string-conversions.hs
A handy illustration of converting between String, Text and ByteString in Haskell
#! /usr/bin/env stack
-- stack --resolver lts-18.8 script
{-# LANGUAGE OverloadedStrings #-}
{-
This is a handy illustration of converting between five of the commonly-used
string types in Haskell (String, ByteString, lazy ByteString, Text and lazy
Text).
data Foo = Foo Int deriving (Show, Num)
addition1 = (+) <$> Just 1 <*> Just 2 -- works
addition2 = (+) <$> Foo 1 <*> Foo 2 -- how to make it work just like addition1?

1. Value of Documentation

earlier finished, higher-value, more successful projects delivered at less cost and better working conditions

Actually, appropriate documentation pays off itself multiple times — however, it is usually conceived as too expensive, superfluous.

Appropriate documentation

TODO: reduce to non-project management items only

@benjaminweb
benjaminweb / gist:e067563f586b7d36f785ddd2d737747a
Created January 4, 2019 20:26
URL encode params with req
import Network.HTTP.Req
main = do
let params =
"foo" =: ("bar" :: Text) <>
queryFlag "baz"
let urlEncoded = ReqBodyUrlEnc params -- how can I urlencode the params only without performing the request?
-- http://hackage.haskell.org/package/req-1.2.1/docs/src/Network.HTTP.Req.html#ReqBodyUrlEnc has so far not enlightened mea
module QuickCheckDemo where
import Test.QuickCheck
showRev :: Int -> String
showRev = reverse . show
prop_ShowRev i = reverse (show i) == showRev i
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedStrings #-}
module MinimumWorkingExample where
import GHC.Generics
import Data.Aeson
import Data.Text (Text, pack)
import Data.Maybe (fromJust)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""Returns list of currently commuting German trains (regional and national)."""
import requests, json, threading
def get_tile(no=1):
"""Retrieve trains for tile no ranging from 1 through 23, including.
1 covers long distance trains only, 2 through 23 includes trains for
specific tiles.
"""
"""Module to retrieve last X delays for DB trains per station
Assumption: Each train commutes once per day.
TODO:
o devise implementation tests
(mock http requests with https://github.com/getsentry/responses)
"""
from collections import defaultdict
# SCOPE: install lektor in a venv on a Mac
# use *either* stable OR dev path
# stable path
curl -O 'https://pypi.python.org/packages/a0/2c/7dcbda332db0e7ece0e5476c324983fef455e9223e351ff972674fa5bdac/Lektor-2.3.tar.gz'
tar xvf Lektor-2.3.tar.gz
mv Lektor-2.3 lektor
# dev path