Skip to content

Instantly share code, notes, and snippets.

@tomtitchener
tomtitchener / script-docker-rmall.sh
Created July 12, 2019 13:57
docker: bash script to remove all running services
#!/bin/bash
for j in `docker service ls | grep batch | cut -d ' ' -f 9`;do
echo -n $i
docker service rm $j
done
@tomtitchener
tomtitchener / main.go
Last active July 12, 2019 20:45
golang: using reflect to copy like field name and type from source struct to destination struct.
package main
import (
"fmt"
"reflect"
"time"
)
type SC struct {
L int
@tomtitchener
tomtitchener / little-schemer-y.ss
Last active June 3, 2017 18:57
The Little Schemer: applicative-order Y from Chapter 9 "... and Again, and Again, and Again, ..."
#! /usr/local/bin/scheme --libdirs --script
;; chmod +x ./y.ss
;; echo "" | ./y.ss
;; The Little Schemer, Friedman & Felleisen, 4th Edition
;;
;; Chapter 9 "... and Again, and Again, and Again, ..."
;;
;; Skipping partial vs. total functions with examples Ackerman, termination.
@tomtitchener
tomtitchener / fix.hs
Last active June 4, 2017 16:24
Examples from You could have re-invented fix.
--http://www.vex.net/~trebla/haskell/fix.xhtml
module TryFixPoint where
import Data.Function
{--
-- | @'fix' f@ is the least fixed point of the function @f@,
-- i.e. the least defined @x@ such that @f x = x@.
@tomtitchener
tomtitchener / rank-2-types.hs
Last active August 29, 2015 14:12
Rank 2 Type Example in Haskell
{-# LANGUAGE RankNTypes #-}
-- Example of rank-2 type, from http://blog.mno2.org/posts/2012-04-06-what-is-rank-n-types-in-haskell.html
module Main(main) where
import Prelude hiding (length)
-- The function as the first argument to check is itself
-- of rank-1 type.
@tomtitchener
tomtitchener / barber.hs
Last active August 29, 2015 14:12
The barber shaves all persons that do not shave themselves
-- http://en.wikibooks.org/wiki/Haskell/Denotational_semantics
-- Begin Quote "
-- We are now looking for suitable mathematical objects that we can attribute to every Haskell program.
-- In case of the example 10, 2*5 and sum [1..4], it is clear that all expressions should denote the
-- integer 10.
-- Generalizing, every value x of type Integer is likely to be an element of the set \mathbb{Z}.
-- The same can be done with values of type Bool. For functions like f :: Integer -> Integer,
-- we can appeal to the mathematical definition of "function" as a set of (argument,value)-pairs,