Installing and Creating a Mac App for Zim Wiki

This guide walks you through installing Zim Wiki and then creating Zim.app so you can open Zim from Launchpad on Mac or keep it in your dock. Let's get started.

  1. If you don't already have Homebrew on your mac, follow these instructions to install it.

  2. In your terminal run the following to install Zim using Homebrew.
     
    brew install zim

    At this point you have Zim installed. The rest of the steps cover how to create Zim.app.

  3. Platypus is an app that takes command-line scripts and converts them into Mac apps.
    Run the following to install Platypus.

    brew install --cask platypus
    

  4. Open Platypus and use these suggested values.
     
    1. Icon: Pick any icon you like or keep the default one.
    2. App Name: Zim
    3. Script Type: Bash
    4. Script Path: choose New and put the following line inside (replacing existing sample content): 
      #!/bin/bash
      PYTHONPATH="/opt/homebrew/Cellar/zim/0.75.1/libexec/lib/python3.11/site-packages" XDG_DATA_DIRS="/opt/homebrew/share:/opt/homebrew/Cellar/zim/0.75.1/libexec/share" exec "/opt/homebrew/Cellar/zim/0.75.1/libexec/bin/zim"  "$@"
      
    5. Interface: none
    6. Identifier: Edit as you see fit
    7. Author: Edit as you see fit
    8. Version: Edit as you see fit
    9. Uncheck all checkboxes
    10. Files to be bundled into the application's Resources folder: leave blank.

  5. Click "Create App"

  6. Save zim.app to the Applications folder
Run and Enjoy!

Dealing with “No space left on device” when partition is not full

When you get the “No space left on device” error on linux, first thing you do it to check your disk space usage.  Often times you notice you still have space, so what could be wrong?

Although your partition is not nearly full, most likely you have too many small or zero-sized files on your disk. So while you have enough disk space, all your available inodes have been exhausted. 

To check this run:
df -ih
If IUse percentage is at or near 100%, then huge number of small files is the reason for “No space left on device” errors.

To find out where inodes are being used run:
echo "Detailed Inode usage for: $(pwd)" ; for d in `find -maxdepth 1 -type d |cut -d\/ -f2 |grep -xv . |sort`; do c=$(find $d |wc -l) ; printf "$c\t\t- $d\n" ; done ; printf "Total: \t\t$(find $(pwd) | wc -l)\n"
After finding the directory with largest number of files, delete any unwanted files to free up some inodes. 

NOTE : If a process is using the files you are deleting, you will need a reboot to free the inodes used.

How to find out where a class is being loaded from

Sometimes you are interested in knowing where your code is getting a certain class from. Knowing this helps you with resolving conflicts.

Let's say in our ClassA, we are calling a certain API from ClassB, and that API is not functioning as we expect. We are interested to see which jar file ClassB is loaded from. To do this add the following line to you code and inspect or print the value of the returned string.

String mysteriousPath = ClassA.class.getResource("ClassB.class").openConnection().getURL().toString();

How to run a command on a filtered file list returned by grep

I often find myself passing a file list returned by some linux command to grep for filtering like below :
ls *.jar | grep test 

Sometimes i like to run a certain command on these filtered results. I achieve this by :

ls *.jar | grep test | while read line; do sha1sum "$line"; done

The generic form is :
<command generating a file list>   |   grep <filter keyword> | while read line; do <command> "$line"; done  

How to check if a port is open on Linux

Sometimes when writing a script/program you need to know if a port your are interested in has an established connection to it or it's free.

My favorite way to do this is to run the following command ( replace PORT with the port number you want to check for ):

netstat -ln | grep :PORT
-l = Show only listening ports
-n = Show port number
 If this command doesn't return anything, it shows that your PORT is available to use.
In your script you can check $? to see the return code of the above command. If it's non-zero, the PORT is available.

One thing to note though is that, this doesn't tell you the status of your network e.g. if PORT is accessible from outside of your notwork.

How to generate a sql script that drops all tables starting with a certain prefix

In some circumstances, you may want to drop all tables in a schema that start with certain prefix. Say for example you like drop all tables starting with the prefix 'TMP_'.

You can execute:

BEGIN
  FOR t IN ( SELECT table_name FROM user_tables WHERE table_name LIKE 'TMP_%' )
  LOOP
    EXECUTE IMMEDIATE 'DROP TABLE ' || t.table_name || ' CASCADE CONSTRAINTS';
  END LOOP;
END;
This block finds and drops all tables whose name start with 'TMP_'.

Another way is to first generate a list of drop statements, save the list as a sql script and finally execute it. Personally I like this way better since it lets me to see and be sure exactly what is going to be removed.

This block generates a list of drop statements for all tables in your schema starting with 'TMP_' :
select 'drop table ' || table_name || ' cascade constraints' || ';'
from   user_tables
where  table_name like 'TMP_%';
You can then take this generated list, save it as a sql script and execute it as you wish.

How to zip files with a pattern in name into a single zip file

To zip files with a certain pattern in their name in a directory, we can combine find and zip command like below :

find <DIRECTORY_PATH> -name \*<PATTERN>\* | zip <ZIP_FILE_NAME>.zip -@ 

Finding out tablespace size, used space and free space in Oracle database

This query which should be run as SYS or SYSTEM user, will give you the following information:

  • Tablespace Name
  • % used
  • Space allocated to tablespace
  • Space used in tablespace
  • Space free in tablespace
  • Number of datafiles used by tablespace

SELECT  a.tablespace_name,
    ROUND (((c.BYTES - NVL (b.BYTES, 0)) / c.BYTES) * 100,2) percentage_used,
    c.BYTES / 1024 / 1024 space_allocated,
    ROUND (c.BYTES / 1024 / 1024 - NVL (b.BYTES, 0) / 1024 / 1024,2) space_used,
    ROUND (NVL (b.BYTES, 0) / 1024 / 1024, 2) space_free, 
    c.DATAFILES
  FROM dba_tablespaces a,
       (    SELECT   tablespace_name, 
                  SUM (BYTES) BYTES
           FROM   dba_free_space
       GROUP BY   tablespace_name
       ) b,
      (    SELECT   COUNT (1) DATAFILES, 
                  SUM (BYTES) BYTES, 
                  tablespace_name
           FROM   dba_data_files
       GROUP BY   tablespace_name
    ) c
  WHERE b.tablespace_name(+) = a.tablespace_name 
    AND c.tablespace_name(+) = a.tablespace_name
ORDER BY NVL (((c.BYTES - NVL (b.BYTES, 0)) / c.BYTES), 0) DESC;

How to find out which jar file a class is loaded from

There are ways to programmatically find out where the java classloader loads a certain class from. But what if you don't have access to the source code and are on a production environment.
In these cases JVM provides you with a nice option :
-verbose:class

So if you are working with a an app server like WebLogic or Tomcat, just modify the appropriate script that sets JVM arguments and you should be able to see output like this in your server log :

 [Loaded java.io.Serializable from C:\Program Files\Java\jdk1.7.0_04\jre\lib\rt.jar]
[Loaded java.lang.Comparable from C:\Program Files\Java\jdk1.7.0_04\jre\lib\rt.jar]
[Loaded java.lang.CharSequence from C:\Program Files\Java\jdk1.7.0_04\jre\lib\rt.jar]
..............................................................................
..............................................................................
..............................................................................

Best way to transfer large file or resume dropped ftp/scp file transfers


When transferring large files your first choice should be rsync, since it gives you the ability to resume unfinished/dropped transfers. However, if you started a large file transfer with ftp/sftp or scp and the connection was lost during the transfer, you don't need to start over again. Simply run rsync the following way and it will resume your transfer :

rsync --partial --progress --rsh=ssh <USER>@<HOST>:<REMOTE_FILE_PATH> <LOCAL_FILE_PATH> 

This command is what should be used for large file transfers.

How to create an executable jar with 3rd party dependencies included in the jar

If you have written a small java utility that has dependencies on other 3rd party jar and you would like other people to use it without building your jar, you will need to include those jars in your jar. To do this you need to use the maven-assembly-plugin .

So inside <build> ... <plugins>  of your pom.xml put

<plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>your.fully.qualified.MainClass</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
</plugin>

Then run maven using :  mvn clean compile assembly:single

How to install VNC on Redhat and avoid getting "font catalog is not properly configured" error

 yum install -y  tigervnc-server tigervnc-server-module libXfont pixman xterm xorg-x11-twm

Setting YUM proxy settings in Redhat

If you are behind a proxy YUM won't be able to connect to its repositories. To fix this you will need to add your proxy setting to /etc/yum.conf

If you are using an anonymous proxy, only the following line needs to get added to yum.conf

proxy=http://<poxy-server>:<proxy-port>/

In case your proxy server requires authentication also add the following lines in addtion to the above

proxy_username=<proxy-user>
proxy_password=<proxy-password>

Determining schemas inside an Oracle data pump/dump file

Have you ever wondered how you can findout the schema or tablespace names contained within an Oracle Datapump dump or export?

Well, there is a way and it's an easy one:

First make sure ORACLE_SID and ORACLE_HOME is corectly set and Oracle binaries are in your PATH. Then using a user with appropriate privillages execute :

impdp \'/ as sysdba\' dumpfile=<YOUR_DMP_FILENAME>.dmp sqlfile=<OUTPUT_FILENAME>.txt

After this is done, simply open the text file for viewing and look for statements like :
CREATE USER ......

How to setup SSH private and public keys

  • 1)
    ssh-keygen -t rsa -b 4096 Generating public/private rsa key pair.
    Enter file in which to save the key (~/.ssh/id_dsa): 
    (just press Enter) 
    Enter passphrase (empty for no passphrase): 
    (enter a passphrase and then press Enter or if you don't want want one just press Enter) 
    Enter same passphrase again: 
    (repeat last action) 
    Your identification has been saved in ~/.ssh/id_rsa
    Your public key has been saved in ~/.ssh/id_rsa.pub
    The key fingerprint is:
    A long string appears here
    %
  • 2)
    Paste the content of the  ~/.ssh/id_dsa.pub file that just got generated on your local host into the file ~/.ssh/authorized_keys on the remote host and save.
  • 3)
    Set proper permissions on your local host keys and .ssh directory:
    chmod 700 ~/.ssh
    chmod 644 ~/.ssh/id_rsa.pub
    chmod 600 ~/.ssh/id_rsa
    set proper permissions on your remote host authorized_keys and .ssh directory
    chmod 700 ~/.ssh
    chmod 644 ~/.ssh/authorized_keys

How to find the 10 largest file or directories in Linux


This finds the largest 10 files :

find . -type f -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

This finds the largest 10 directories:

find . -type d -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

You can easily change -10 to -n where n is the number of files/directories you are trying to find.

Killing all processes containing a specific pattern in their process name

Say you want to kill all processes spawned from your Oracle Home. In Linux/Unix there is a nice command that lets you achieve this very easily.

If your Oracle Home is /u01/app/oracleHome then any oracle related process will have oracleHome in it's name. To kill all such processes at once issue the command :

pkill -9 -f oracleHome