Prevent upgrade of (“lock” version) specific packages in Debian/Ubuntu Linux

In many cases, you may need to preserve the current version of a package in Debian or Ubuntu Linux. For example, your production environment may use an older version of a package and, in your development environment (perhaps on a Vagrant virtual machine), you want to make sure you use the same version. The apt package manager provides functionality to “lock” (or, as it’s called in Debian/Ubuntu, to “hold”) the version of a package. The command is simple:

sudo apt-mark hold package_name

where package_name is the name of the package, such as grub-pc. You can include multiple package names on the command line by separating each with a space.

For more information, see the Ubuntu help topic on apt “pinning”.

Use PHP array_map() function to remove white space from array elements

One common scenario in PHP is take an input list, such as some search criteria entered by a user, and tokenize the input into individual items using a separator, such as comma. The PHP explode() function works great for splitting up the individual values into an array(). However, if have white space before or after the separator, each of the elements of the new array will contain that white space. You could use a foreach loop, with the $key => $value syntax to apply the trim() function to each item. But PHP has the perfect function already built in: array_map().

array_map() takes a callback function as its first argument and an array as the second argument. It applies the specified callback function to each element of the array that is passed in. You simply provide the name of the callback function as a string (either in single or double quotes) and the function can be a function within your code or any of the built-in PHP functions. For example, to put all of the pieces together, you could do something like this:

$input = "apricot, banana, cherry, dewberry, eggplant, fig";
$output_trimmed = array_map("trim", explode(',', $input));