Roll Your Own HTML in Clerk

23 April 2023

The clerk/table component automatically limits itself to only showing 20 results. Other presentation components, especially text, have configurable elision behaviors, but it doesn’t apply to the table.

After searching, guessing at ways to do it, and even asking in conference talks, I finally realized that we can render our own HTML with clerk/html and hiccup. That HTML is not limited to any size, and building a table is easy. We used to do it all the time.

I wrote my own simple function to render a table, and I used that instead of the clerk/table. It takes the same parameters I was already using.

^{:nextjournal.clerk/visibility {:code :hide :result :hide}}
(ns sample
  {:nextjournal.clerk/visibility {:code :fold :result :show}}
  (:require
   [nextjournal.clerk :as clerk]))

^{:nextjournal.clerk/visibility {:code :hide :result :hide}}
(defn my-table
  "display a simple table in html.
  :head is the sequence of head labels.
  :rows is a sequence of sequences.
  :limit is the max to display of the rows. (default 100)"
  [params]
  (clerk/html [:table
               [:thead
                [:tr
                 (for [h (:head params)] [:th h])]]
               [:tbody
                (for [r (take (or (:limit params) 100) (:rows params))]
                  [:tr
                   (for [c r]
                     [:td c])])]]))

(my-table
  {:head ["x" "y"]
   :limit 100
   :rows [[1 2]
          [3 4]]})

Update 2023-11-27

As of the 0.15.957 release, clerk tables have a ::clerk/page-size parameter, so I use that now instead of the code above.


Podcast List for November 2022

03 November 2022

I have 73 feeds I currently follow. I have a whole system of prioritization, so I can listen to important things first. I’ve listed them alphabetically here:


Java Joyless

27 January 2021

Mr Haki has a Java Joy article about transforming a stream of strings into a map using functional Java. I’m having a bit of trouble embracing it enthusiastically, since each example is 81 lines of Java code and a pointy pile of type declarations!

I dashed out the same functionality in 4 lines of Clojure, and I can understand it a whole lot easier. I’m not even sure this is the fewest forms, but it’s still nicer.

  (->>
    ["language" "clojure" "username" "john"]
    (partition 2)
    (reduce (fn [m [k v]] (assoc m k v)) {}))
  ;; => {"language" "clojure", "username" "john"}

Update 2021-04-14: It can be done in one line of Clojure.

  (apply hash-map ["language" "clojure" "username" "john"])
  ;; => {"language" "clojure", "username" "john"}

Written with Clojure 1.10.2.


Fixes for Overtone and SuperCollider on PopOS 20.10

02 November 2020

I took the update to PopOS 20.10, and my Overtone setup stopped working. When I’d try to boot up the internal SuperCollider server from Emacs or from the leiningen repl on my music projects which all (:require [overtone.live :refer :all]), get an error in native libraries. I could also try to start the server with (boot-internal-server) or (boot-external-server), but it gives the same error.

--> Booting internal SuperCollider server...
Cannot read socket fd = 107 err = Success
CheckRes error
Could not read result type = 22
Client name = Overtone conflits with another running client
Cannot connect to the server
JackShmReadWritePtr1::~JackShmReadWritePtr1 - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
could not initialize audio.
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f5eec0e9ba7, pid=30517, tid=30605
#
# JRE version: OpenJDK Runtime Environment AdoptOpenJDK (15.0.1+9) (build 15.0.1+9)
# Java VM: OpenJDK 64-Bit Server VM AdoptOpenJDK (15.0.1+9, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C  [libscsynth.so.1+0x63ba7]  World_WaitForQuit+0x7
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/john/workspace/music/hs_err_pid30517.log
--> Connecting to internal SuperCollider server...
[thread 30576 also had an error]
#
# If you would like to submit a bug report, please visit:
#   https://github.com/AdoptOpenJDK/openjdk-support/issues
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Since it can no longer start the server internally from within Overtone, I start the server manually. I wrapped a script around the start up, so I can set the environment variables for configuring jack and starting up the synth:

#!/bin/sh

# automatically connect up jack ports
export SC_JACK_DEFAULT_INPUTS="system:capture_1,system:capture_2"
export SC_JACK_DEFAULT_OUTPUTS="system:playback_1,system:playback_2"

scsynth -u 57110

To get Overtone going again, I disabled the automatic boot of the server within Overtone by switching all the requires in each file from overtone.live to overtone.core, and I connect to that external server from my REPL manually with (connect-external-server) before doing anything else.

Finally, Overtone was consistently failing to find my MIDI keyboard. When things were working well enough a couple months ago, it still had required a little dance of killing off jackd and restarting Overtone, since something had been tying up the MIDI interface. This workaround was no longer adequate, since scsynth and jackd needed to already be started. I disabled MIDI connection in jackd by removing the -Xseq option from my ~/.jackdrc.

I’m back in business, and it’s probably more robust with these manual steps now. I think I’m also seeing some other odd little things working with the external server that didn’t previously, like using (mouse-x) for reading mouse positions into the synth values. The built-in piano synth is also working where it hadn’t previously.

Update 2021-02-13: I had lost the ability to send desktop audio (pulseaudio) through to the Jack Sink with this setup, so I figured out to start qjackctl before my supercollider.sh. That gets the Jack Sink available again to pulseaudio and the desktop sound menu.


All the Posts

April 2023

November 2022

January 2021

November 2020

October 2020

May 2020

March 2020

December 2019

March 2018

February 2018

January 2018