Skip to content

Instantly share code, notes, and snippets.

View Lambeaux's full-sized avatar

Steven Lombardi Lambeaux

  • Centripetal Networks
  • Arizona, United States
View GitHub Profile
@Lambeaux
Lambeaux / README.md
Created August 24, 2022 16:41
Simple ClojureScript rendition of the game GO, drawn with tile squares instead of stones on intersections.

Basic implementation of GO using vanilla CLJS. No frameworks. No libraries.

Run to start the game at the REPL:

clj -M --main cljs.main --compile game-of-go.core --repl
(in-ns 'game-of-go.core)
(draw-board!)
@Lambeaux
Lambeaux / user.cljs
Created October 11, 2021 20:02
Toggle to keep NodeJS ClojureScript REPL from crashing on uncaught errors
(defn exception-handler [err]
(binding [*print-fn* *print-err-fn*]
(println "An error occurred that otherwise would have crashed the Node process:")
(println err)))
(defn handle-all []
(.on js/process "uncaughtException" exception-handler))
(defn handle-none []
(.removeListener js/process "uncaughtException" exception-handler))
@Lambeaux
Lambeaux / mapper.java
Created April 27, 2018 00:17
Unrelated object functional abstraction
private static <T> Map<Class<T>, Function<T, List<JAXBElement<?>>>> mappings() {
return ImmutableMap.<Class<T>, Function<T, List<JAXBElement<?>>>>builder()
.put(BinaryLogicOpType.class, new Function<BinaryLogicOpType, List<JAXBElement<?>>>() {
@Override
public List<JAXBElement<?>> apply(BinaryLogicOpType t) {
return null;
}
})
.build();
}
@Lambeaux
Lambeaux / OptionalErasure.java
Last active April 19, 2018 18:37
Optionals erase types, even with casting
List<Map> resultTemplates = new ArrayList();
// Will not compile
List<String> descriptors =
Optional.of(resultTemplates.get(0))
.map(m -> m.get("descriptors"))
.map(List.class::cast)
.orElseThrow(() -> new AssertionError("Result template data was malformed"))
.stream()
.map(String.class::cast) // Explicitly ignoring this cast
@Lambeaux
Lambeaux / Expansions.java
Last active February 7, 2018 23:20
First pass at property expansions
/**
* Returns a new {@link Dictionary} where values containing system property notation such as
* {@code ${my.system.property.name}} are substituted with their appropriate values.
*/
private Dictionary<String, Object> expand(Dictionary<String, Object> original) {
Dictionary<String, Object> expanded = new Hashtable<>();
for (String key : list(original.keys())) {
Object val = original.get(key);
if (val instanceof String) {
expanded.put(
@Lambeaux
Lambeaux / TryWithResourcesIgnoresClose.java
Created November 9, 2017 23:09
Proof that all exceptions, both operations within the try block, as well as the close, will be caught in a single catch and that embedded try blocks are unnecessary.
package com.connexta;
import static com.connexta.Utils.print;
import java.io.Closeable;
import java.io.IOException;
public class TryWithResourcesIgnoresClose {
static void run() {