Command line grep

Here’s a pretty nice combination of parameters for command line grep using egrep (which supports regex):

egrep -rHnC1 "bprajb"

This will search in the current directory recursively through all files that match the word “praj” (regex boundary b tags) and return the file name and context (1 line either side of the match) with line numbers.

For example here’s the resut with the matching word highlighted as well on the terminal.

MySQL compare strings by case

Here’s one method of comparing strings by case in MySQL. You can use the md5 function to hash the string and compare to its lower case value.

This example is for checking for usernames that are not lower case in moodle.

select username, md5(username), md5(lower(username))
from mdl_user
where deleted = 0 and suspended = 0
and md5(username) != md5(lower(username));

If the md5 hash when the string is lower cased is different to the current md5 hash you will get a result.

$_SESSION global is empty

If you find that your global $_SESSION variable is empty there can be several reasons, here are a few:

  • The session.save_path is invalid (does not exist) or is not writable.
  • The session.cookie_secure is set to true but you not using a secure site (SSL/https).
  • The session.cookie_domain is set to a domain that does not match your site – very common if setting up a dev or test environment from a production site with a public domain.

soapUI 5.x hangs on Mac OSX

I’ve had this issue on OSX Mavericks and Yosemite on soapUI 5.x versions. Here’s a fix that disables the browser in soapUI which seems to cause it to hang.

Open /Applications/ (adjust to suit your version).

Editvmoptions.txt and add line: -Dsoapui.browser.disabled=true

Open /Applications/ (adjust to suit your version)

Edit and uncomment line: -Dsoapui.browser.disabled=true

PHP Session Save Path

You can find the session.save_path through php info or using the command line:

php -i | grep save_path

E.g. /var/lib/php/session

Once you have that, you clear PHP sessions by going into that path and clearing out the relevation session files.

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.

Spreadsheet Fu for Week day (text) for a given date

Use the following formula to get the day of the week (e.g. Friday) for the given date field:


The WEEKDAY function returns the day of the week as a number (1-7) and the TEXT function formats that number into the corresponding text value for that day of the week e.g. 1=Sunday…7=Saturday.