Kleber Garcia

2013-02-18 01:07:09

Hello World!

Hello world! so finally I have decided to create my first own website. How exciting ;). I plan to use this website as a main blog were I can post my thoughts on several interesting topics. I am planning to make this mostly a discussion board on computer science and programming, including some of my opinions here and there.

There is so much knowledge I would love to share with the world right now! Let me start this first blog post with a little bit of background information about this website (how recursive!). The entire website was designed and written by me (server side, client side, even the procedural art that you see in the background). The server side tech I chose was LAMP (linux, apache, mysql and php). I truly believe that while this is not a very powerful framework [like django or ruby on rails], its definitely one of the most flexible out there.

The Tech

As I mentioned before, its all about power vs flexibility. You can have power but not so much flexibility, but you can definitely have flexibility which could yield to greater power. By that I mean that you will probably have to implement the things under the hood in order to make them work properly. A concrete example is how in this website (if you noticed) I use a very modern URL system. Its basically folder based urls (i.e. reddit.com) with no ugly Get parameters. While django provides this for free, its a complete pain in the ass to set up loose files. They advice in the framework to setup a loose file separate server, which sucks completely.

I also have to mention that django its a very inefficient and CPU intensive framework :( I chose just regular php because I can easily override the url from the apache layer, by having this little .htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* ./index.php [L]

By doing this I redirect every url the user inputs in the browser to a single index.php file. Once inside this php file, I smartly parse the url request and send everything to a page switch.

The Pattern

I simply love the pattern that some frameworks [like django] provide by default. Again the problem is flexibility, a lot of the features I use on those frameworks are not quite flexible. Perhaps the prime example of a framework that I am not even a big fan of is ASP.NET. While its really cool to toss around your webiste in dlls, and have a good abstraction with C#, this framework is the prime example of inflexibility. I would like to challenge somebody on taking the task of writting a C# website that will provide you a real time bar on how many bytes are left until a file is fully uploaded. In php you can use the APC cache and do this easily. In C# you will end up writting an http module.

The pattern I use here is that of separating internal functionality and rendering. This usually involves by introducing two concepts, which is data processing, and then passing a data structure with all your arguments to a template. The template would then produce the appropiate html upon reading the arguments. I implemented this easy pattern by creating custom php templates, and adding a page switch. The switch and the template look like this:

<?php
function page_switch($request)
{
    $page = $request["PAGE"];
    $args = $request["ARGS"];
    $db = new KechomeDb();
    $db->Start();
    $r = Array();
    if ($page == "home")
    {
        $r = home_main($args, $db);
    }
    elseif ($page == "blog")
    {
        $r = blog_main($args, $db);
    }
    //and so on
    $db->Stop();

    return $r;
}

//then another module would execute this:
$args = page_switch($request);
execute_template($args);

function execute_template($args)
{
    print_header($args);
    print_menu_bar($args);
    print_footer($args);
}

function print_header($args)
{
?>
    //print here html
<?php
}


//and so on

?>

As seen above, the function page_switch redirects the request to the appropiate page worker. The page worker then returns the render arguments, which are finally passed to the template. The template as seen here, is completely unaware of the database or origin of data as such. This provides easy ways of reusing template fragments, and even mocking pages that require databases by passing directly pre made structures as render arguments.

The Tools


The image above is my current desktop. Notice I use a transparent vim window which allows me to swap between the website and the source very fast. I used entirely open source tools to develop this blog. I used an SSH shell to communicate with my production servers, to generate ssh keys so I can transfer files back and forth and to work remotely when I felt like it. I used VIM as my 'IDE'. You might ask, how the hell did I do code browsing? well if you know how to use vim its very easy and powerful. I used CTAGS to perform those deeds. My operating system is Gentoo with KDE as the window manager. For deploying the website to a particular machine I have my own python / make scripts that I wrote for my own use. They also include database migration. Maybe someday I will post these scripts accordingly to share with the world :). I used python for all the behind scenes stuff (deployment and db migration).

Web GL and the procedural Art

I have been fascinated lately with procedural art. This was all introduced a few months ago when I had a Houdini tutorial at work. It was amazing. I was then inspired to write a mini render wrapper for WebGl, so rendering and vertex manipulation could be done fairly easy and fast. When I was done I wrote the first javascript proceduraly generated abstract art for this little render engine, which I call 3dliner. I will post later more details on this, on the meantime check the source for MiniWebGl, and also the art produced by it 3dliner by clicking here.

And with this, I shall say goodbye and see you soon! looking forward for your questions / comments / concerns / trolls / critiques in the little box below. Pronto my friends!


submit to reddit

comments powered by Disqus