Skip to content

Instantly share code, notes, and snippets.

@agentultra
agentultra / Socket.hs
Created July 19, 2020 17:31
This works differently on Windows
-- This is basically the same program taken from https://hackage.haskell.org/package/network-3.1.1.1/docs/Network-Socket.html#g:9
-- on 2020-07-19
-- It works as expected on Unix-like OSs: each line is buffered in and echoed back out
-- On Windows each character is read and echoed back out
module Lib where
import Control.Concurrent (forkFinally)
@agentultra
agentultra / Adventure.hs
Created April 16, 2020 14:17
A minimalist text adventure
module Adventure where
import Control.Monad.State
import Data.Char
import Data.List
import System.IO
data Item
= Item
{ itemName :: String
@agentultra
agentultra / SentinelFields1.hs
Last active July 18, 2018 21:07
Aeson Parsing Optional Fields with a Sentinel
{-# LANGUAGE DeriveGeneric #-}
module SentinelFields1 where
{-
We have some JSON..
[
{
"name": "Foo Test",
@agentultra
agentultra / Form.hs
Last active March 27, 2018 19:34
Modelling a Form in Haskell
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StandaloneDeriving #-}
module Form where
import qualified Data.Aeson as JSON
@agentultra
agentultra / agealyzer.clj
Last active February 25, 2016 20:53 — forked from clee/agealyzer.clj
agealyzer: given a root directory, spits out histogram of ages of files
(ns clee.agealyzer)
(require '[clojure.java.io :as io])
(defn date [x] (java.util.Date. x))
(defn is-file? [f] (.isFile f))
(defn last-modified [f] (.lastModified f))
(defn get-year [x] (.getYear x))
(defn process-dir
git clone https://git.openstack.org/openstack-dev/devstack
cd devstack
cat << EOF > local.conf
[[local|localrc]]
HOST_IP=192.168.33.33
PUBLIC_NETWORK_CIDR=10.0.1.0/24
DEST=/opt/stack
DATA_DIR=/opt/stack/data
SCREEN_LOGDIR=/opt/stack/data/logs/
LOGFILE=/opt/stack/data/logs/devstacklog.txt
git clone https://git.openstack.org/openstack-dev/devstack
cd devstack
cat << EOF > local.conf
[[local|localrc]]
DEST=/opt/stack
DATA_DIR=/opt/stack/data
SCREEN_LOGDIR=/opt/stack/data/logs/
LOGFILE=/opt/stack/data/logs/devstacklog.txt
VERBOSE=True
USE_SCREEN=True
import sys
def main(args=()):
x, y = 0, 0
total_presents = 1
visited = {(0, 0),}
with open('3-1.txt') as f:
directions = f.read(256)
while directions:
import sys
from collections import namedtuple
RightRectPrism = namedtuple('RightRectPrism', ('l', 'w', 'h'))
def parse_prism(s):
return RightRectPrism(*map(int, s.strip().split('x')))
@agentultra
agentultra / sloccount.fish
Last active December 16, 2015 16:34
get a rough line count of a source tree
function count_sloc
find . -name $argv | xargs cat | wc -l
end