Wednesday, October 29, 2014

Get terminal to speak after finished a long processing command on OSX

Just append
 && say "Done"

For example;
 $ sleep 10 && say "Done"

This trick could be useful if you are running some tasks and want switch to work on something else while it's running but also want to get back to it immediately after it finished.

Source: How to make the hardware beep sound in Mac OS X 10.6


Wednesday, August 27, 2014

Really stop Clojure's infinite loop future with future-cancel

If you like me, executed future-cancel and the future is still running. This blog post is for you.

I suppose your code is something similar to this:
(def f (future (while true (your-function ... ))))
(future-cancel f)
All you have to do as describe in this SO comment is to replace true with (not (Thread/interrupted)). Example:
(future (while (not (Thread/interrupted)) (your-function ... )))
Because future-cancel will send interrupt signal to the future, Thread/interrupted will be changed to true. Now your future-cancel should work as expected.

Handy note from The Future of Ruby Performance Tooling talk

GoRuCo 2014 - The Future of Ruby Performance Tooling by Aaron Quint

It introduces a few numbers of promising Ruby performance tooling. I'll definitely refer back to this post when I do performance optimization.

Tuesday, July 22, 2014

[PostgreSQL] See SQL queries (without restarting the server!)


1. In postgresql.conf (probably under /etc/postgres/...), uncomment log_statement and set to 'all'
log_statement = 'all'
2. To reload config, sending SIGHUP to postgres server by going to psql shell and execute:
select pg_reload_conf();
    There's an another way to send SIGHUP, please refer to the link below

3. Observe the queries at postgresql.log (probably under /var/log/...)
4. To disable, comment out log_statement and reload config again

log_statement, reloading postgresql config

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

Sunday, July 20, 2014

Run clojure.test inside Light Table

Simply add a line
(run-tests)
and evaluate source code normally (cmd+shift+enter). See the output in the console.

Saturday, June 7, 2014

Clone a PostgreSQL database

At some point in development, you may want to make a copy of your existing development database to play with an unstable new feature. Postgres makes it super trivial to do that by allow us to create a new database by using existing database as a template.

In postgres console, run
=# CREATE DATABASE new_database_name WITH TEMPLATE original_database_name;

Boom!, you got a cloned database named new_database_name.

Credit: Creating a copy of a database in Postgres
PS: I've seen a convenient way to make a clone across remote server too. (Haven't try) How to copy postgres database to another server

Update Aug 27, 2015:
Instead of running command in psql, we can use createdb with -T flag like so
$ createdb -T original_database_name new_database_name
Credit: http://stackoverflow.com/a/6739995 

Collectd PostgreSQL Plugin

I couldn't find this link when searching with google https://www.collectd.org/documentation/manpages/collectd.conf.html#plugin-postgresq...