LogPixels DPI hack Wednesday, January 4th 2012
Here's a handy tip for those netbook users out there in dire need of more screen estate. You can force a DPI value of lower than 96 by using the Windows registry. To do so open Regedit, navigate to HKEY_CURRENT_CONFIG/Software/Fonts/LogPixels and change the decimal value from 96 to something lower such as 80. Then log out and back in and you will see the changes. I'm using a value of 80 on my netbook and it is about the most that I will drop it while still keeping things (half) readable. You will notice that it really hinders the readability of fonts as well as having some strange bitmap scaling artifacts, but if you're like me and can adjust to it then the extra screen space gained is well worth it :)

You can view a side by side comparison of the my desktop with LogPixels at 80 and at 96 by viewing this imgur album.

http://i.imgur.com/DKnsWm.jpg http://i.imgur.com/JHrJim.jpg
Comment on this Post
Docstrings in my Chicken? Sunday, November 13th 2011
Here's a little bit of amateur code to enable the use of docstrings in Chicken Scheme. I haven't written any Scheme in a few months and don't have any formal training in the ninja art of explicit renaming macros so I'd appreciate any feedback from Scheme veterans:

;;; Docstrings for Chicken!

;; The hash-table that will contain the procedures and their associated
;; documentation strings as well as their code for later use.
(define *documentation-hash-table* (make-hash-table))

;; Documented define er-macro
(define-syntax (define* form r c)
  (let* ((args-form (second form))     ; (proc args)
         (proc-name (first args-form)) ;  proc
         (doc (third form))            ; "The docstring"
         (body (drop form 3)))         ; (everything else)
    (hash-table-set! *documentation-hash-table* proc-name (list doc body)) ; insert the doc and code body
    `(,(r 'define) ,args-form ,@body))) ; Define the procedure as normal

;; Example of a documented procedure, will print a nice-ish list of documented procedures
(define* (print-docs)
  "Print a list of documented procedures"
  (hash-table-walk *documentation-hash-table*
    (lambda (key val)
      (printf "~a => ~a~n  ~a~n~n" key (first val) (second val)))))


Another example of why Scheme is such a fun language to work with :) Comment on this Post
Twitter's Bootstrap Friday, November 4th 2011
To me, one of the most annoying parts of prototyping a new web application is getting a presentable look and feel up quickly. When I'm prototyping stuff I love to have a good looking interface from the start, even if that interface will be changed before going live.

Recently, Twitter released a wonderful CSS/JS framework named Bootstrap for this exact purpose. As stated it is a toolkit "[...] designed to kickstart development of webapps and sites.". It combines an aesthetically pleasing base styling (based somewhat off of Twitter itself) of HTML elements with an easy to use CSS grid, great browser compatibility, and various optional Javascript modules to extend functionality of things such as Drop-down menus and modal dialogs.

As for the elements it offers, some of my favourites are:

  • All typical HTML elements are styled, including decent typography
  • A top bar to be used for menus and such, with drop-down menus to be activated easily with JS
  • Tabs/Pills
  • Ability to pretty-print code when used in conjunction with google-code-prettify
  • Labels and buttons, with styles for success, warning, notice, etc
  • Alert boxes, with corresponding styles, great for showing form submission status etc

  • Bootstrap is built on top of the LESS CSS preprocessor for ease of extending and integrating into your apps. Personally I found that the precompiled stylesheet was more than enough to begin with however, and I'm more of a fan of the SASS preprocessor anyway. The JS modules are also very easy to integrate with very little code needed to hook them up to their appropriate classes.

    I jumped into Bootstrap shortly after its release, and have been using it ever since for my internal prototypes and eventual applications, including an application in the process of being deployed. Bootstrap played an integral part in getting that project complete under it's tight deadline.

    Highly recommended to all! Comment on this Post
    Das Keyboard Ultimate Wednesday, October 12th 2011
    I took the plunge recently and bought my first mechanical keyboard, the Das Keyboard Ultimate. It was very hard to find someone that would ship one to NZ, but eventually I found AusPCMarket that ships the Das as well as several other "clicky keyboards". The Das is known for being a bit pricey.. the Ultimate set me back $230NZD (incl shipping and GST) at the current exchange rate and was delivered in just over a week. If you need to justify the price by thinking of it as an investment, then do :)

    With it being my first mechanical keyboard I'm unable to give a fair review in comparison to others of its kind. My previous keyboard was a Microsoft Comfort Curve 2000 keyboard (a much cheaper $40NZD), a brilliant keyboard but of course based around rubber dome technology.

    Anyway, it took me a while to adjust to the non-curved layout of the Das, but now that I have I feel that I am touch-typing much MUCH more efficiently than before. It feels great to type on, plus it sounds amazing! Personally I revel in the sound of the Das, and while I wouldn't want to use one around sleeping people, it certainly won't break through any music playing on your headphones and so far doesn't seem to penetrate walls ;)

    Overall a definite thumbs-up from me. If you're in NZ and looking to get a Das, I'd highly recommend also going through AusPCMarket as their service was quick and no-bullshit. Comment on this Post
    Tiny Memcached Wrapper Friday, August 12th 2011
    No posts in a while huh! Been pretty busy and haven't thought of much to blog about lately. But I've been playing with Memcache and wanted to share a tiny class I made to add easy caching to my PHP projects. This PHP class just provides a nice simple interface to use by extending the Memcached class:

    // Call the class whatever you want
    class MyCache extends \Memcached {
        function cache($key, $time, $func) {
            if (($val = $this->get($key)) === false) {
                $val = $func();
                $this->set($key, $val, strtotime($time) - time());
            }
            return $val;
        }
    }


    And now to use it, first you summon it in the same way as the regular class:

    $c = new MyCache;
    $c->addServer('127.0.0.1', 11211);


    Then where you would like to begin caching (I'm using this very blog as an example, where GeSHi for syntax highlighting is the main bottle-neck for page generation), you call the class like so:

    // Example using my BLACK blog engine (http://github.com/ZaneA/BLACK)

    // Here is the original line
    $row['body'] = render($row['body']);

    // And here is a cached version
    // As you can see we have a KEY, a TIMEOUT, and a FUNCTION to call for a cache miss
    $row['body'] = $c->cache("blog_post_{$row['id']}", '30 minutes', function () use ($row) {
        return render($row['body']); // Renders all the post filters, including syntax highlighting
    });


    Awesome, for this small tweak on my local test blog (with 4 posts), this takes the page response time down from 14ms to 2ms. Quite a win I'd say :)

    Of course this code requires the memcached PHP extension and a running Memcache server ;) Comment on this Post
    Emacs Tip: Vimpulse Thursday, July 7th 2011
    One thing I love about Emacs is that it is so extensible. I was an avid Vim user for a long time and it took me several tries to switch to Emacs, but I will never look back. With the Vimpulse addon to the built-in viper-mode, Emacs becomes a powerful Vim impersonator, capable of being extended with Emacs-Lisp.

    A lot of my time is spent doing web development, and so strong HTML editing ability is essential in any editor I use. Vim has this amazing concept of text objects which allows you to be very efficient when transforming text; one of the most useful when doing web development is therefore the XML/HTML tag text object. I would use this all the time by invoking "cit" to change text between a pair of tags. To demonstrate, here's a piece of text you might have sitting in a file:

    <title>Hello |World</title>


    Now with the cursor somewhere in between the tags (visualized above by the pipe, '|') we can go into command mode and type "cit" and the above will be replaced with:

    <title>|</title>


    Ready to be edited!

    Well sadly, Vimpulse doesn't have this feature by default, probably one of the very few parts of Vim that it doesn't emulate in fact! (NB. Evil contains emulation for this already) But not to worry, we can just add it in! This is Emacs after all.

    So how do we instruct Vimpulse to recognise another text object? Turns out it's REALLY easy:

    (vimpulse-define-text-object vimpulse-tag (arg)
      "Select a tag"
      :keys '("at" "it") ; The keys that will trigger this text object
      (vimpulse-inner-object-range ; We're basically defining a range on which to act upon
       arg
       (lambda (arg) (search-backward ">" nil nil arg) (forward-char)) ; Look to the left for a ">" character
       (lambda (arg) (search-forward "<" nil nil arg) (backward-char)) ; Look to the right for a "<" character
       )) ; and return the distance between them!


    Note that this isn't a perfect implementation, but for the purposes of this demonstration it will suffice! We can now "cit" and "dit" to our hearts content! Hail Emacs!

    For a more robust implementation it may be worth looking at using sgml-skip-tag-backward and sgml-skip-tag-forward for movement instead.

    Happy Hacking! Comment on this Post