Skip to content

Instantly share code, notes, and snippets.

View eigenhombre's full-sized avatar

John Jacobsen eigenhombre

View GitHub Profile
@eigenhombre
eigenhombre / trycfn.clj
Created March 10, 2018 15:03
Driving AWS CloudFormation from the Clojure REPL
(ns trycfn.core
(:require [amazonica.aws.cloudformation :as cfn]
[cheshire.core :as json]
[clj-http.client :as http]
[yaml.core :as yaml])
(:gen-class))
;; AWS puts lots of "::" in their key names; unfortunately colons have
;; a special meaning in Clojure (but clojure.walk/keywordize-keys will
@eigenhombre
eigenhombre / output
Created March 6, 2018 19:52
simple logging counter
(defn counter
"
A little counter formatter that outputs progress frequently at
first, then less often as the count increases.
Examples:
(counter \"Trial %d\") ;; reports at every doubling
(counter \"Trial %d\" 0.1) ;; reports at every 10% increase
"
([s] (counter s 1))
# Name: crowd.rb
# Date: May 27, 2008
# Description: copy selected component randomly throughout an area
# Copyright: John Jacobsen, NPX Designs, Inc.
# http://www.johnj.com
# Permission to use, copy, modify, and distribute this software for
# any purpose and without fee is hereby granted, provided that the above
# copyright notice appears in all copies.
# scan_plugins.rb
# March 28, 2010
#
# Description: scan a separate plugin directory and load scripts
# automagically.
#
# To use, set PATH to some working directory and create your plugin
# scripts there. DirScanner will keep an eye on that directory and
# load (i.e., execute) any scripts which appear there. Because each
# file will be executed as soon as it is changed, the Ruby files in
@eigenhombre
eigenhombre / build.boot
Created May 22, 2017 22:10
amazonica issue
(set-env! :dependencies '[[amazonica "0.3.100"]])
(require '[amazonica.aws.s3 :as s3])
(s3/get-object "mybucket" "foo")
;;=>
;; 1. Unhandled java.lang.UnsupportedOperationException
;; Client is immutable when created with the builder.
@eigenhombre
eigenhombre / example.sh
Created November 8, 2016 03:38
trivial static image galleries with ImageMagick and bash
# Convert a gallery of e.g. scanned images into HTML + thumbnails + originals
function galthumbs {
for i in $(ls IMG*.png| grep -v thumb); do
echo -n $i "...> "
o=$(echo $i | sed 's/.png/_thumb.png/')
echo -n $o
convert $i -thumbnail 'x200' $o
echo "."
done
}
;; To test out a grammar, simplify it as much as possible and then
;; apply it over a bunch of sample expressions:
(vec (map #(-> "D = txt
<txt> = (words | em | strong)+
strong = '*' txt '*'
em = '/' txt '/'
words = '.'+ !words
"
parser
(parses %)
;; Desired results shown as ";; <--", below...
(map #(-> "D = (B|S)*
S = 'S' B*
B = 'B'"
parser
(parses %))
[""
"B"
@eigenhombre
eigenhombre / README.org
Last active August 29, 2015 14:16
Using ClojureScript + Node for scripting

This took me awhile to get right. I wanted to see if Node + cljs might be suitable for scripting tasks where loading the entire Clojure infrastructure would be painfully slow.

I used lein new mies-node to make the project. This works with my installed Node.js (0.10) but stopped working when I upgraded to Node 0.12, so I rolled back.

Since Node 0.10 child_process doesn’t support spawnSync like Node 0.12 does, I had to use the spawn-sync package, installed via NPM.

The resulting script runs in 330 msec from start to finish.

(defun get-file (filename)
(with-open-file (stream filename)
(loop for line = (read-line stream nil)
while line
collect line)))
(defvar *filename*
"/Users/jacobsen/Programming/Lisp/commonlisp/word-pairs.txt")
(defun hash-keys (hash-table)