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

Monday, July 13, 2015

[PostgreSQL] List index usage

Update: This query is much cooler Index size/usage statistics


In psql console, connect to the database you want to check its indexes usage. Then execute this query.
# SELECT * FROM pg_stat_user_indexes ORDER BY idx_scan DESC;
If your database is manage by Rails's schema, you could filter out auto generated public key indexes like so
# SELECT * FROM pg_stat_user_indexes WHERE indexrelname NOT LIKE '%_pkey' ORDER BY idx_scan DESC; 

Tuesday, June 16, 2015

Sort file name by number of changes in git history

git log --pretty=format: --name-only | sort | uniq -c | sort -rg | less
Literally copied from the answer of "Finding most changed files in git"

Tuesday, June 9, 2015

[PostgreSQL] Using some indexes from Composite index

If we had a composite index on three fields: we would be able to use it for queries on the first field, for queries on the first two fields and for queries involving all three fields, but not on any other field combination.
Copied directly from How to stop worrying and love your Postgres indexes 

Monday, May 25, 2015

[PostgreSQL] List running queries

In psql, run this command
select * from pg_stat_activity where datname = YOUR_DB_NAME and state = 'active'
 You might also what to order the result by query_start or state_change

Saturday, April 4, 2015

Start lein repl with test profile

When you try to run lein repl with test profile, you'll get warning/error message similar to this.
$ lein with-profile test repl
Warning: no nREPL dependency detected.
Be sure to include org.clojure/tools.nrepl in :dependencies of your profile.
Error loading clojure.tools.nrepl.server: Could not locate clojure/tools/nrepl/server__init.class or clojure/tools/nrepl/server.clj on classpath: 
Error loading complete.core: Could not locate complete/core__init.class or complete/core.clj on classpath: 
Exception in thread "main" java.lang.ClassNotFoundException: clojure.tools.nrepl.server, compiling:(/private/var/folders/7d/98yf91rn0yz6wbh56h5q7rkh0000gn/T/form-init2792809345387087761.clj:1:1340)
The reason is because unlike default profile, tools.nrepl isn't added as dependency for test profile. You can verify this by comparing the output between lein pprint (or lein with-profile default pprint) and lein with-profile test pprint.

To fix this error, you can use the feature that lein provided combining profile like so;
$ lein with-profile default,test repl
With the command above, lein should start the repl without any errors.