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:
- ranger: file manager with vi key bindings.
- jq: parse json data
- pathpicker (wow, they have this, it is very new)
- silversearcher-ag: a faster grep
- ttyrec: a tty recorder
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:
- Cloudera QuickStart VM
- Hortonworks Sandbox
- Vagrant + Cascading + Hadoop 2 Cluster
- vagrant-hadoop-2.4.1-spark-1.0.1
- Install a Virtual Apache Hadoop Cluster with Vagrant and Cloudera Manager
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:
- ranger reads
.bashrc
, so make one (soft link or source from.bash_profile
) - use iTerm2 v2.9, current
2.1.1
doesn't support inline images. - 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
- Newer Entries
- 2015 September
- 2015 October
- 2015 November
- 2015 December
- 2016 January
- 2016 February
- 2016 March
- 2016 April
- 2016 May
- 2016 June
- 2016 July
- 2016 August
- 2016 September
- 2016 October
- 2016 November
- 2016 December
- 2017 January
- 2017 February
- 2017 March
- 2017 April
- 2017 May
- 2017 June
- 2017 July
- 2017 August
- 2017 September
- 2017 October
- 2017 November
- 2017 December
- 2018 January
- 2018 February
- 2018 March
- 2018 April
- 2018 May
- 2018 June
- 2018 July
- 2018 August
- 2018 September
- 2018 October
- 2018 November
- 2018 December
- 2019 January
- 2019 February
- 2019 March
- 2019 April
- 2019 May
- 2019 July
- 2019 October
- 2019 November
- 2019 December
- 2020 August
- 2020 September
- 2020 October
- 2020 November
- 2020 December
- 2021 January
- 2021 February
- 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
- 2024 December
- Older Entries
- 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