July 14th, 2010
I recently ran into the problem that I had too add two rows to a database that uses a UUID (in this case converted to a binary) as a key.
The problem I had was that running two insert statements after each other (just separated by “;”) then the same id was generated.
A workaround I have found is to sleep for a second between the two statements.
Examples (using SELECT instead of INSERT):
Getting the same id twice
SELECT UNHEX(REPLACE(UUID(),'-','')) AS uuid1, UNHEX(REPLACE(UUID(),'-','')) AS uuid2;
-- Shows: "849392548f1311df91b70019dbd264f1" "849392908f1311df91b70019dbd264f1"
Adding a sleep to get different ids
SELECT UNHEX(REPLACE(UUID(),'-','')) AS uuid1, SLEEP(1), UNHEX(REPLACE(UUID(),'-','')) AS uuid2
-- Shows: "3901c1928f1511df91b70019dbd264f1" "0" "399a5b148f1511df91b70019dbd264f1"
And another one using INSERTS
INSERT INTO testTable (id) VALUES (UNHEX(REPLACE(UUID(),'-','')));
SLEEP(1);
INSERT INTO testTable (id) VALUES (UNHEX(REPLACE(UUID(),'-','')));
Tags: MySQL, uuid
Posted in MySQL | No Comments »
July 12th, 2010
The first idea that comes into mind for doing this is to simply make a typecast of the boolean variable to a string and use that (which works)
$testVar = false;
echo (string)$testVar; //will output a empty string (as that evaluates to false)
$testVar = true;
echo (string)$testVar; //will output 1 (as that evaluates to true)
but what if the requirement is that the string should say true or false
$testVar = false;
echo $testVar ? 'true' : 'false'; //will output false
$testVar = true;
echo $testVar ? 'true' : 'false'; //will output true
(While the above example might seam useless I recently had to do this for a db insert)
Tags: bool, php, php5, typecast
Posted in PHP5 | No Comments »
July 11th, 2010
After installing MLCad the first time the error “Invalid Path (no Parts and/or Pdir Found)” is shown and a directory selector is shown.
The directory that should be selected is the main LDraw directory.


Tags: LDraw, LEGO, MLCad
Posted in LDraw, MLCad | No Comments »
July 10th, 2010
When you open a folder in Windows Explorer a click sound is played. To disable this there are two ways to do it:
- Turn it off using the control panel:
- Open “Start”->”Settings”->”Control Panel”
- Open up “Sounds and Audio Devices”
- Open the tab that says “Sounds”
- Scroll down until you find “Windows Explorer”->”Start Navigation”
- When you mark this line at the bottom there is a drop down that is labeled “Sounds:” Here you should be able to change to anther sound or “none” if you do not wish a click.
- The second option is a bit more direct and rude – but if the above does not work for you (for me something kept resetting the old sound); just remove the file that contains the click sound.
- Open up a Windows Explorer and go to “%windir%\Media” and find the file that is named “Windows XP Start.wav”
- Either remove it (permanently) or rename it to something that windows won’t recognize (but you can – so you later can reverse this if you would like to)
Tags: click, windows
Posted in Windows 2003, Windows Vista, Windows XP | 1 Comment »
July 7th, 2010
Windows, Linux/Unix and Mac have different line-endings on text files.
A quick overview on the endings are:
- Windows-style line endings are CRLF ( \r\n or hex 0D0A )
- Mac-style line endings are CR ( \r or hex 0D )
- Unix-style line endings are LF ( \n or hex 0A )
A HEX editor can be used to double check that the correct endings are written.
Tags: line-ending
Posted in Development | 2 Comments »
June 23rd, 2010
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).
Tags: pine
Posted in linux, unix | No Comments »
June 18th, 2010
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);
Tags: class, static
Posted in PHP5 | No Comments »
June 16th, 2010
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];
Tags: uuid
Posted in PHP5 | No Comments »
June 16th, 2010
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')
Tags: uuid
Posted in MySQL | 1 Comment »
June 8th, 2010
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.
Tags: apt-get, debian, ubuntu
Posted in debian, ubuntu | No Comments »