I wrote the below BASH function today. It's good because it performs super well compared to the alternative commands (which are commented out below above the new commands):

own() {

  echo "Taking ownership..."
  #chown -R jj5:jj5 .
  find . \! -user jj5 -or \! -group jj5 -execdir chown jj5:jj5  "{}" \;
  [ "$?" = 0 ] || { echo "Could not take ownership in '$PWD'."; exit 1; }

  echo "Fixing directory permissions..."
  #find . -type d -execdir chmod u+rwx "{}" \;
  find . -type d -and \( \! -perm /u=r -or \! -perm /u=w -or \! -perm /u=x \) -execdir chmod u+rwx "{}" \;
  [ "$?" = 0 ] || { echo "Could not fix directory permissions in '$PWD'."; exit 1; }

  echo "Fixing file permissions..."
  #find . -type f -execdir chmod u+rw "{}" \;
  find . -type f -and \( \! -perm /u=r -or \! -perm /u=w \) -execdir chmod u+rw "{}" \;
  [ "$?" = 0 ] || { echo "Could not fix file permissions in '$PWD'."; exit 1; }


The basic premise is don't do work which doesn't need to be done!

NetBeans PHP “Invalid include path”

So I migrated my projects from a Debian 8 (Jessie) system to a Debian 9 (Stretch) system. The default NetBeans installed by apt-get install netbeans on Strech was 8.1, and it didn't include PHP support, so I manually installed NetBeans 8.2.

When I opened my old projects I got an error about an invalid global PHP include path.

So initially I edited ~/.netbeans/8.2/ to change the settings (to remove /usr/share/php5, because in Stretch I'm running PHP 7.0). But that didn't work. Each time I ran NetBeans the file was overwritten with the old php5 directory.

So then I found ~/.netbeans/8.2/config/Preferences/org/netbeans/modules/php/project/ In there I edited the phpGlobalIncludPath and removed the /usr/share/php5 directory.

Then when I reopened NetBeans all of my projects opened properly without an error! Everything is easy when you know how!

Navigate to matching brace in NetBeans

So I wanted to know the keyboard shortcut to navigate between matching braces in my PHP (and other) code in NetBeans. I'm running NetBeans 8.2. So I searched and found General Editor Features which said "to find a shortcut for a specific command, type the command name in the Search field." So the Search field they're talking about is on the Keymap screen under Tools -> Options. After creating myself a custom Keymap Profile based on the NetBeans default settings I searched in the 'Search:' box for 'match' and found 'Insertion Point to Matching Brace' which is Ctrl+OPEN_BRACKET. Everything is easy when you know how!

PDO: Execute a prepared statement using array for IN clause

See Example #5 here.

/* Execute a prepared statement using an array of values for an IN clause */
$params = array(1, 21, 63, 171);
/* Create a string for the parameter placeholders filled to the number of params */
$place_holders = implode(',', array_fill(0, count($params), '?'));

    This prepares the statement with enough unnamed placeholders for every value
    in our $params array. The values of the $params array are then bound to the
    placeholders in the prepared statement when the statement is executed.
    This is not the same thing as using PDOStatement::bindParam() since this
    requires a reference to the variable. PDOStatement::execute() only binds
    by value instead.
$sth = $dbh->prepare("SELECT id, name FROM contacts WHERE id IN ($place_holders)");

KCachegrind doesn’t open cachegrind profiler log file

So I had an issue with KCachegrind where I would open a cachegrind profile file and "nothing happened". The status bar said the file had loaded, but the user interface widgets were all empty. Turns out clicking Settings -> Sidebars -> Function Profile loaded the part of the UI I needed to get started... everything is easy when you know how!