Skip to content

Instantly share code, notes, and snippets.

@DarinM223
DarinM223 / PrefixRenamer.class.st
Last active April 28, 2022 18:25
Renames all classes in package to have prefix
"
I rename all classes in my package to have a prefix of ""DM"".
"
Class {
#name : #PrefixRenamer,
#superclass : #Object,
#category : #Lambcalc
}
{ #category : #'menu - change set' }
@DarinM223
DarinM223 / async-channel.lisp
Last active March 18, 2021 23:22
Asynchronous channel in Common Lisp using cl-async
(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload :cl-async)
(ql:quickload :iterate)
(ql:quickload :bordeaux-threads)
(ql:quickload :cl-speedy-queue)
(ql:quickload :access)
(use-package :iterate))
(access:enable-dot-syntax)
@DarinM223
DarinM223 / ConduitTest.hs
Last active February 11, 2021 15:13
Combining producers in streaming libraries
module ConduitTest where
import Data.Conduit.Internal (sourceToPipe, unconsM)
import Data.Foldable (for_)
import Control.Monad (forever, void)
import Control.Monad.Trans.Maybe (MaybeT (MaybeT, runMaybeT))
import Conduit
lotsOfInts :: Monad m => ConduitT () Int m ()
lotsOfInts = for_ [0..5] $ \i -> yield i
@DarinM223
DarinM223 / Main.hs
Created January 22, 2021 14:40
Playing around with recursion schemes
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import Data.Foldable (fold)
import Data.Functor.Foldable (cata, embed, hylo)
@DarinM223
DarinM223 / Main.hs
Last active January 6, 2021 00:26
ExceptT with resource handling, async, and exceptions
module Main where
import Control.Concurrent.Async (async, wait)
import Control.Exception (Exception, catch, throwIO)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Except (ExceptT (ExceptT), runExceptT)
import Control.Monad.Trans.Resource (ResourceT, allocate, release, runResourceT)
newtype MyException = MyException String deriving Show
@DarinM223
DarinM223 / concurrency.rkt
Created December 13, 2019 13:28
Concurrency+Parallelism examples (test 1 and 4 are good, 2 and 3 are bad)
#lang racket/base
(require racket/async-channel racket/future ffi/unsafe/os-thread)
(define (mandelbrot iterations x y n)
(let ([ci (- (/ (* 2.0 y) n) 1.0)]
[cr (- (/ (* 2.0 x) n) 1.5)])
(let loop ([i 0] [zr 0.0] [zi 0.0])
(if (> i iterations)
i
@DarinM223
DarinM223 / vec_get_set.rkt
Last active November 26, 2019 00:23
More convenient getting/setting of multidimensional vectors in Racket
(require syntax/parse/define
(for-syntax racket/base racket/syntax))
(define-syntax-parser v!
#:datum-literals (:=)
[(_ vec:id [e:expr ...]) #'(~> vec (vector-ref e) ...)]
[(_ vec:id [e:expr ...] := exp:expr)
(define es (syntax-e #'(e ...)))
#`(~> vec
#,@(for/list ([i (in-range 0 (length es))]
@DarinM223
DarinM223 / table.lisp
Last active December 28, 2019 10:18
Compile time table in Racket and Common Lisp
(defmacro make-table (sym &rest kvs)
(let* ((hash-sym (gensym))
(setters (iter (for (k v) in kvs)
(collect `(setf (gethash ,k ,hash-sym) ,v)))))
`(defmacro ,sym ()
(let ((,hash-sym (make-hash-table)))
,@setters
,hash-sym))))
(defmacro get-table (sym k)
@DarinM223
DarinM223 / operator_parser.rkt
Created November 23, 2019 11:39
Operator precedence parsing macro in Racket
(define-syntax (: stx)
(syntax-parse stx
; #:literals needs to have bindings in order to work
; #:datum-literals only needs symbols so it works with '^'.
#:datum-literals (+ - * / ^)
[(_ l ... + r ...) #'(+ (: l ...) (: r ...))]
[(_ l ... - r ...) #'(- (: l ...) (: r ...))]
[(_ l ... * r ...) #'(* (: l ...) (: r ...))]
[(_ l ... / r ...) #'(/ (: l ...) (: r ...))]
[(_ l ... ^ r ...) #'(expt (: l ...) (: r ...))]
@DarinM223
DarinM223 / script.hs
Created November 21, 2019 03:34
Example of scripting using Haskell and Cabal
{- cabal:
build-depends: base >= 4.11 && < 5,shelly,text
ghc-options: -Wall -O0
default-language: Haskell2010
-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Shelly