Useful Regular Expressions

Match everything up to a pattern
.+?(?=PATTERN)

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();