Skip to content

Instantly share code, notes, and snippets.

View jamesdavidson's full-sized avatar

James Davidson jamesdavidson

View GitHub Profile
@jamesdavidson
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
jamesdavidson / find-or-create.sql
Created July 17, 2023 17:28
find or create values
View find-or-create.sql
-- https://stackoverflow.com/a/70312948
WITH
extant AS (
SELECT id FROM access_code WHERE ("value") = ('asdf')
),
inserted AS (
INSERT INTO access_code ("value")
SELECT 'asdf'
WHERE NOT EXISTS (SELECT FROM extant)
View ec2-boot-bench.txt
# 12th July 2023
# trying out https://www.daemonology.net/blog/2021-08-12-EC2-boot-time-benchmarking.html
cloudshell-user@ip-10-2-80-7 infra]$ history
1 git clone https://github.com/cperciva/ec2-boot-bench
2 cd ~/ec2-boot-bench/
3 ls
4 cat BUILDING
5 ./configure
@jamesdavidson
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
jamesdavidson / scatterplot.clj
Created May 24, 2021 07:48
scatterplot.clj
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 https://stackoverflow.com/questions/59061235/apache-poi-manage-scatter-chart
(ns user
(:import [org.apache.poi.xssf.usermodel XSSFWorkbook]
[org.apache.poi.ss.util CellRangeAddress]
[org.apache.poi.xddf.usermodel.chart XDDFDataSourcesFactory ChartTypes AxisCrosses AxisPosition MarkerStyle]
[org.apache.poi.ss.usermodel.charts LegendPosition]
[java.io FileOutputStream]))
@jamesdavidson
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 (java.io.PushbackReader. (java.io.FileReader. "config.clj"))]
(loop []
(when-let [form (read {:eof nil} config)]
(do (eval form) (recur))))))
;; see also https://gist.github.com/vkz/4c32cdff75ba7254ed0c
@jamesdavidson
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
jamesdavidson / microphone.clj
Last active April 13, 2020 16:20 — forked from BurkeB/microphone.clj
Microphone Clojure test
View microphone.clj
(import
[javax.sound.sampled TargetDataLine AudioFormat AudioSystem AudioInputStream AudioFileFormat$Type DataLine$Info]
[java.io 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
jamesdavidson / basic-producer-consumer.py
Last active March 28, 2020 09:11
Demo of basic producer/consumer just for fun.
View basic-producer-consumer.py
# 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
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
PACKAGE_VERSION = 0.10.3
JAR = $(PACKAGE)-$(PACKAGE_VERSION).jar
EXTRA_DIST = Makefile
RPM_TOPDIR := $(HOME)/rpmbuild
$(JAR):
curl -s -o $(JAR) http://crawler.archive.org/cmdline-jmxclient/$(JAR)