28 April 2008

Notes on Emacs

I'm giving Emacs a serious chance, so here are a few notes, mainly for personal future use.

  • auto-indent an entire file:
    (defun iwb ()
    "indent whole buffer"
    (interactive)
    (delete-trailing-whitespace)
    (indent-region (point-min) (point-max) nil)
    (untabify (point-min) (point-max)))
  • find .emacs on Windows: C-x C-f ~/.emacs (I know, it's banal, but...)
  • set tab size to my favourite default (3):
    (setq-default tab-width 3)
    (setq-default c-basic-offset 3)
  • php-mode: haven't quite understood how to activate it yet. I get syntax highlighting for everything BUT php. D'oh. UPDATE: ahh, you have to byte-compile it yourself. What a lazy environment for a dynamic language! Anyway, thanks to this blog post, I now know how to do it: M-x byte-compile-file (and then point to php-mode.el)
    UPDATE: Oh, and you have to use the 1.2 version with emacs 21 and lower.
  • (UPDATE) To maximize it at startup, two options:
    • Easy one: in the registry (HKCU\Software\GNU\Emacs, which you have to create), set a String property called "Emacs.Fullscreen" with value "fullboth". Unfortunately this is calculated from the very bottom of the screen, so if you have the taskbar set to "always on top" and no "auto-hide" (like me), you will end up with the taskbar covering the minibuffer.
    • better one: do
      M-x : (frame-width)
      and write down the number that comes up (e.g. 155), then repeat with (frame-height). Then (in the same key as above) set a String property "Emacs.Geometry" set to these value, e.g. 155x59. If you have the same taskbar issue as above, reduce the second parameter until it's ok (I had to reduce it by 3).

Why Emacs? I'm doing a "good deed" which involves php, and since I have to churn out loads of useless "$" and "->" and brackets, maybe it's time I learn a proper power-tool for text editing.

27 April 2008

MySQL character set ("charset") options for UTF8

While dabbling with PhPeace, I found out a few things about how MySQL handles charset options.

There are several levels at which you can specify a charset, from top to bottom: server instance, database/schema, table/column and, finally, connection.
Usually, the lowest option will override the previous one, so if you specify the encoding at connection level (with a query like "SET CHARSET 'utf8'; SET NAMES 'utf8' COLLATE 'utf8_general_ci';") you should be safe. However, if you want to fix things "once and for all", you can add these options to your /etc/mysql/my.cnf file (or adding a /etc/mysql/conf.d/UTF8 in Debian with these options):

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
default-character-set=utf8
[client]
default-character-set=utf8

The *-server* options are instance-specific, while default-character-set is connection-specific. If you wonder what the "collation" stuff is, it's the method to use for sorting. I'm not sure if, as guideline, you should use utf8_unicode_ci rather than the default utf8_general_ci, but I didn't find out how to override the default option at connection level in the .cnf file, so I'll stick to utf8_general_ci to have a consistent environment.

08 April 2008

Google App Engine

Google App Engine. Write applications in Python using a WSGI-compatible application framework, then host them on Google’s highly scalable infrastructure.
(via Simon Willison's Links)

"Holy s**t" was Ryan Tomayko's comment, and my first thought as well. Google is realising the promises of WSGI, and what a sight it is.
On one hand, this is fantastic; it made me think of "J2EE done right". On the other hand, if you use GAE, you are handing your entire infrastructure and data (!) over to Google, which might not be the smartest move for lots of companies (any FTSE100 for example, and probably any NASDAQ-listed as well).

Anyway, Python rocks.

07 April 2008

Do The Indie Kid

I love MJ Hibbett & The Validators, and you should too. So here's his latest video.

15 March 2008

Notes from BubbleCity

Last day in California, blogging from a little cafe in the Fillmore area of San Francisco.

Silicon Valley is dead boring, I ran away from it on Friday afternoon, but I like the big city up here. Went to Berkeley (slightly disappointing), done the sightseeing thing downtown (Fisherman's Wharf, Russian Hill, Alamo Square, Chinatown, built-in-Milan cablecars, etc) which wasn't fantastic, much better just to walk around up&down the hills, Lower Haight, Octavia, Fulton, to get a feeling for the lovely (upscale) 'hoods.

Got lucky and landed in JapanTown on the first saturday of Cherry-Blossom Festival, so the entire district was all tarted up and in full swing (including long queues for the International Asian Film Festival), I really enjoyed it (but the hyashi-chuka was average).

It can be as seductive as NYC at times, even though the character is very different; NYC feels like the place where you go "to be the best", while you come to SF "to be yourself" or "to find what's next". It looks like a fundamentally mexican/asian city, rather than white, and this is fantastic. Whereas Santa Clara/Silicon Valley is such a whitey, middle-class, boring place, it's no wonder that waves of geeks are escaping to SF-SOMA (South-Of-MArket-street) and commute from there.

Been to the scenic SF Giants stadium (ahh, one day I have to see a live match) which was recently built on reclaimed land facing the bay and it's gorgeous. I still didn't see the western area, Golden Gate Park etc, but hey, you have to keep something for the next visit!