Jim Cheung

Wednesday, December 02, 2020

SensibleSideButtons enables back/forward actions on my Anker mouse under os x

but I ordered a trackball mouse, looking forward to it

installed back x-tile on my pinebook pro, not as awesome as awesomewm but good enough

usually for two opened windows, I will use x-tile h to tile them horizontally

for 3 windows, it supports triangle-up/down/left/right, then I'll use x-tile y/i to swap windows

more than 3, I will x-tile q to quad all windows then use x-tile m to zoom in and x-tile M to zoom out

(x-tile * all mapped to shortcut keys)

couple links about arm cpu:

Friday, December 04, 2020

an interesting article about terminal workflow: My personal workflow for terminal-based coding, writing, research, and more!

I don't use a floating/drop down terminal, so I installed guake and I like it.

Sunday, December 13, 2020

I also got myself a happy hacking keyboard on black friday sale, professional 2 type-s

for DIP I switched on 2 (mac), 3 (DEL as backspace) and 5 (switch Alt and ◇)

Dockerfile best-practices for writing production-worthy Docker images

it suggests using krallin/tini: A tiny but valid init for containers as ENTRYPOINT

found two useful nc command from Become shell literate


$ find . ! -path './Content/*' | xargs tar -cv | pv | zstd | nc 204:fbf5:... 12345


$ nc -vll :: 12345 | zstdcat | pv | tar -xv

Friday, December 18, 2020

playing with gron with my favrouite data source

gron https://old.reddit.com/r/clojure.json | egrep "data.title|data.url |data.num_comments|data.score" | sed -r "s/.children//g" | sed -r "s/data.//g" | gron -u | jq .

I love emacs but usually I'll start with terminal, vim is less thinking tool for me.

I'm practicing vim for simple/toy clojure programs, the setup is minimal:

  1. lein new proj
  2. lein repl
  3. in vim start with :Connect
  4. start coding

I'm using fireplace.vim and parinfer.vim, both are just single .vim files

switching between repl and code file is easier, they're just tmux panes

some fireplace commands:

another reason why vim is more easy for me is I don't use package manager, I put all plugins in git and on every machine I just clone the repo then everything's ready

for emacs even though I have a package list, but it's much less stable I usually need to resolve broken packages, maybe I should start saving packages to git ...

Sunday, December 20, 2020

everytime I start with deps.edn, I go back to use lein, it's just easier for me.

I switched to use bhauman/rebel-readline as my repl, seems no official guide to start a nrepl server, I'll just start it after rebel launched:

(require '[nrepl.server :refer [start-server stop-server]])
(defonce server (start-server :port 7888))

Tuesday, December 22, 2020

scripting with babashka, really fun

to include dependencies is easy, just add add-deps lines to the script:

(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {medley/medley {:mvn/version "1.3.0"}}})

(require '[medley.core :refer [filter-keys]])

to test in the repl is also easy, usually it's a single clj script, start the repl and load the file:

(load-file "script.clj")

however meander is not supported yet, also arm binary is not available

Wednesday, December 23, 2020

normal diff doesn't handle long line well, even vimdiff is not good

found online this produces good result:

$ wdiff a b | colordiff | less -R

also git produces the same result:

$ git diff --word-diff --no-index -- a b

on my terminal I need to tune the color for the diff, add to ~/.gitconfig:

[color "diff"]
  old = red bold
  new = magenta bold

Friday, December 25, 2020

picking up some new clojure tools recently:

I use portal to navigate nested json files:

$ rlwrap bb -cp `clj -Spath -Sdeps '{:deps {djblue/portal {:mvn/version "0.7.0"}}}'`

user=> (require '[portal.api :as p])
user=> (require '[clojure.java.io :as io])
user=> (require '[cheshire.core :as json])
user=> (p/open)
user=> (p/tap)
user=> (def data (json/parse-stream (io/reader "foo.json") true))
user=> (tap> data)

then browser the data in the web ui

to cleanup use

user=> (p/clear)
user=> (p/close)

but for command lines, there's easier way in their README


{:main-opts ["-m" "portal.main"]
 {djblue/portal {:mvn/version "0.7.0"}
  ;; optional json support
  cheshire/cheshire {:mvn/version "5.10.0"}
  ;; optional yaml support
  clj-commons/clj-yaml {:mvn/version "0.7.0"}}}


alias portal='bb -cp `clojure -Spath -M:portal/cli` -m portal.main'
alias edn='portal edn'
alias json='portal json'
alias transit='portal transit'
alias yaml='portal yaml'

then simply

cat foo | json

I can also use portal on pinebook pro (arm) since it doesn't require javafx

Saturday, December 26, 2020

another clojure tool I like:

very useful to navigate/transform nested maps, much better than meander when use in repl but meander describes the structure clearly

again use reddit json to test

(require '[com.rpl.specter :refer [select submap])

(select [:data :children :ALL :data (submap [:title :url :score :num_comments]) json-data) 

this video is a good introduction: Understanding Specter: Clojure's missing piece

this wiki shows how powerful the navigator is: List of Navigators

restructured my ~/.clojure/deps.edn, cleared the dependencies, instead categorize them into aliases

after that I'll start my quick repl with:

$ clojure -A:dev -A:dev/db -M:repl/rebel

dev/db contains dependencies for database libraries, which I don't often use

babashka can also use dependencies that described in deps.edn

just start it with

bb -cp `clojure -Spath -A:dev` script.clj

the classpath can also put into a enrionment variable

export BABASHKA_CLASSPATH=$(clojure -Spath -A:dev)

then can use normal bb to run the script however this slows down when open a new terminal session, even worse when the directory has deps.edn

I didn't put it into .bashrc instead I'll just export the variable to a specific pane only

Sunday, December 27, 2020

to filter a large map part of its values, found couple ways to do the submap? predicate function:

(defn submap?
  [submap m]
  (clojure.set/subset? (set submap) (set m)))

(defn submap?
  [^java.util.Map submap ^java.util.Map m]
    (.containsAll (.entrySet m) (.entrySet submap)))

the 2nd one doesn't work in babashka

for deep version Alex Miller has one here

testing sql under babashka:

$ brew install postgresql
$ pg_ctl -D /usr/local/var/postgres start
$ brew install borkdude/brew/pod-babashka-postgresql

test connection:

(require '[babashka.pods :as pods])
(pods/load-pod "pod-babashka-postgresql") 

(require '[pod.babashka.postgresql :as pg]) 

(def db {:dbtype "postgresql"
         :host "localhost"
         :dbname "postgres"
         :port 5432})

(pg/execute! db ["select version()"])

create a dummy table:

postgres=# create table dummy (id serial not null primary key, data json not null);

feed json data into it:

(doseq [x data]
  (pg/execute! db ["insert into dummy (data) values (?::json)" (json/generate-string x)]))
postgres=# select data from dummy where data->>'project' = 'foo' and data->>'tier' = 'bar';
Blog Archive