Jim Cheung

Monday, August 03, 2015

when following examples of Clojure Web Development Essentials, found they're not working. turns out that Luminus 2.0 has quite a few big changes.

so basically anything relates to lib-noir is useless, that sucks.

Tuesday, August 04, 2015

playing with the Luminus guestbook tutorial since examples in the book are not working.

when doing the final step uberjar, to run with the h2 db will need to set a database url property (below just reuse the dev db file):

java -Ddatabase.url=jdbc:h2:./guestbook_dev.db -jar target/guestbook.jar

because uberjar will set the env to production (inside project.clj). same, to enable nrepl for the when running the jar, give jvm the property:

java -Dnrepl.port=7000 -Ddatabase.url=jdbc:h2:./guestbook_dev.db -jar target/guestbook.jar

about why database.url will become :database-url in profiles.clj, see the environ project page (actually environment variables work as well, and is the docker way)

to setup production tables:

java -jar target/guestbook.jar migrate

for server setup, deployment page has a very nice introduction.

lein-ancient is a lein plugin to check outdated dependencies.

Friday, August 07, 2015

reading Clojure Programming for fourth time, because the examples in it are so elegant:

(let [log-capacity 5000
      events (agent [])]
  (defn log-event [e]
    (send events #(if (== log-capacity (count %))
                    (-> % (conj e) (subvec 1))
                    (conj % e)))
    e)
  (defn events [] @events))

I may need to update the reading notes as well ...

Friday, August 07, 2015

also found this snippet, process a message at a maximum rate of 1 per second:

(while true
  (let [t (timeout 1000)]
    (process-message queue)
    (<!! t)))

however, someone commented with this:

repeat
do in parallel
call process_message(queue);
wait for 1 second;
end;
end

it's Gensym G2, never heard of it, not much details even on google.

Saturday, August 08, 2015

bringing out with the wedge keyboard again, however found Terminal IDE is not working under lollipop. installed termux instead, because it comes with apt-get, got everything I need actually. (for a list of packages, go check their apt repo).

found few interesting packages:

some will try on desktop:

also they got ruby, nodejs, python, perl, c, c++ (maybe some java tools? saw dx, jack, ecj)

start doing 4clojure (there is an unofficial client for android), two of questions I found myself doing pretty ok :p

;; #20 Write a function which returns the second to last element from a sequence.
(comp second reverse)
;; #22 Write a function which returns the total number of elements in a sequence.
#(reduce + (map (constantly 1) %))

and for fibonacci sequence

(defn fib [n]
  (take n
    (map first (iterate (fn [[x y]] [y (+ x y)]) [0 1]))))

Monday, August 10, 2015

found that Herding Code is a good podcast too.

having difficulty on 28. Flatten a Sequence. actually many clojure core functions are just macros, take a look at the source code will eventually get the answer:

(filter (complement sequential?)
      (rest (tree-seq sequential? seq x)))

but tree-seq is not that easy to understand, there's another solution found online which is nice too:

(fn f [s] (if (sequential? s) (mapcat f s) (list s)))

however, most of solutions I followed use coll? instead of sequential?.

for 32. Duplicate a Sequence, my solution is:

(fn [s] (reduce (fn [acc x] (conj acc x x)) [] s))

actually the solution is as easy as: #(interleave % %) or mapcat #(list % %):

this is the thing I like about 4clojure the most, you can find the most elegant solution for a specific problem. and 4clojure notes deserves its own page.

continue reading Big Data, need to setup a vm for the examples, however, it is not easy that any of following looks complicated:

Chapter 7 uses JCascalog (created by book author Nathan Marz, who also created Apache Storm), but I can just use the clojure version: Cascalog :-p

for JDK 8 Massive Open and Online Course: Lambdas and Streams Introduction , passed 3 quizzes without watching videos and slides. but for lesson 3, I did failed on the first attempt, may need to go over those slides.

Tuesday, August 11, 2015

really like ranger, first get a set of config files under home directory:

ranger --copy-config=all

for serious tasks I still prefer use normal command line mode, to open a shell under the folder you're on, press S and when exit will return to ranger.

for os x, brew install ranger, and few things need to be done:

  1. ranger reads .bashrc, so make one (soft link or source from .bash_profile)
  2. use iTerm2 v2.9, current 2.1.1 doesn't support inline images.
  3. update ~/.conf/ranger/rc.conf:
    set preview_images true
    set preview_images_method iterm2

it's the fastest image previewer ever ...

so I have a very good reason to run a emacs server now.

Thursday, August 13, 2015

ralesi/ranger brings ranger to emacs.

after How Google Invented an Amazing Datacenter Network Only They Could Create (paper, video), these is One trillion edges: graph processing at Facebook scale (paper), things are getting too big now.

Sunday, August 16, 2015

finally deployed my first clojure site, a tiny one. the experience is great.

for tiny web projects, compojure is good enough for me. if I need more functions, I'll start a Luminus project, or mix and match with different kind of libraries, it's very easy, they're all built around the ring library.

also the deployment is easy, just a jar file and run it in a docker container. actually I found my jre 8 image is smaller than nodejs ...

of course jvm will have a larger memory footprint (120MB vs 20MB, i have another nodejs app just needs 3MB) if you have profiled your app, you can try Tuning For a Small Memory Footprint, but 100MB is already considered small for jvm web apps.

Wednesday, August 19, 2015

to make multiple new diretories:

$ mkdir -p build/{specs,release}

to use heredoc write to new file:

$ cat <<EOF > myfile
...
EOF

a simple way to sign a package: distribute gpg public keys to nodes, use gpgcheck to verify.

Thursday, August 20, 2015

failed the test by whoami.filippo.io, updated .ssh/config by adding these at the bottom:

Host *
  IdentitiesOnly yes
  ForwardX11 no
  ForwardX11Trusted no
  ForwardAgent no
  User admin
  IdentityFile ~/.ssh/fake.id_rsa

and set a password for existing private keys:

ssh-keygen -p -f keyfile

on mac os x, start emacs daemon

/Applications/Emacs.app/Contents/MacOS/Emacs --daemon

running /Applications/Emacs.app/Contents/MacOS/bin/emacsclient default is under terminal mode (btw, F10 open menu), use -c to open a gui frame.

Friday, August 21, 2015

under os x, to force ssh agent expires your entered password, add following to /System/Library/LaunchAgents/org.openbsd.ssh-agent.plist under /usr/bin/ssh-agen line:

<string>-t</string>
<string>30m</string>

Tuesday, August 25, 2015

another funny trick, to start a script on boot, add this line to crontab:

@reboot /opt/script.sh

Saturday, August 29, 2015

trying Loggly, they provide a setup script for quick start, easy.

but i'm using docker, so might need to setup manually: Docker Logging & Syslog

update: this way is more simple: Linux Log File Monitoring

Blog Archive