Praj's Blog

Escaping variables inside other variables in bash scripts

Say you have a variable that comprises of another variable like so:


The above won’t work as bash will interpret the underscore after $var_name as part of the variable name and look for a variable called $var_name_and_extension and not find it.

Two ways to solve this:

Enclose in curly braces as follows:


Use double quotes to delineate between the variable name and the string:


Find constants in your PHP code base

The following grep command will search for any constants such as define('CONSTANT', 1) within your PHP code base so you can see their values. Useful as many applications store the constant’s value in the database and not the constant’s friendly name.

This requires regular expressions, hence the use of egrep.

egrep --include *.php "(define)(.*)" -r *

Mac Slack Client Keeps Crashing

Found this morning that my Mac Slack client (v1.13, build 2813) kept on crashing on start up (I’m running Mac OSX 10.9 Mavericks). It was working fine until the latest Mac update (Security Update 2015-006 version 1.0 18/08/2015).

The crash reporter tells me something along the lines of this:

  Application Specific Information:
  *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not make an sqlite3 statement for: CREATE TABLE IF NOT EXISTS downloads (team         TEXT NOT NULL, token        TEXT NOT NULL, href         TEXT NOT NULL, state        TEXT NOT NULL DEFAULT 'pending', http_status  TEXT NOT NULL DEFAULT '', file_path    TEXT NOT NULL DEFAULT '', file_exists  TEXT NOT NULL DEFAULT 'false', mime_type    TEXT NOT NULL DEFAULT '', start_ts     TEXT NOT NULL DEFAULT '', end_ts       TEXT NOT NULL DEFAULT '', base64_png   TEXT NOT NULL DEFAULT ''); | (
  terminating with uncaught exception of type NSException
  abort() called

Uninstalling/reinstalling didn’t fix the issue. I ended up deleting the following folder in my home directory:


This obviously holds some sort of data, so I’m not sure of the entire consequences of doing this. For a start, you need to sign into all your accounts again. It doesn’t appear to impact your slack history or anything like that.

Converting strings to dates in MySQL

Use the str_to_date function and provide the format you need to it. for example, if you have a field called created_dttm with a date which is in the format “24-07-2015 06:00:00” you can use this to convert into a MySQL date so that you use various MySQL date functions on it.

select str_to_date(created_dttm, '%d-%M-%Y %H:%i%s');

See this list for all the date formats.

Wireless Router & Headset conflict

I have an ASUS AC68U wireless router and lLgitech G930 wireless headset, and I kept finding that my headset with drop out. After some research, I came to the conclusion that I should try changing the wireless control channel on my router.

The control channels range from 1 to 11, so the best options to avoid interference are 1, 6 or 11 (i.e either end or the middle of the spectrum). I tried 11, then 6 and both weren’t much better, however control channel 1 seemed to do the trick. You can tell it works because a restart of the wireless on the router after changing the channel would cause a drop out, and this happened immediately on channels 6 and 11, but not on 1.

Fixing Mac Book Pro – No Internal Speakers

This happens on occassion on the Mac Book Pro – You lose the internal speakers and are only left with digital out. A sign this has occurred is that the red light in the headphone port (where you plug in your headphones) will be on.

There are numerous ways to try to fix this, anything from system preference tweaks all the way to opening up your Mac Book.

Here’s the simplest thing you can try (and it does seem to work with a bit of persistence):

  1. Open System Preferences > Sound
  2. Plug in your headphones as you won’t have control over the volume/mute of the digital output
  3. Once headphones shows up on the list, move the volume slider up and down and check/uncheck the mute button.
  4. Unplug your headphones
  5. Check if digital out has disppeared and been replaced by Internal Speakers.
  6. Rinse and repeat. Note it can take several attempts before this works. For example, after 3 times, I finally had internal speakers appear for a second then disappear back to digital out. On the fifth attempt, internal speakers appeared again and this time stayed. Basically what you are doing is trying to get the Macbook to recheck its sensors and correctly revert to internal speakers.

Good luck.

SublimeLinter (with PHP)

SublimeLinter is a great syntax/error checking plugin for SublimeText.

Here are the steps to get it working (for example with PHP):

Note if you get stuck, use


to open your sublime text console and look for any errors. Also check the very comprehensive documentation: