Min and max functions are available in perl, but you need to load them first. To do this, add use List::Util qw[min max]; to the top of the script. These functions take a list of numbers and return the min/max of that list. The list can have 1 number or 100 – it doesn’t matter: [...]
Posts Tagged ‘script’
Setting the maximum execution time in PHP
Posted: 5th September 2011 by Tim in PHPTags: fatal error, maximum, PHP, script, set_time_limit, time limit, web
If you’re writing a website in PHP, then by each PHP script will time out after a set time (usually 30 seconds by default). If this happen, you’ll see an error like the following: Fatal error: Maximum execution time of 30 seconds exceeded in <file> on line <line> This is a safety feature; if your [...]
CREATE LANGUAGE if it doesn’t exist in PostgreSQL
Posted: 27th August 2011 by Tim in PostgreSQLTags: create, create language, exist, if exists, if not exists, language, plpgsql, postgres, PostgreSQL, query, script, sql, statement
If you’re writing functions in postgres then you’ll probably be using a language such as plpgsql. Let’s say you’re writing a script to to add all of these functions to a new database, but you don’t know whether that language has been created yet. You’ll probably want to do something like CREATE LANGUAGE IF NOT [...]
Substrings in Bash
Posted: 17th October 2010 by Tim in BashTags: Bash, manipulation, programming, script, shell, string, substr, substring, variable
There are a number of ways to extract parts of a string in bash. If you know the position of the substring you’re looking for, then you can use the ${string:offset[:length]} syntax. This works by providing a string, an offset (or starting position – remember that the first letter is in position 0) and, optionally, [...]
Checking for empty string in Bash
Posted: 19th May 2010 by Tim in BashTags: Bash, coding, dash, empty, language, linux, null, programming, script, scripting, SET, shell, string, terminal
In Bash you quite often need to check to see if a variable has been set or has a value other than an empty string. This can be done using the -n or -z string comparison operators. The -n operator checks whether the string is not null. Effectively, this will return true for every case [...]
List files which are not up to date in CVS
Posted: 5th October 2009 by Tim in Bash, CVS, UbuntuTags: Bash, cvs, grep, pipe, repository, script, shell, terminal
CVS is annoying in that if you want to find out which files have been modified or need updating, you can’t simply use the cvs status command as there’s too much information displayed. In order to make it useful, you really need to filter the output. Note: the following tutorial only works for linux computers [...]
Removing directories in CVS
Posted: 21st September 2009 by Tim in Bash, CVSTags: Bash, cvs, delete, directories, files, folders, linux, remove, repository, script, unix, version control, versioning
There is no way to delete a folder in CVS like you can with files. The directories must be kept so that the versioning information relating to the files which used to be in the repository can still be used (ie: you can revert back to a revision when the files still existed). The only [...]