Skip to content

Instantly share code, notes, and snippets.

@hardentoo
hardentoo / Tree.hs
Created April 27, 2018 01:40 — forked from Kedrigern/Tree.hs
Implementation of binary search tree in Haskell
{- Implementation of BST (binary search tree)
Script is absolutly free/libre, but with no guarantee.
Author: Ondrej Profant -}
import qualified Data.List
{- DEF data structure -}
data (Ord a, Eq a) => Tree a = Nil | Node (Tree a) a (Tree a)
deriving Show
@hardentoo
hardentoo / Minimax.hs
Created April 25, 2018 03:24 — forked from jooyunghan/Minimax.hs
Haskell port of Tic-Tac-Toe example in 'Why Functional Programming Matters'
module Minimax (aimove) where
import Tree
-- Find value for max key from assoc list
maxkey :: (Ord k) => [(k, v)] -> v
maxkey = snd . foldl1 (\(k1,v1) (k2,v2) -> if k1 > k2 then (k1,v1) else (k2,v2))
max' :: (Ord a) => [a] -> a
max' = foldl1 max
@hardentoo
hardentoo / binaryTrees.hs
Created April 25, 2018 01:20 — forked from owainlewis/binaryTrees.hs
Haskell BTree
module BinaryTree
where
-- Haskell Binary Tree Examples
-- A binary tree can either be empty or a node with a left and right branch
data Tree a = EmptyTree | Node a (Tree a) (Tree a)
deriving ( Show, Read, Eq )
import Data.Functor
import Data.Functor.Constant
import Data.Functor.Identity
import Data.Monoid
import Data.Traversable (Traversable(..))
import Control.Comonad
import Control.Applicative (ZipList(..))
class Cotraversable t where
@hardentoo
hardentoo / monads.txt
Created April 7, 2018 07:51 — forked from jhrr/monads.txt
"Programming with Effects" by Graham Hutton -- http://www.cs.nott.ac.uk/~gmh/monads
PROGRAMMING WITH EFFECTS
Graham Hutton, January 2015
Shall we be pure or impure?
The functional programming community divides into two camps:
o "Pure" languages, such as Haskell, are based directly
upon the mathematical notion of a function as a
mapping from arguments to results.
@hardentoo
hardentoo / starttmux.sh
Created April 1, 2018 17:13 — forked from todgru/starttmux.sh
Start up tmux with custom windows, panes and applications running
#!/bin/sh
#
# Setup a work space called `work` with two windows
# first window has 3 panes.
# The first pane set at 65%, split horizontally, set to api root and running vim
# pane 2 is split at 25% and running redis-server
# pane 3 is set to api root and bash prompt.
# note: `api` aliased to `cd ~/path/to/work`
#
session="work"
@hardentoo
hardentoo / introrx.md
Created March 30, 2018 23:00 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
{ config, pkgs, ... }:
let
hostname = "luz3";
in {
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
# I use VirtualBox to connect to Windows and Linux guests
@hardentoo
hardentoo / configuration.nix
Created March 29, 2018 21:59
My NixOS configuration.nix and hardware-configuration.nix for a ThinkPad x250
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
boot = {
initrd.luks.devices = [
-- A tiny chat server to check I understand STM and threads.
-- To connect, run this program, then connect a few clients
-- using 'nc localhost 5252' in different terminals. Type a line + enter to send a message.
import Network
import System.IO
import Control.Concurrent
import GHC.Conc
import Control.Monad(forever)