Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env stack
-- stack --resolver lts-12.18 script
import Control.Concurrent (threadDelay)
import Control.Concurrent.Async (replicateConcurrently_)
import Control.Monad (unless)
import Data.IORef
import System.Random (randomIO)
main :: IO ()
main = do
{ nixpkgs ? <nixpkgs>
, includeBroken ? true
}:
# Results in all haskell packages that are instantiatable and are executables
# Buildable via `nix-build haskell-exes.nix`
let
pkgs = import nixpkgs {
config = {
allowBroken = includeBroken;
@jonschoning
jonschoning / 24-bit-color.patch
Created January 9, 2019 19:47 — forked from cpixl/24-bit-color.patch
24-bit color patch for URxvt version 9.22 (based on https://github.com/spudowiar/rxvt-unicode)
--- README.configure
+++ README.configure
@@ -9,8 +9,8 @@ CONFIGURE OPTIONS
--enable-everything
Add (or remove) support for all non-multichoice options listed in
- "./configure --help", except for "--enable-assert" and
- "--enable-256-color".
+ "./configure --help", except for "--enable-assert",
+ "--enable-256-color" and "--enable-24-bit-color".
@jonschoning
jonschoning / Main.hs
Created December 14, 2018 16:28 — forked from chessai/Main.hs
Averaged across persons, excluding legal fees, how much money had each person spent by time 6?
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Main (main) where
import Colonnade (Headed)
import Data.ByteString (ByteString)
import Data.Map (Map)
import Data.Text (Text)
import Siphon (Siphon, SiphonError)
@jonschoning
jonschoning / Main.hs
Created December 14, 2018 16:25 — forked from gelisam/Main.hs
Averaged across persons, excluding legal fees, how much money had each person spent by time 6?
-- in response to https://www.reddit.com/r/haskell/comments/a50xpr/datahaskell_solve_this_small_problem_to_fill_some/
{-# LANGUAGE BangPatterns, OverloadedStrings, RecordWildCards, ScopedTypeVariables #-}
module Main where
import Control.Category ((>>>))
import Data.Function ((&))
import Data.Map.Strict (Map, (!))
import Data.Set (Set)
import Test.DocTest (doctest)
@jonschoning
jonschoning / termux-url-opener
Created November 18, 2018 03:34 — forked from LordH3lmchen/termux-url-opener
termux-url-opener
#!/data/data/com.termux/files/usr/bin/zsh
#
# This is a termux-url-opener script to do diffrent tasks on my Android phone
#
url=$1
echo "What should I do with $url ?"
echo "y) download youtube video to movies-folder"
echo "u) download youtube video and convert it to mp3 (music-folder)"
echo "s) download with scdl (soundcloud)"
@jonschoning
jonschoning / prismatic.hs
Created November 10, 2018 04:24 — forked from parsonsmatt/prismatic.hs
I figured out a nice way to pluck exceptions out of a constraint!
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
@jonschoning
jonschoning / ecs-annotated.py
Created November 8, 2018 21:32 — forked from mvanga/ecs-annotated.py
A Python3 implementation of an entity-component-system in under 50 lines code.
import uuid
import json
# Returns a python dictionary given a file containing a JSON-based
# component definition. Every definition *must* contain a 'type'
# and 'schema' field inside a top-level dictionary. Here is an
# example of a simple schema file that defines a 'meta' component
# containing a 'name' field.
#
newtype MonoidComp r m a = MonoidComp { unMonoidComp :: ContT r m a }
deriving (Functor, Applicative, Monad, MonadTrans)
instance (Applicative m, Monoid r) => Alternative (MonoidComp r m) where
empty = MonoidComp $ ContT $ const (pure mempty)
MonoidComp a <|> MonoidComp b =
MonoidComp $ ContT $ \f -> liftA2 (<>) (runContT a f) (runContT b f)
foldMapA :: (Foldable f, Applicative m, Monoid r) => (a -> m r) -> f a -> m r
foldMapA f = foldr (liftA2 (<>) . f) (pure mempty)
#! /usr/bin/env nix-shell
#! nix-shell -I nixpkgs=channel:nixos-18.09 -i ghci -p "haskellPackages.ghcWithPackages (p: [p.monoidal-containers p.average])"
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MonadComprehensions #-}
import Control.Applicative ( Alternative(..) )
import Control.Monad.Trans.Cont
import Data.Map.Monoidal ( MonoidalMap )
import qualified Data.Map.Monoidal as Map