Jim Cheung

Monday, February 01, 2021

there's a quite interesting discussion about REPL driven development on clojureverse

tldr; don't type in the repl when doing RDD, use Rich Comment Forms

watching these two videos on this topic:

found some useful tricks in Sean Corfield's talk:

he started the repl by

$ clojure -M:rebel:reveal:add-libs:test:dev

(reference: seancorfield/dot-clojure: My .clojure/deps.edn file)

I didn't know you can chain aliases like this :D

then by adding , at the end of (comment ...) block, makes it easier to append expressions at the end

(comment
  (ns-public (find-ns 'ring.adapter.jetty))
  ,)


the add-libs also interesting, add this alias to ~/.clojure/deps.edn

:dev/add-libs {:extra-deps {org.clojure/tools.deps.alpha
                            {:git/url "https://github.com/clojure/tools.deps.alpha"
                             :sha "d77476f3d5f624249462e275ae62d26da89f320b"}}
               :main-opts ["-e" "(->>(Thread/currentThread)(.getContextClassLoader)(clojure.lang.DynamicClassLoader.)(.setContextClassLoader,(Thread/currentThread)))"]}

usage:

(require '[clojure.tools.deps.alpha.repl :refer [add-libs]])

(add-libs '{ring/ring {:mvn/version "RELEASE"}})

(require '[ring.adapter.jetty])


when using fpp, use f to select single file or A to select all

once opened in vim, use :tab ball to move buffers into tabs

Thursday, February 04, 2021

saw this video Automating Video Edits with Clojure and ffmpeg on reddit, his flow is quite interesting, so I watched a little bit of his live streams recording: Clojure dev. VOD 01

then I started getting intested in literate programming, I found this video, and it blows my mind: Org-mode, literate programming in Emacs

the stuffs you can do in org mode is beyond my imagination, in the video:

I have to switch to org mode :D


just some notes I took when playing org-mode

for todo, start the item with [ ] and add [/] to the title, use c-c c-c to toggle

in code block

Thursday, February 04, 2021

this is the set up for enable babel

(setq org-confirm-babel-evaluate nil)
(setq org-babel-clojure-backend 'cider)
(setq org-startup-folded nil)
(add-hook 'org-mode-hook 'org-indent-mode)

(org-babel-do-load-languages
 'org-babel-load-languages
 '((emacs-lisp . t)
   (clojure . t)
   (python . t)
   (shell . t)
   (plantuml . t)))

(defun org-babel-tangle-block()
  (interactive)
  (let ((current-prefix-arg '(4)))
    (call-interactively 'org-babel-tangle)))

(eval-after-load "org"
  '(progn
     (define-key org-mode-map (kbd "C-c t") 'org-babel-tangle-block)))

the last two block is define a short key for tangle to file within a single code block without the setup short key is c-u c-c c-v t

also they changed sh to shell in new emacs versions

reference:


swapping alt and ctrl keys, gonna give it a week to test it out one major benefit is now I have both left and right ctrl ...

even though .Xmodmap is no longer auto loaded at X startup, I still think it's much simpler than xkb:

clear Control
clear Mod1
keycode 37 = Alt_L Meta_L
keycode 105 = Alt_R Meta_R
keycode 64 = Control_L
keycode 108 = Control_R
add Control = Control_L Control_R
add Mod1 = Alt_L Meta_L

(use xev to capture keycode)

then I just put it to ~/.profile

xmodmap ~/.Xmodmap

Friday, February 05, 2021

pdflatex command is missing under os x, to intall:

$ brew install mactex

then add the path to emacs:

(setenv "PATH" (concat (getenv "PATH") ":/Library/TeX/texbin"))

I also don't want to evalute code blocks on export, instead of adding eval: never-export header argument, I'll set org-export-use-babel variable or put this line to the file (by m-x add-file-local-variable-prop-line)

# -*- org-export-use-babel: nil; -*-


some basic text formatting in org mode, I need to get used to it

  - /italicised text/
  - *bold text*
  - _underlines_
  - =literal text=
  - ~code~
  - [[LINK][DESCRIPTION]]
  - [[LINK]]
  - +strike-through+

for block of text, use these:

I also have these to set word wrapping

# -*- truncate-lines: nil; word-wrap: t; -*-

Sunday, February 07, 2021

without any tweaking, the org file is pretty hard to read these two simple packages make big difference:


some interesting note taking methods here

related books:


some random notes while watching Literate Devops with Emacs

then use contents[1,0] to refer to contents result's row 1 and col 0

:dir /com.example.com:, this uses tramp file name syntax

define a column1 code block, then in another code block, use :post column1(data=*this*) to do the post-processing


org mode js block is not working, the workaround is adding this variable:

(setq org-babel-js-function-wrapper
      "console.log(require('util').inspect(function(){\n%s\n}(), { depth: 100 }))")

and use return at the end of code block

Tuesday, February 09, 2021

org mode

from: https://orgmode.org/manual/Using-Header-Arguments.html

Language-specific header arguments are also read from properties header-args:<LANG> where <LANG> is the language identifier. For example,

* Heading
  :PROPERTIES:
  :header-args:clojure:    :session *clojure-1*
  :header-args:R:          :session *R*
  :END:
** Subheading
  :PROPERTIES:
  :header-args:clojure:    :session *clojure-2*
  :END:

the :results replace or org-babel-remove-result-one-or-many (c-c c-v k) is not working on my org files

but once set :results drawer it becomes normal again


still getting used to the org mode workflow

since I'm replacing part of my shell workflow to emacs, I have to deal with file paths, so did some changes to make it easier

you can insert file path from counsel-find-file, use m-o i (m-o to bring up the menu) and after set (setq counsel-find-file-at-point t), I can find file in directory that under cursor

I also have a list of a ignored files, for example:

(setq counsel-find-file-ignore-regexp
      (concat
       ;; file names beginning with # or .
       "\\(?:\\`[#.]\\)"
       ;; file names ending with # or ~
       "\\|\\(?:[#~]\\'\\)"))

and I have a shell script to grep stuffs, I tweak the result so it displays full file path as org link:

awk -F ":" -v d=$FULLPATH 'BEGIN{a=""}{b=$1;gsub(/^\.\//, "", b); if (a!=b){print "\n[["d"/"b"]]"; a=b;} print}'

then I can just use mouse right click to open the file in emacs

and I'll use sed to add partial content:

sed -n '/[regex]/,+10p' [file] | head -10

but it's very difficult to ask sed to only match once, I'll just use head


also I found esc esc esc (keyboard-escape-quit) is useful too, even though it close all other windows, but for me it's perfect

normally c-g acts as escape, but it doesn't close mini buffers (use c-] to do so)

and for windows can use winner-undo (c-c left) to bring them back

when I use external keyboard on macbook pro, esc as alt too

Wednesday, February 17, 2021

learning plantuml

setup for org mode:

download PlantUML

(setq org-plantuml-jar-path (expand-file-name "/path/to/plantuml.jar"))

can also add #+STARTUP inlineimages to load images on buffer start

after execute the block, use c-c c-x c-m-v to redisplay inline image

there's Hitchhiker’s Guide to PlantUML! and online server to try out

one surprising feature is it can print json data structure, very useful for me

other useful types including wireframe and calendar

Thursday, February 18, 2021

watched an introduction video about oakes/odoyle-rules, it's interesting but I need more studying on rules engine first

there's another library called Clara


then I decided to invest some time on core.logic I read all core.logic chapters in these books

found few useful ideas, like it's good for generating data, network of relations etc.

also found these articles helpful:

  1. Messin With Core.logic
  2. More Core.logic
  3. Arrowed Core.logic

of course spent some time on clojure/core.logic Wiki

and this one is relatively new: Let's Play Checkers with AI and Clojure

Sunday, February 21, 2021

writing a reverse proxy for local development, just for fun

aleph maybe a good option, but will check on it later

I'll make it simple to use jetty:

(defn ^AsyncMiddleManServlet middle-man-servlet
  []
  (proxy [AsyncMiddleManServlet] []
    (rewriteTarget [req]
      "https://httpbin.org/get")))

(let [server (Server. 8080)
      context (ServletContextHandler. ServletContextHandler/NO_SESSIONS)
      holder (ServletHolder. (middle-man-servlet))]
  (.setContextPath context "/")
  (.setHandler server context)
  (.addServlet context holder "/*")
  (.start server))

there're very few jetty examples online, quit painful to get the thing I want from it

Blog Archive