Skip to content

Instantly share code, notes, and snippets.

View candera's full-sized avatar

Craig Andera candera

View GitHub Profile
@candera
candera / README.md
Last active February 13, 2024 10:04
Clojure config files

A little Clojure configuration reader

This is a handy bit of code I've written more than once. I thought I'd throw it in here so I can refer back to it later. Basically, it lets you read a config file to produce a Clojure map. The config files themselves can contain one or more forms, each of which can be either a map or a list. Maps are simply merged. Lists correspond to invocations of extension points, which in turn produces a map, which is merged along with everything else.

An Example

Consider the following files:

names.edn

@candera
candera / hundred-day-hacking.md
Created November 16, 2011 14:57
100 Days of Hacking

One Hundred Days of Hacking

Objective

Get better at some aspects of creating software by doing them more regularly.

Inspiration

A friend of mine, as a way to "level-up" her young daughter at violin, set a goal that the child would practice every single day for 100 days, without a break. This seems like such a good idea that I decided to steal it.

@candera
candera / Interception-xy.cs
Created March 2, 2012 15:38
Shows how to interoperate with interception.dll from C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace kchordr
{
public static class ScanCode
{
(ns com.wangdera.slideshow
(:use [clojure.contrib.test-is])
(:import (java.io File)
(javax.imageio ImageIO)
(javax.swing JFrame JPanel Timer)
(java.awt Dimension Frame Color)
(java.awt.event ActionListener WindowAdapter)))
(def imagelist (atom []))
(def current-image (atom nil))
@candera
candera / SlowInputStream.java
Last active June 30, 2020 12:46
A fairly naive implementation of a slow InputStream. Useful for simulating slow HTTP servers in Ring apps. Also shows how to proxy overloaded methods.
// A Java variation on the same theme
package user;
import java.io.InputStream;
import java.util.Random;
public class SlowInputStream extends InputStream {
private final long time;
private final long size;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Threading;
using Timer = System.Windows.Forms.Timer;
using System.IO;
@candera
candera / dopar.clj
Last active February 25, 2020 14:02
dopar
(defn dopar
"Given a (potentially infinite) sequence `coll`, uses core.async to
run `f` for side effects against each value in the collection.
Performs at most `concur` operations in parallel, and never enqueues
more than `lead` items ahead of the ones being consumed. If any call
to `f` throws an exception, it will be rethrown from this function.
Otherwise, returns nil. Optional timeout value is number of
milliseconds to wait for all operations to complete."
([coll f concur lead] (dopar coll f concur lead nil))
([coll f concur lead timeout-ms]
@candera
candera / example.sh
Last active January 26, 2020 00:43
Package ClojureScript in a Native EXE
# Update: This micro-blog is now also a guide on clojurescript.org:
# http://clojurescript.org/guides/native-executables
# Hello! This is a micro-post about how to produce native executables
# from ClojureScript source. The basic idea is to produce a
# JavaScript file using the ClojureScript compiler, and then use a
# Node.js tool called nexe (https://github.com/jaredallard/nexe) to
# compile that into an executable. The resulting file can be run
# without requiring a node install on the target machine, which can
# be handy.
@candera
candera / ssh-repl.org
Last active February 9, 2019 07:50
ssh-repl

Embedding an SSH-accessible REPL in a Clojure process

N.B. This is now a library, thanks to the efforts of the wonderful @mtnygard. And the README does a good job of making clear just how terrible an idea it is to actually do this. :)

As any Clojurist knows, the REPL is an incredibly handy development tool. It can also be useful as a tool for debugging running programs. Of course, this raises the question of how to limit access to the REPL to authorized parties. With the Apache SSHD library, you can embed an SSH server in any JVM process. It takes only a little code to hook this up to a REPL, and to limit access either by public key or

(require '[clojure.math.combinatorics :as combo]
'[clojure.core.async :as async])
(def zeus-route
["Kadena"
"Pohang"
"Pusan"
"Kimhae"
"Sachon"
"Taegu"