Sunday, July 10, 2016

Why I'm writing in Clojure and Ruby

Sandy Metz. Around the 35th minute of

I came from Smalltalk, and I segued to Java a little bit, hated every minute of it, and then fell saved by Ruby. And so I have spent the last 20 some years writing code in languages that had enormous faith in my ability to do the right thing. And along with that enormous faith in my ability to do the right thing, they gave me the freedom of everything.

(My summary: She talked to a guy after a conference who asked her how using dynamic language could possibly work, and she answered)

You just trust people. And he said they are not trustworthy. And I said well, they shouldn't write Ruby, they should write Java. I really prefer languages that allow me to shoot myself in the foot if I do but give me the power to do that.

  • Has enormous faith in my ability to do the right thing
  • Give me the freedom of everything
  • You just trust people

These are exactly why I'm writing in Clojure and Ruby.

Sunday, June 26, 2016

How to indent in Facebook post/comment on OS X

  1. Put your cursor on the text box of the post/comment you want to indent
  2. Go to the menubar at the top of the screen
  3. Edit > Emoji & Symbols
  4. On Characters window, click setting icon. It's a gear nearly the top-left of the window, close to 3 color buttons.
  5. Choose Customize Lists...
  6. Choose Code Tables > Unicode and Done
  7. Go to Unicode section at the end of the most left panel of Characters window
  8. Look for the character number 3000. It's called "IDEOGRAPHIC SPACE"
  9. Double click on that character to insert it to your text box. You can insert it as many characters as you want.
  10. Save your post/comment. This empty space should help you indent your text properly.
  11. You can add this character to Favorites section by click "Add to Favorites" button under the thumbnail of the character in the right most panel of the Characters window.
  12. Or you can just go to "Frequently Used" section and the character should already be there.

Saturday, June 4, 2016

How to comment in Clojure and my use case of each approach

There are 3 ways to comment code in Clojure. I personally use all 3 of them depending on the situation.

; [semicolon]
It's similar to // or # in the other languages. Source code from the point you put it until the end of line won't be executed.

I use it for a quick short documentation of the code or when I want to try remove a line quickly. It's the most easy to use one because all the IDEs and text editors support it out of the box.

(comment (expr)) [comment macro]
Use it to wrap expression you don't want it to be run. It's more convenient to use when using with tool to help maintaining balance of the parentheses such as paredit or parinfer.

I use this one a lot in while I'm doing interactive development via repl. I always put the code to execute function the I'm implementing in the same file with the function definition so that I can quickly test out when I change something. I wrap that code with comment macro so that I won't be execute automatically by Clojure. When I want, I send only the inside code to the repl to see what's the output of the function.

#_ reader macro
It comments out an expression that follows it, from opening to closing parens

This one I've just learnt about it recently. It comes in handy when I don't want to care about where is the end of the expression. I just put #_ and thing will behave as I expected. It's great for multiline comment, similar to the comment macro with a less keystrokes.

ClojureBridge is done a better explanation than me

Friday, May 20, 2016

Workaround for creating chart from messages with non-numeric fields in Graylog

As we all know, Graylog doesn't support creating a chart on non-numeric value at the moment. There is a neat workaround suggested by Drew Miranda that can fulfil this functionality. I'll try to rephrase it step by step.

  1. Go to Graylog UI page
  2. Make a search for the field and value that you want to represent as a chart
  3. Around the bottom left corner of search page, click all fields
  4. Find timestamp field and generate chart from it
  5. Around top right of the chart, Customize > Value > Total
That's it for a single value chart. But if you want a chart to contain multiple values, keeps going
  1. Redo 2-5 again for different fields
  2. Click and hold on hamburger menu button at the top right of each, drag to merge them
That's neat right?

Thursday, May 19, 2016

Add local registry mirror to docker daemon on systemd ubuntu (after 15.04)

After docker installation, follow this steps

  • Create directory /etc/systemd/system/docker.service.d if not exist
  • Create mirror.conf file inside that directory. The name "mirror" can be changed to anything.
  • In the file, add this lines
ExecStart=/usr/bin/docker daemon -H fd:// --registry-mirror=http://registry-host:registry-port
  • registry-host is hostname/ip of your local registry mirror
  • registry-port is port of your local registry mirror
  • Flush the change with $ sudo systemctl daemon-reload
  • Restart docker with $ sudo systemctl restart docker
  • Check if the change is successfully applied with $ systemctl status docker,  your config should appear somewhere in the command output.
Tested on Docker 1.11, Ubuntu 15.10 & 16.04

If you want more explanations about these commands, please refer to follow links. Thank you for all of them for providing me a direction to solve the issue and also come up with this post.

Thursday, May 12, 2016

Delete unused (orphaned) Docker volume

Since Docker 1.9, there's an easy way to find unused volumes and delete them.

To list unused volumes, use this command

$ docker volume ls -qf dangling=true

To delete them, use

$ docker volume rm $(docker volume ls -qf dangling=true)

Credit: I copied the whole thing from this SO answer

Tuesday, May 10, 2016

[Fixed] WARN Not all child routes satisfy compojure.api.routing/Routing. {:path nil, :method nil}, invalid child routes:

I had this error in my client app that uses compojure-api. The cause of this problem is that I put the static assets routing configuration in the wrong place. We put (route/resources "/") inside defapi which is a place for api routing configurations. So to fix this, we create a defroutes for static assets routing config and merge this defroutes with defapi before giving it to webserver as a ring handler. At the end, the code look something like this.

(ns my.namespace
  (:require [compojure.api.sweet :refer [defapi]]
            [compojure.core :refer [defroutes routes]]
            [compojure.route :as route]))

(defapi app

(defroutes site
  (route/resources "/"))

(defn handler []
  (route site app))