Tuesday, May 9, 2023

Thursday, February 24, 2022

How to set memory for Solr on MacOS (installed via homebrew)

Modify this file /opt/homebrew/Cellar/solr/X.XX/homebrew.mxcl.solr.plist to add these lines

<key>EnvironmentVariables</key>

<dict>

  <key>SOLR_JAVA_MEM</key>

  <string>-Xmx2g</string>

</dict>


Save and restart Solr


$ brew services restart solr

Thursday, December 2, 2021

How to set Java version for lein

To select specific Java (JDK) to use for leiningen, set environment variable JAVA_CMD

For example,

JAVA_CMD=/path/to/bin/java lein repl

Credit: https://gist.github.com/camsaul/c982019fd915510677236cd4b720a583#gistcomment-3439527 

Saturday, October 2, 2021

Friday, September 24, 2021

Links related to how force macOS to use integrated/discrete graphics


Copied from the above post in case the post is gone


sudo pmset -a gpuswitch 0

-b when on battery
-c when on AC power
-a always

0 iGPU only
1 dGPU only
2 automatic graphics switching

To reset everything back to default:
sudo pmset -a gpuswitch 2

Monday, December 21, 2020

[PostgreSQL] How to check null in jsonb array

 Use jsonb_array_elements  to convert jsonb array to set (queriable similar to normal table) then we can use  where x::text = 'null' to match the null value.

Examples:

=> select x->'id' as id 
from jsonb_array_elements(
'[{"id": 4, "val": [null,1,null]}, 
{"id": 2, "val": [3]}]'::jsonb
) as x, 
jsonb_array_elements(x->'val') as y 
where y::text = 'null';
 id 
----
 4
 4
(2 rows)


=> select x->'id' as id
from jsonb_array_elements(
'[{"id": 4, "val": [null,1,null]}, 
{"id": 2, "val": [3]}]'::jsonb
) as x, 
jsonb_array_elements(x->'val') as y 
group by x->'id' 
having count(x) filter (where y::text  = 'null') > 1;
 id 
----------
 4
(1 row)


[PostgreSQL] How to check if there's a NULL value in array

WHERE array_position(array_column, NULL) IS NOT NULL 

Friday, June 26, 2020

Some usages of jstat

-gcutil

$ jstat -gcutil


This command shows utilization percentage of memory spaces of a java process.

S0: Survivor space 0
S1: Survivor space 1
E: Eden space
O: Old-gen space

GC activities

YGC: Young GC count
YGCT: Time spent by Young GC 
FGC: Full GC count
FGCT: Time spent by Full GC


-gc

$ jstat -gc

Find the current vm heap size by sum value under S0C, S01, EC, OC


More at https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html

[Linux] Visualize parent - child process relationship

$ ps -axf -o pid,ppid,tty,stat,cmd

Credit: Orphan vs Zombie vs Daemon processes

Thursday, July 25, 2019

Compress a file before scp from remote server to local


ssh user@host "tar -zcvf - -C /path/to/dir filename" | tar -zxvf -

Note: only use when it's much faster to transfer a compressed file to your machine than transferring the original one.

Credits:
https://superuser.com/a/1354868
https://stackoverflow.com/a/3035446/1032449

Wednesday, August 22, 2018

Useful commands for observe running JVM process

$ jcmd

List running processes

$ jinfo 

Get details of a process

$ jps -lvm

List running processes with params

Saturday, December 9, 2017

Clojure has lesser typing error problems than the others well-known dynamic typing languages

Give these snippets a try.
// JS
function foo () {
  bar(1)
}
# Ruby
def foo
  bar(1)
end
; Clojure
(defn foo [] 
  (bar 1))

As you can see from the images below, Clojure doesn't allow you to refer to an undeclared symbol. I believe this takes away quite a bit of typing error issues.

Wednesday, July 12, 2017

Config number of file descriptors on Linux

Check file descriptor limit for a process. Vary depending on owner of the process
$ cat /proc/{process-id}/limits
Check current number of file descriptors of a process
$ sudo ls /proc/{process-id}/fd | wc -l
Set file descriptors limit for a user at /etc/security/limits.conf
*    soft nofile 64000
*    hard nofile 64000
root soft nofile 64000
root hard nofile 64000
Check system file descriptor limit
$ cat /proc/sys/fs/file-max
Check current number of system file descriptors
$ cat /proc/sys/fs/file-nr 

Credits:

Collectd PostgreSQL Plugin

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