WorkSimple 1.3.5 control panel and login fix

After playing around with WorkSimple 1.3.5 (and apparently not doing much  testing), login.php doesn't redirect on login and cp.php strips HTML.  Download the attachments below and replace cp.php and login.php with the new versions. Save the new versions as cp.php and login.php respectively and upload them to your WorkSimple install directory.

Reverse postal code lookup in PHP

 I've never played with any geolocation tools before but I thought I'd take a whack at it. After stumbling across GeoHelper, I thought I'd test things out with it. Well, after finding that the only reverse postal code lookup is Canada Post, I might as well make my own.

Download GeoHelper and script at the bottom of the page and place it in the same directory. That's pretty much it, the code explains itself. It can also do a reverse lookup on IPs.


Live demo here




External antennas on ASUS EeePC 701

I finally did what I always wanted to do: add external antennas to my 701. Drilling the holes were a bitch. First, I tried at the right hinge, but the end of the RP-SMA connector was too large. Then next to the VGA port and no luck, Oh, but perhaps next to the second USB port on the right hand side? Nope. Well, what I ended up doing was putting the connector on the outside. Check out the picture:

Edit: here's a better picture



I only have on antenna with me but the wifi reception is superb. I pick up more networks and at a greater dBm. Routing the antenna cables in the board we're that hard and I'm surprised they reached. And for the price, $1.19 on eBay, they were a steal.  

WorkSimple 2.0 roadmap

I've been making lots of new changes to WorkSimple, paving the way for WorkSimple 2.0. I'll be going over old code and re-implementing some things. I used Twig for templating instead of a custom made method since it seemed easier and more convenient. Templates now are much more customizable and flexible. Check out the screenshot for what it may look like (the colours suck, I know).

Pasteros: cloud-based text storage

I just had to create [another] text storage project, just for shits. Pasteros (temporary domain) is a text storage storage (think Pastebin, Pastie, etc) running on DotCloud. It uses Twig for templating and I just converted the MySQL innerworkings to PostgreSQL (juste pour le fun). I also made an API for public use as well. I'll be releasing the source code shortly. Any feedback is appreciated.

How not to order RAM

So, back in June or so, I ordered four sticks of 2GBs of RAM for my main workstation, DDR2 PC6400. Couldn't wait to get them right? So, a month goes by and they finally come in. Now, the board I have right now is a Supermicro X6DVL-EG2 which accepts ECC RAM. I thought my current RAM was non-ECC so I said fuck it and ordered non-ECC RAM. Wrong. RAM came in, tried it, motherboard beeped at me. Fuck. So I sent it back out east for a refund (to Newegg). A week or two goes by until I get the refund so I go ahead and order DDR2 PC6400 RAM. Though, when I remember installing the last sticks of RAM, I remember reading "DDR2 400MHZ ECC ONLY" on my motherboard. Ahh, fuck it. New RAM comes in and, oh, surprise! It doesn't work! 


So, now I'm sending it back to Newegg for the second time but I have to pay for shipping ($20) to get a refund. Turns out, the right RAM (PC3200 ECC) is $45 per stick, when the PC6400 ECC was $30. I found a cheaper price on eBay so woohoo. Next time, I'll be more careful.

Templating with Twig

I've been working on this shitty video sharing site for a couple weeks now and thought I'd try out some new things. I' used phpass for the password management and ended up using Twig as a template framework. I've never used a template engine before so I was new to using one. Twig is actually quite easy to implement into any of your projects. In your PHP script add:


require_once 'Twig/Autoloader.php';

$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader);
$template = $twig->loadTemplate('index.html');
echo $template->render(array('value' => 'test');

And that's it. In the example, 'index.html' is the template file. The array passes the variables onto the template. So, your index.html would look something like this:


This is a {{ value }} 

That would echo 'test'. The documentation for Twig is alright but it doesn't show how one uses the core extensions. See the below example as a block is transated for Twig's use:

      $a = $s + ($limit);
       if ($a > $numrows):
       $a = $numrows;
       $b = $s + 1;
       echo "Showing results $b to $a of $numrows";


{% set a = s + limit %}
    {% if a > numrows %}
        {% set a = numrows %}
    {% endif %}    
{% set b = s + 1 %}  
   Showing results {{ b }} to {{ a }} of  {{ numrows }}


I figured out when you're calling a template, you're able to call two. So for example, the follow code will pass the variables into both index.tmpl and menu.tmpl

 $template = $twig->loadTemplate('index.tmpl', 'menu.tmpl');

I needed to do this because index.tmpl was my main page as to keep the entire sites template intact, I also needed to pass two variables to menu.tmpl. Before, I included my menu file,' into the pages but that became broken after a while. What I changed was that I added Twig variables to menu.tmpl, which changes on whether a user is logged in. So, rather than using anymore, I went to the template.
To include templates is simple:

{% include 'menu.tmpl' %}

Also, one could also extend one template with another. There are no foreach or while loops available in Twig but you can use this as a foreach statement:

{% for message,thing in test %}
    {{ message }} contains {{ thing }}
{% endfor %}

Twig also has a sandbox feature which seems great for sanitizing input and such. I'm definitely glad I found out about Twig; my code is much cleaner and doesn't look [as ] hideous.