Skip to content

Instantly share code, notes, and snippets.

View bowbahdoe's full-sized avatar

Ethan McCue bowbahdoe

  • Pembroke, MA
View GitHub Profile

Looking at some old code there were a couple of undesirable features. One particular code smell is a good motiviating example: handlers calling other handlers.

It encourages the developer to "register handlers as reusable components" but that's a pretty clumsy way to write utilties. Over time those util handlers were collecting barnicles and were becoming very hard to reason about or refactor.

Handlers, actions and utils

With the advent of :fx we have a clean composable alternative with some desirables traits.

My app has three namespaces (app.handlers, app.actions and app.utils)

@ryan-haskell
ryan-haskell / Carousel.elm
Last active November 26, 2020 23:56
an example of a component built around a data structure.
@divs1210
divs1210 / extrapolate.clj
Last active June 22, 2024 14:23
extrapolate: like iterate, but different
(defn extrapolate*
[gen-next shrink v]
(lazy-seq
(let [next-item (gen-next v)
new-v (shrink (conj v next-item))]
(cons next-item
(extrapolate* gen-next shrink new-v)))))
(defn extrapolate
"Returns a lazy seq produced by extrapolating `coll` with given rules.
@mitranim
mitranim / flat-block-macros.clj
Last active June 7, 2021 11:49
Clojure macros for writing flat blocks with early returns, avoiding the let/if-pyramid
(defmacro return-or [sym expr] {:pre [(symbol? sym)]}
`(if (reduced? ~sym) (unreduced ~sym) ~expr))
(defn imp-block [[expr & tail-exprs]]
(match expr
(('let pattern init) :seq)
(if-not tail-exprs
(list init)
(match (imp-block tail-exprs)
@garretfick
garretfick / terraform.tf
Last active October 1, 2020 12:38
Terraform Configuration for Heroku/S3 Application
# This terraform configuration generates a Heroku PHP application
# using the Heroku postgress database addon and creates an AWS S3
# bucket to host static files for the application.
# The site is sufficiently simple that this configuation is
# contained in a single file
# The build creates environment variables in the Heroku application
# containing the credentials for the S3 bucket.
# Authentication for the AWS provider - we use this access
# key in order to be able to create a new AWS user and the S3
@mathieuancelin
mathieuancelin / Lens.java
Last active March 7, 2023 02:23
Lenses with Java 8
package bar.foo.lenses;
import java.util.function.BiFunction;
import java.util.function.Function;
public class Lens<A, B> {
private final Function<A, B> getter;
private final BiFunction<A, B, A> setter;
@semperos
semperos / clojure-deftype-scaffolding.clj
Created October 4, 2012 18:16
Clojure Scaffolding for deftype (Christophe Grand) - Show which methods a class implements and for which interfaces
;; Big thanks to Christophe Grand - https://groups.google.com/d/msg/clojure/L1GiqSyQVVg/m-WJogaqU8sJ
(defn scaffold [iface]
(doseq [[iface methods] (->> iface .getMethods
(map #(vector (.getName (.getDeclaringClass %))
(symbol (.getName %))
(count (.getParameterTypes %))))
(group-by first))]
(println (str " " iface))
(doseq [[_ name argcount] methods]
(println
@pal
pal / ClasspathInspector.java
Created May 11, 2009 15:40
Find classes in the classpath (reads JARs and classpath folders).
package com.palbrattberg.classpathtools;
import java.io.File;
import java.io.FilenameFilter;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;