Journal: 2024

..

2024-01-07

Mistaking category for entity

In programming, names should make it clear whether you’re talking about a category of things or a specific entity. I commonly see programmers work with entities, but name the category. The name is too wide, if we use Zach Tellman’s terminology from Elements of Clojure.

2024-02-10

State pling plong

I’m still not used to playing around with stateful systems. I avoid state like the plague! Should I change that? Perhaps?

If yes, how? Write an interactive chat application? Write some logging thing? A way to visualize those logs?

Hmmm.

2024-02-18

State pling plong 2

Since last “State pling plong”, I set up a PostgreSQL database for mikrobloggeriet.no. That was a helpful learning experience. I’m glad i spent the time.

Contributing to igrishaev/pg2

https://github.com/igrishaev/pg2

https://github.com/igrishaev/pg2/issues/1

Problem: no REPL, no tests

When I tried starting a REPL like I normally do, it didn’t work.

Have I read the project docs?
this might be described in the README or somewhere I haven’t read.
Have I read the Leiningen docs?
this should be described in the leiningen docs too.

Unrelated, what is igrishaev doing?

lots of changes.

README.md                                                 | 297 +++++++++++++++++++++++++++++++++++++-
pg-bench/src/pg/demo.clj                                  | 197 ++++++++++++++++++++++++-
pg-core/src/clj/pg/core.clj                               |  60 +++++---
pg-core/src/clj/pg/jdbc.clj                               | 262 +++++++++++++++++++++++++++++++++
pg-core/src/clj/pg/pool.clj                               |  10 +-
pg-core/src/java/org/pg/Accum.java                        |   4 +-
pg-core/src/java/org/pg/ConnConfig.java                   |  19 ++-
pg-core/src/java/org/pg/Connection.java                   |  21 ++-
pg-core/src/java/org/pg/ExecuteParams.java                |   1 +
pg-core/src/java/org/pg/Main.java                         |   9 +-
pg-core/src/java/org/pg/Payload.java                      |   1 +
pg-core/src/java/org/pg/auth/ScramSha256.java             |   2 +-
pg-core/src/java/org/pg/codec/DecoderBin.java             |   2 +-
pg-core/src/java/org/pg/codec/DecoderTxt.java             |   2 +-
pg-core/src/java/org/pg/codec/EncoderBin.java             |   5 +-
pg-core/src/java/org/pg/codec/EncoderTxt.java             |  18 ++-
pg-core/src/java/org/pg/enums/Format.java                 |   2 +-
pg-core/src/java/org/pg/enums/SASL.java                   |   2 +-
pg-core/src/java/org/pg/enums/TXStatus.java               |   2 +-
pg-core/src/java/org/pg/{ => error}/PGError.java          |   2 +-
pg-core/src/java/org/pg/{ => error}/PGErrorResponse.java  |   2 +-
pg-core/src/java/org/pg/json/JSON.java                    |   2 +-
pg-core/src/java/org/pg/msg/AuthenticationResponse.java   |   2 +-
pg-core/src/java/org/pg/msg/ErrorResponse.java            |   2 +-
pg-core/src/java/org/pg/msg/Execute.java                  |   2 +-
pg-core/src/java/org/pg/msg/FieldParser.java              |   2 +-
pg-core/src/java/org/pg/msg/NegotiateProtocolVersion.java |   2 +-
pg-core/src/java/org/pg/msg/NoticeResponse.java           |   2 +-
pg-core/src/java/org/pg/msg/NotificationResponse.java     |   2 +-
pg-core/src/java/org/pg/msg/Parse.java                    |   2 +-
pg-core/src/java/org/pg/pool/Pool.java                    |  22 ++-
pg-core/src/java/org/pg/{clojure => proto}/IClojure.java  |   2 +-
pg-core/src/java/org/pg/{reducer => proto}/IReducer.java  |   2 +-
pg-core/src/java/org/pg/reducer/Default.java              |   1 +
pg-core/src/java/org/pg/reducer/Dummy.java                |   1 +
pg-core/src/java/org/pg/reducer/First.java                |   1 +
pg-core/src/java/org/pg/reducer/Fold.java                 |   1 +
pg-core/src/java/org/pg/reducer/GroupBy.java              |   1 +
pg-core/src/java/org/pg/reducer/IndexBy.java              |   1 +
pg-core/src/java/org/pg/reducer/Java.java                 |   1 +
pg-core/src/java/org/pg/reducer/KV.java                   |   1 +
pg-core/src/java/org/pg/reducer/Matrix.java               |   1 +
pg-core/src/java/org/pg/reducer/Run.java                  |   1 +
pg-core/src/java/org/pg/type/PGEnum.java                  |   2 +-
pg-core/src/java/org/pg/util/HashTool.java                |   2 +-
pg-core/src/java/org/pg/util/HexTool.java                 |   2 +-
pg-core/src/java/org/pg/util/IOTool.java                  |   2 +-
pg-core/test/pg/client_test.clj                           |  18 ++-
pg-core/test/pg/concurrency_test.clj                      | 164 +++++++++++++++++++--
pg-core/test/pg/decode_txt_test.clj                       |   2 +-
pg-core/test/pg/encode_bin_test.clj                       |   2 +-
pg-core/test/pg/encode_txt_test.clj                       |   2 +-
pg-core/test/pg/jdbc_test.clj                             | 289 +++++++++++++++++++++++++++++++++++++
pg-core/test/pg/pool_test.clj                             |   4 +-
todo.md                                                   |  26 +++-

README, demo, tests. But “jdbc”??? Why jdbc?

(ns pg.jdbc
  "
  The Next.JDBC-friendly wrapper. Mimics most of the
  `next.jdbc` functions and macros.

  https://github.com/seancorfield/next-jdbc/blob/develop/src/next/jdbc.clj
  "
  (:import
   clojure.lang.IPersistentMap
   clojure.lang.IFn
   org.pg.Connection
   org.pg.pool.Pool)
  (:require
   [clojure.set :as set]
   [pg.core :as pg]
   [pg.pool :as pool]))

specifically

The Next.JDBC-friendly wrapper. Mimics most of the `next.jdbc` functions and macros.

Yeeeeah, OK. Not “let’s use jdbc and compare to pg2 to test our code”, but “let’s provide a nice comptibility layer for those using next.jdbc today.”

Project docs for REPL and tests?

Let’s see.

Kompilere subprosjekter før jeg gjør noe mer?

Jeg har nå gjort cirka følgende fra toppen:

(cd pg-core && lein clean && lein javac && lein install)
(cd pg-honey && lein clean && lein javac && lein install)
(cd pg-component && lein clean && lein javac && lein install)

… og jeg får nå andre typer feil når jeg prøver å kjøre testene (feks med (cd pg-core && lein test)).

docker compose up

Feilene jeg fikk over så ut som “prøver å koble til port, finner ikke”

lein test pg.client-test

lein test :only pg.client-test/test-decode-oid

ERROR in (test-decode-oid) (IOTool.java:139)
PORT 10110
Uncaught exception, not in assertion.
expected: nil
  actual: org.pg.PGError: cannot open a socket, host: 127.0.0.1, port: 10110
 at org.pg.util.IOTool.socket (IOTool.java:139)
    org.pg.Connection._connect_unlocked (Connection.java:304)
    org.pg.Connection.connect (Connection.java:297)
    org.pg.Connection.<init> (Connection.java:73)
    org.pg.Connection.<init> (Connection.java:82)
[...]

Må jeg kjøre opp en PostgreSQL-instans lokalt?

$ docker compose up
[...]
[+] Running 1/0
 ✔ Network pg2_default   Created                                                                   0.0s
 ⠋ Container pg2-pg14-1  Creating                                                                  0.0s
 ⠋ Container pg2-pg11-1  Creating                                                                  0.0s
 ⠋ Container pg2-pg15-1  Creating                                                                  0.0s
 ⠋ Container pg2-pg12-1  Creating                                                                  0.0s
 ⠋ Container pg2-pg16-1  Creating                                                                  0.0s
 ⠋ Container pg2-pg13-1  Creating                                                                  0.0s
Error response from daemon: make cli opts(): making volume mountpoint for volume /Users/teodorlu/dev/igrishaev/pg2/.docker/postgres/initdb.d: mkdir /Users: operation not permitted
Error: executing /opt/homebrew/bin/docker-compose up: exit status 1

Hmmmm.

Makefiles!

Heh, det finnes jo makefiles overalt! :D De må jeg prøve.

2024-02-25

scicloj study group

people

  1. daniel stuff

    using ggplot from clojure work by generateme - how to use ggplot from Clojure (clojisr)

    90 minutes total

  2. Teodor

    Programming, civil engineering, product. Interested in data and data visualization, not an expert.

    Data Visualization: not an expert, and would definitely like to get better.

  3. thomas 2018

    frontend databases, dashboards, visuals get into the data part “r is a great place to start”

    d3, three.js “grammer of graphics”

    wrote a gallery

  4. daniel

    community organizer scicloj funded by clojurists together

  5. andrew

    dataviz and data science python, scala, r, clojure prior experience with ggplot

    found ggplot to be superior for fundamental reasons primarily clojure now think there is a lot to learn from ggplot

    implement wilkinsons “grammar of graphics”

    “there’s a reason why ggplot2 is THE dataviz library for R” explore more and learn.

    daniel: what is grammar of graphics

  6. kira

    possible to do dataviz with vega / vega-lite “dataviz biggest hole”

    really cool to implement the grammar of graphics in clojure it’s an idea, it’s a grammar

    “right now, only impl is in R”

  7. tomasz

    written clojure libraries created “cljplot” from scratch, “lots of mistakes”, hope to contribute

  8. jaryt

    phd student, small university midwest taught at a small university in africa here to study, “be with the best!”

part two

  1. intro, andrew

    in the clojure world, we work with vega & vega lite impl of grammar of graphics

    from leol wilkinson early work 80s statistical computing data visualization access to computers was new spss “chief scientist” “h2o AI” passed away grammar of graphics is his “magnus opus”

    important because — page 2 —

    first part, syntax

    we often call graphics charts (greek), latin pie charts, bar charts

    shuns charts

    charts instances of general objects

    pie is a divided bar into polar coordinates

    histogram != bar charts

    different grammars

    fewer charts than wanted no deep structure no reuse cannot add new charts “theory of graphics, not charts”

    decompose basic charts into the more fundamental things axes, scales coordinates

    ways of combining formal algebra

    r library ggplot “much more directly implements the algebra” than vega (lite) hypothesis: we’ll see ggplot2 perform better than vega (lite).

    Wilkinson book: https://link.springer.com/book/10.1007/0-387-28695-0

    Other book: https://ggplot2-book.org/

  2. daniel demo

    Qs teodor

    1. Are you getting completion from CIDER?
    2. What was the return value from (r "1 + 1")

    .

  3. ggplot vs vega

    ggplot has a combinator API

    ways to combine primitives!

    kira: about vega-lite, “have to understand everything in order to do the fancy stuff” axes, layers, scales don’t want to care marks, encodings have that magic “behind the scenes” translation between high-level easy to EDN/JSON/…

    andrew: “incremental specificity”, “compositional power”

    daniel: functions, objects, “hidden” teodor: emmy, reitit, pure data representation is opt-in

    daniel: jun cho wants to look inside, ggplot is hiding ggplot-like “functions and safety”, can check if args are ok perhaps we end up with something safe to hanami

  4. daniel demo

    teodor: what if we start by translating from r

    daniel: “stat layer” in your dataflow

    “hard”. Actionabes?

    1. put more effort into studying
    2. get a better teacher / access better pedagogy
    3. learn a better topic

    scale: log scale, linear scale grammar: roles of “things” in function calls

    nice book.

    chapter 13 - build a plot layer by layer https://ggplot2-book.org/layers

    thomasz has a nice backend, but is looking for a better way to create the plots.

    kira: move processing to the JVM side. CLJplot: crunching in Clojure on the JVM

    andrew: humble UI

    thomas: learn, document the learning! kira: learn, document the learning!

    daniel: look into hanami. Defaults and some logic around defaults as data.

    Teodor: separate speed from design.

    kira: sensible defaults, meta-merge them up current impl: proliferation of chart templates, infinite number of possible chart specifications. general data science work: need more general things.

    “what’s better, vega, hanami or ggplot?” Kira: you don’t have to understand everything in ggplot.

    goal: can make it work without understanding what’s under the abstractions goal: make it terse

  5. teodor ggplot draft

    (ns explore.ggplotj
      (:refer-clojure :exclude [+]))
    
    ;; STEP 1: OPERATIONS AND EXAMPLE USAGE
    
    (defn + [])
    (defn ggplot [])
    (defn aes [])
    (defn geom-point [])
    
    ;; STEP 2: PROTOCOLS AND STRUCTS
    ;;
    ;; ... assuming we don't need two-argument dispatch.
    
    (comment
      +
      ggplot
      aes
      geom-point)

    alternative name: jjplot. Symmetry & hat tip to ggplot. Hat tip to CloJure & Jvm.

2024-02-29

a UI for updates

2024-03-28

Poor performance on main page

Mostly because unpgk is slow to return.

Lessons:

Decision: disable livejs temporarily, rerun bench.

2024-03-29

a new random button!

On coding without a goal

I’ve made play.teod.eu with a goal in mind:

Intent: bring ideas to life. Discuss, sharpen, play. Minimize the distance between intent and reality.

Without that goal, I would have worked differently. That goal helps me know how to balance the amount of technical debt in my system. Rather than code to code, I code to achieve some outside goal!

Lately, I discovered that I had 360 lower-case formatted UUIDs in my system, and 36 upper-case formatted UUIDs. See for instance commit 8f62a0. This is kind of embarrassing! But, what do I do with it? Fix it?

I decided on the following:

  1. Change the code that could generate upper-case uuids to generate lower-case uuids all the time.
  2. Ensure that we actually do it right the second time around.
  3. Nothing else.

2024-04-06

x

Stumbled over Eva Parish and her text What I think about when I edit, which I enjoyed a lot.

About a skill I value, a skill where I have something to learn, and a skill I wish more people would value.

2024-04-13

meninger ≠ observasjoner, slutninger ≠ vurderinger

subjektiv objektiv
liten mening observasjon
stor vurdering slutning

opinion ≠ observation, deduction ≠ judgment

subjective objective
small opinion observation
big deduction judgment

decided to put this table in a tweet: https://twitter.com/TeodorHeggelund/status/1779112730001125852

opinion ≠ observation, deduction ≠ judgment

I think we could avoid a lot of pain if we put in a bit more effort to separate between “objective falsifiable” (let’s find the facts!) and “subjective” (let’s explore taste!).

2024-05-26

Pragmatism, encouragement and helpfulness embodied: on working with Michiel

This is a text I’d like to write about what I’ve learned from Michiel Borkent.

pragmatism

he ships. He does not require perfection. But he does require making an effort to work in the right direction.

enouragement

he encourages those around him. Problems are soluable, and we can do this together.

helpfulness

he helps people achieve what they want. He does not super-impose his on goals & designs on others.

clarity

he asks those he works with for clarity. What are you actually trying to achieve? What, exactly, are you doing to cause this error?

embodied
he’s there, not off in his white tower. He discusses reality, not hypotheticals

2024-09-14

Supporting full-width elements on my site

Context. I want full width elements on my site. <body> width is currently controlled by Pandoc’s CSS rules, where the <body> has a margin.

Problem. <body> CSS margin prevents <body> child elements from having full width.

Proposed solution: ditch Pandoc’s CSS. Take control of the CSS, and delete the rule we don’t want.

Proposed solution: override the <body> CSS rule.

  1. Reset the <body> margin back to zero with an !important rule
  2. Re-apply the <body> margin with rules applied to <body>’s children (with body > * rules)
  3. Then override that rule with specific body > .my-exception rules.

Attempting to override the <body> CSS rule

Parts of it worked nicely, but not all of it. Here’s my attempt:

https://github.com/teodorlu/play.teod.eu/commit/c1b8aa0d31b13b65d45b0024b6a897dae9b3b7f3

So, what didn’t work out?

  1. Behavior on small screen sizes broke. I got margins that I couldn’t get rid of.

What assumptions were wrong?

  1. That this was just a matter of changing the body width. Several CSS rules are at play here.

Lessons learned?

  1. I probably want to control CSS from the bottom up myself.
  2. I could keep the <meta> tags from Pandoc if I want to.

This would mean avoiding –standalone.