Skip to content

Instantly share code, notes, and snippets.

View 573's full-sized avatar

Daniel Kahlenberg 573

View GitHub Profile
get_db() {
if [ -z "$CABAL_SANDBOX_CONFIG" ]
then
db=""
else
db=$(sed -nr -e 's/^package-db: (.*)/\1/p' "$CABAL_SANDBOX_CONFIG")
if [ $? -ne 0 ]; then exit 1; fi
fi
}
db_cmd() (
module Printf
%default total
data Format = FInt Format -- %d
| FString Format -- %s
| FOther Char Format -- [a-zA-Z0-9]
| FEnd --
format : List Char -> Format
@kaoskorobase
kaoskorobase / 00-README.md
Last active October 30, 2015 11:43
Cont monad with error handling in C++

So I've been looking at the new NSURLSession API and imagining the tangled mess of delegate methods and completion blocks blurred my vision and made my head spin. After regaining my composure I remembered the wonderful world of Haskell monad transformer stacks and in particular I remembered two blog posts I came across some time ago ([1] and [2]) about restructuring nested callbacks with the Cont(inuation) monad. Digging further, I found an excellent [article][3] about the continuation monad in C++.

This is an attempt at generalizing some of the definitions, in particular making Cont (Continuator in the article) a typedef for a std::function and expanding the definition of bind to allow a change from one continuation argument type to another. I've also added error handling by wrapping the continuation arguments in a boost::variant; this is effectively

@kgadek
kgadek / gist:11380592
Last active August 29, 2015 14:00
AGH Informatyka (sem 10) :: Zaawansowane Techniki Integracji SystemΓ³w :: Laboratoria 1
{-# LANGUAGE OverloadedStrings, DeriveGeneric #-}
import Web.Scotty
import Data.Aeson
import GHC.Generics
data Stuff = Stuff { dt :: Things
} deriving (Show, Generic)
instance FromJSON Stuff
instance ToJSON Stuff
data Things = Things { id :: Int
@gseitz
gseitz / CanBuildFrom.hs
Last active November 16, 2015 07:03
CanBuildFrom.hs
{-# LANGUAGE MultiParamTypeClasses #-}
{-#LANGUAGE FlexibleInstances #-}
module CanBuildFrom where
import Data.Foldable
import Data.Map
data Builder from elem to = Builder {
result :: to,
add :: elem -> Builder from elem to
@Kartones
Kartones / postgres-cheatsheet.md
Last active November 22, 2025 11:15
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@staltz
staltz / introrx.md
Last active November 19, 2025 07:55
The introduction to Reactive Programming you've been missing
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Web.Scotty
import Data.Text.Lazy hiding (filter)
import Control.Concurrent.STM
import Control.Monad.IO.Class
import Data.List (nub)
storeTODO :: Text -> TVar [Text] -> STM [Text]
@aweijnitz
aweijnitz / Vagrantfile
Last active March 25, 2024 13:54
This is a Vagrant file and a provisioning script to create a Debian-based Jenkins server, including Java, Ant and Tomcat. Also see "provision.sh" below
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
# Named boxes, like this one, don't need a URL, since the are looked up
@pchiusano
pchiusano / type-inhabitants.markdown
Last active January 7, 2023 17:23
Reasoning about type inhabitants in Haskell

This is material to go along with a 2014 Boston Haskell talk.

We are going to look at a series of type signatures in Haskell and explore how parametricity (or lack thereof) lets us constrain what a function is allowed to do.

Let's start with a decidedly non-generic function signature. What are the possible implementations of this function which typecheck?

wrangle :: Int -> Int