Pine: Flags

To mark a message as unread in pine this can be done using flags.
First flags have to be turned on in setup
[M]ain [S]etup [C]onfig
Then find “enable-flag-cmd” and turn it on.
After this marking a message as unread is done by “* N” in the list view or when looking at the message.

All the flags are:

  • [N]New
  • [D]Deleted
  • [*] Important
  • [A] Answered

[^T] Can be used to see all the flags and set/unset them one by one (or all).

PHP: Static functions in a Class

Static functions can be used without instantiating the object.

A quick example of a static function is shown below as well as a comparison with a non static function.

A quick example of this (in PHP5):

class TestClass{
	static function staticFunction(){
		echo "static function called";
	}
 
	function nonStaticFunction(){
		echo "nonstatic function was called";
	}
}
 
TestClass::staticFunction(); //will echo static function called
 
$testClass = new TestClass();
$testClass.nonStaticFunction(); //will echo nonstatic function was called
unset($testClass);

PHP: converting a uuid stored as BINARY(16) in mysql to RFC 4122 format

If you are storing uuid’s are BINARY(16) in the database, then the following will turn the stored id to the “original” format.

$uuidReadable = unpack("h*",$uuid);
$uuidReadable = preg_replace("/([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})/", "$1-$2-$3-$4-$5", $uuidReadable);
$uuidReadable = array_merge($uuidReadable);
echo "uuid is " . $uuidReadable[0];

MySQL inserting UUID to a binary(16) field

It is advantageous to store a UUID (acc to RFC 4122) in a binary(16) field in the database.
It is not hard to create such a table and to insert data into it.

CREATE TABLE IF NOT EXISTS test_table (
  id BINARY(16) NOT NULL,
  name VARCHAR(128) NOT NULL,
  PRIMARY KEY  (id)
) 
 
INSERT INTO test_table (id, name) VALUES
(UNHEX(REPLACE(UUID(),'-','')), 'test1'),
(UNHEX(REPLACE(UUID(),'-','')), 'test2'),
(UNHEX(REPLACE(UUID(),'-','')), 'test3')

apt-get WARNING: The following packages cannot be authenticated!

apt-get is verifying the packages before installing them.
If the keys are not up to date, then apt-get upgrade will issue a warning.

WARNING: The following packages cannot be authenticated!
  ure uno-libs3
Install these packages without verification [y/N]?

The way to solve this is rather simple, just run apt-get update and it should download the keys automatically.

apt-key handles keys, using apt-key list will show you the keys that are on the computer.

MySQL importing a sql file

To simply import a sql file (and get any results printed to the prompt)

mysql -uUSERNAME -p DBNAME < FILENAME

The parameters are
-u username (note no space between the u and USERNAME)
-p password (can be given as the username (without a space between p and PASSWORD; or if omitted mysql will ask for it)
DBNAME is the name of the database to import to (if the sql file don’t create a database on it’s own)
FILENAME is the name of the file to import

Other parameters can be
-h server host (dns name or ip) if -h is omitted then localhost is assumed.
-P port number
-f force (will not break on errors)

To import a sql file and then have to output to a file (for instance when running from a crontab)

mysql -uUSERNAME -p DBNAME < FILENAME > OUTFILE

Works just as the previous import except that any output will be written to OUTFILE.

PHP5: Quick on timing a script

Sometimes it is nice to know how long a scrip took to execute (or a part of a script).
This is a simple way to time a script in php.

$time_start = microtime(true);
 
usleep(500);
 
$time_end = microtime(true);
$time = $time_end - $time_start;
 
echo "run time was " . $time . " seconds";