Linux Mint: OpenSSH Daemon

I’m in the process of reinstalling my work desktop. One of the mandatory packages which I install once the core system is up and running is a SSH Daemon. Setting it up (on Linux Mint which I’m running) is pretty easy. To install the OpenSSH daemon go to the shell and write: sudo apt-get install openssh-server It’s a fairly small install, so in a few seconds it ought to be up and running.

Trying and failing (twice)

PHP like many other programming languages has facilities to handle exceptions. Using them is pretty easy, but sometimes lazy programmers seems to misuse them to suppress error messages. A try/catch in PHP is usually constructed something like this: try { // Something can go (horribly) wrong... } catch { } The lazy programmer may leave the catch empty, but frankly you should never do it. When you’re doing something - try’ing - it’s for a reason, and if it fails, someone quite possible need to know - the end user, a log file for the sysadm or someone else.

strpos in PHP - like being stung by a needle in a haystack

In PHP when you have a string and want to find out if it contains another string, there are a few ways to do it. You can use regular expressions, use the strstr functions and a few other methods. The easiest way though is probably by using strpos, which returns the number of the character containing the first occurrence of the thing you’re looking for - and false if the string isn’t found.

memcache: set vs. replace

When using memcache from PHP, you can save values with either set or replace. You can probably safely ignore the replace method: “Memcached::replace() is similar to Memcached::set(), but the operation fails if the key does not exist on the server.” - PHP Documentation

Adding to php arrays

In PHP many things can be done several different ways. Picking which way to do something may be a matter of personal taste or habit. Sometimes however, things may be much clearer for the next developer, if you choose one way over another. A very simple example of this, is adding a new item to an array. Often I come across this construct: $valuepairs[] = 'Some value' It’s valid and compact syntax, but in terms of clarity, I’d prefer this construct anytime: