Skip to content

Instantly share code, notes, and snippets.

View jamesdavidson's full-sized avatar

James Davidson jamesdavidson

View GitHub Profile
jamesdavidson / Program.cs
Last active October 17, 2023 05:45
Alternative to getting started for Clojure CLR with a socket REPL and sending a SigV4 signed request (almost)
View Program.cs
// dotnet --version
// 7.0.100
// dotnet restore
// dotnet run
// rlwrap nc localhost 5555
using System;
using System.IO;
using System.Net;
using System.Net.Http;
jamesdavidson / find-or-create.sql
Created July 17, 2023 17:28
find or create values
View find-or-create.sql
extant AS (
SELECT id FROM access_code WHERE ("value") = ('asdf')
inserted AS (
INSERT INTO access_code ("value")
SELECT 'asdf'
View ec2-boot-bench.txt
# 12th July 2023
# trying out
cloudshell-user@ip-10-2-80-7 infra]$ history
1 git clone
2 cd ~/ec2-boot-bench/
3 ls
5 ./configure
jamesdavidson / user.clj
Created June 2, 2023 01:45
Clojure snippet for creating PDF where each page is from a PNG image file
View user.clj
;; org.clojure/clojure {:mvn/version "1.11.1"}
;; com.github.librepdf/openpdf {:mvn/version "1.3.30"}
(import 'com.lowagie.text.Document)
(import 'com.lowagie.text.Image)
(import 'com.lowagie.text.PageSize)
(import 'com.lowagie.text.pdf.PdfWriter)
(def doc (new Document))
(def os (io/output-stream "output.pdf"))
jamesdavidson / scatterplot.clj
Created May 24, 2021 07:48
View scatterplot.clj
;; clj -Sdeps '{:deps {org.apache.poi/poi {:mvn/version "4.1.1"} org.apache.poi/poi-ooxml {:mvn/version "4.1.1"}}}'
;; based on
(ns user
(:import [org.apache.poi.xssf.usermodel XSSFWorkbook]
[ CellRangeAddress]
[org.apache.poi.xddf.usermodel.chart XDDFDataSourcesFactory ChartTypes AxisCrosses AxisPosition MarkerStyle]
[ LegendPosition]
[ FileOutputStream]))
jamesdavidson / move-namespace.clj
Created April 20, 2020 08:48
How to mess around with (ns ...) declarations in Clojure
View move-namespace.clj
(binding [*ns* (find-ns 'some.other.namespace)]
(with-open [config ( ( "config.clj"))]
(loop []
(when-let [form (read {:eof nil} config)]
(do (eval form) (recur))))))
;; see also
jamesdavidson / user.clj
Last active April 15, 2020 16:37
Playing around with a Neanderthal benchmark
View user.clj
;; Deep Learning Base AMI (Amazon Linux 2) Version 22.0 (ami-0c9d86eac25c03fea)
;; p2.xlarge
;; $ nvidia-smi --list-gpus
;; GPU 0: Tesla K80 (UUID: GPU-3e0d6827-3d8e-5a5f-85d6-114d950f6d44)
;; $ cat /etc/os-release
;; NAME="Amazon Linux"
;; VERSION="2"
;; ID="amzn"
;; ID_LIKE="centos rhel fedora"
jamesdavidson / microphone.clj
Last active April 13, 2020 16:20 — forked from BurkeB/microphone.clj
Microphone Clojure test
View microphone.clj
[javax.sound.sampled TargetDataLine AudioFormat AudioSystem AudioInputStream AudioFileFormat$Type DataLine$Info]
[ File ByteArrayInputStream])
(def audio-format (new AudioFormat 44100 16 2 true true))
(def info (new DataLine$Info TargetDataLine audio-format))
(assert (AudioSystem/isLineSupported info))
(def line (AudioSystem/getTargetDataLine audio-format))
(.open line)
(.start line)
jamesdavidson /
Last active March 28, 2020 09:11
Demo of basic producer/consumer just for fun.
# In this program there is a queue implemented as a list protected by a
# mutex so that the producer can run on one thread and the consumer can
# run on another thread. The dequeue_all method will return an empty list
# if there is no work (it does not block its caller).
from random import random
from random import shuffle
from time import sleep
from threading import Lock
from _thread import start_new_thread
jamesdavidson / Makefile
Last active March 25, 2020 03:31
RPM packaging a command-line JMX client for use on CentOS Linux.
View Makefile
PACKAGE = cmdline-jmxclient
EXTRA_DIST = Makefile
RPM_TOPDIR := $(HOME)/rpmbuild
curl -s -o $(JAR)$(JAR)