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:
- Stuart Halloway on Repl Driven Development
- REPL Driven Development, Clojure's Superpower by Sean Corfield (slides)
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:
- keep different code blocks under same session (variables can be shared)
- use result from another code block written in different programming language
- noter to navigate pdf file from org mode headings
- create build and run docker image without leaving emacs
- execute code block inside a docker image!!
- tangle (write) code block to file inside docker image
- plantuml to create flow chart from code block
- calc combine with table, works like a spreadsheet
I have to switch to org mode :D
just some notes I took when playing org-mode
c-enter
: add new headingm-enter
: add new itemc-c *
: toggle headingc-c c-u
: upc-c c-n
: nextc-c c-p
: previousc-x n s
: narrow to subtreec-x n b
: narrow to blockc-x n w
: widenm-up
: move upm-down
: move downm-left
: promote headingm-right
: demote heading<s
: start code blockc-c .
: insert datec-u c-c .
: insert date timec-c c-l
: insert linkc-c c-q
: set tagsc-c c-t
: toggle todoc-c >
: show calendarc-c c-x p
: insert propertyc-c c-x c-v
: toggle inline imagesc-c |
: convert to table
for todo, start the item with [ ]
and add [/]
to the title, use c-c c-c
to toggle
in code block
c-c '
: open mini popup buffer, with language mode support
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:
<s
: source code block<e
: example block (mono fonts)<q
: quote block<c
: center text block<l
: latex code<v
: verse, preserve line breaks, indentation and blank lines
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
:exports code
: just export code block:exports both
: export both code and result:dir <dir>
: to execute code block within<dir>
:var
to insert arguments:results table
: convert result to table
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
- Clojure Data Structures and Algorithms Cookbook
- Clojure: High Performance JVM Programming
- Learning ClojureScript
- The Joy of Clojure, Second Edition
- Clojure Programming Cookbook
found few useful ideas, like it's good for generating data, network of relations etc.
also found these articles helpful:
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
- Newer Entries
- 2021 March
- 2021 April
- 2021 May
- 2021 June
- 2021 August
- 2021 September
- 2021 December
- 2022 March
- 2022 April
- 2022 May
- 2022 June
- 2022 July
- 2022 August
- 2022 September
- 2022 October
- 2022 November
- 2022 December
- 2023 January
- 2023 February
- 2023 March
- 2023 April
- 2023 July
- 2023 August
- 2023 September
- 2023 October
- 2023 November
- 2023 December
- 2024 January
- 2024 February
- 2024 March
- 2024 April
- 2024 May
- 2024 June
- 2024 August
- 2024 September
- 2024 October
- 2024 November
- Older Entries
- 2021 January
- 2020 December
- 2020 November
- 2020 October
- 2020 September
- 2020 August
- 2019 December
- 2019 November
- 2019 October
- 2019 July
- 2019 May
- 2019 April
- 2019 March
- 2019 February
- 2019 January
- 2018 December
- 2018 November
- 2018 October
- 2018 September
- 2018 August
- 2018 July
- 2018 June
- 2018 May
- 2018 April
- 2018 March
- 2018 February
- 2018 January
- 2017 December
- 2017 November
- 2017 October
- 2017 September
- 2017 August
- 2017 July
- 2017 June
- 2017 May
- 2017 April
- 2017 March
- 2017 February
- 2017 January
- 2016 December
- 2016 November
- 2016 October
- 2016 September
- 2016 August
- 2016 July
- 2016 June
- 2016 May
- 2016 April
- 2016 March
- 2016 February
- 2016 January
- 2015 December
- 2015 November
- 2015 October
- 2015 September
- 2015 August
- 2015 July
- 2015 June
- 2015 May
- 2015 April
- 2015 March
- 2015 February
- 2015 January
- 2014 December
- 2014 November
- 2014 October
- 2014 September
- 2014 August
- 2014 March
- 2014 February
- 2014 January
- 2013 December
- 2013 October
- 2013 July
- 2013 June
- 2013 May
- 2013 March
- 2013 February
- 2013 January
- 2012 December
- 2012 November
- 2012 October
- 2012 September
- 2012 August