Friday, November 27, 2015

Terminal.app doesn't save history in El Capitan and you are using RVM

The cause is described here https://github.com/rvm/rvm/issues/3540#issue-113491283
The fix is here https://github.com/rvm/rvm/issues/3540#issuecomment-152824133

I copied the fix here just in case it's removed in the future

Another option is to create .bash_logout with a single line:

shell_session_update

Wednesday, November 4, 2015

Setup Debian/Ubuntu apt package cache server with Ansible

Install elnappoo.apt-cacher-ng with Ansible Galaxy and then follow the instruction in the README tab or README in the github repository. Refer to the test.yml file as an example. If you cache server doesn't have ufw running, don't forget to set apt_cacher_ng_setup_ufw: False

Thursday, October 29, 2015

How to get calller function in Clojure

I posted this question on Clojurians slack channel.
What's clojure equivalent of ruby's `caller` method? http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-caller
To put it another way, if a function is call from multiple places, at runtime, is there a way to print out caller for debugging purpose?
Thanks to Alex Miller. He answered
the Thread class has methods to inspect the stack
(Thread/dumpStack) will just dump that thread's stack to stderr
or (Thread/getStackTrace) gives you an array of StackTraceElement's that you can traverse and do whatever
Basically, we can just use Java's Thread class. To be more precise, getStackTrace is an instance method so we have to call it this way.
(.getStackTrace (Thread/currentThread))
We'll get back Java's array of StackTraceElement class.

You can copy and just use a function I wrote here https://gist.github.com/visibletrap/bdf16dd5596c9a72ec73

Tuesday, October 13, 2015

Convert FLV to MP4 with FFmpeg

Only for no AV recording
$ ffmpeg -i input.flv -c copy -copyts output.mp4
Tested on: OS X 10.11
Credit: http://superuser.com/a/860127

Thursday, September 24, 2015

How to clear terminal screen in Clojure

Print some ANSI characters
(print (str (char 27) "[2J")) ; clear screen
(print (str (char 27) "[;H")) ; move cursor to the top left corner of the screen
Credit: http://codereview.stackexchange.com/questions/17603/critique-my-clojure-game-of-life-code

Find out which process is using a particular port

I was never be able to remember options for netstat command. This option for lsof seems to be easier. Note that it requires a root access.
lsof -i :80
Change 80 to any port number you like.

Creadit: http://unix.stackexchange.com/a/106572

Tuesday, August 25, 2015

On OS X, Java Control Panel and Terminal show different Java versions

That's because Java Control Panel shows version of JRE for normal Mac user, but command line on Terminal shows version of JDK. To update JDK version, need to download the full package from Oracle website.
Older JDK version won't be replace automatically to allow us to switch back if we want. So we have to manually remove it by following the instruction here http://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html#A1096903

Credit: http://stackoverflow.com/a/28254333