Feeds:
Posts
Comments

Just now, I got this error when trying to pull or push:

/usr/bin/gerve: line 53: syntax error near unexpected token `fi’
/usr/bin/gerve: line 53: `fi’

It looks like shell script gone bad. For sure I don’t have ‘gerve’ shell script.

I wonder what happen exactly.

I’ve been using jQuery for more than 4 months now, and I love it more and more.

Through out my career I went through Prototype + Scriptaculous, brief Mochikit, MooTools, and now jQuery. But this post is not about jQuery is super awesome and other framework sucks. It’s about why I really like jQuery so much.

jQuery helps me understand Javascript.

Even though I’ve been doing web development for a while, I felt like there were still holes in my brain about javascript. There were a lot of non-obvious little things like:

  • What callback function takes as arguments. (inside AJAX its data; Inside element it could be element or event; etc.)
  • Functions Scope. (I didn’t realize that, because of function is first-class, javascript scoping is similar to Python)
  • What unobtrusive truly means. (If the web app lost functionalities when javascript is turned off, then its obtrusive)
  • What is the best practice for binding/unbinding events.

Because I didn’t have above (basic) questions answered, it’s hard for me to appreciate framework(s) that monkey-patch global objects. That’s the same reason it took a while for me to get used to Rails.

jQuery solves my complains about Javascript

Javascript language is truly verbose, akin to java. IMHO, verbosity really kills scripting language, especially while typing in interactive console.

I can only type so much of these (example):

var domElem = document.getElementsByName(’someClassName’);

for( var i in domElem ) { console.log(domElem.class) }

In jQuery, it becomes:

$(”.someClassName”).each( function(i) { console.log(i.class) })

Such conciseness is why I like Python and Ruby and jQuery. Shorter code allows me to see what truly important.

jQuery makes being unobtrusive Easy

ready(), click(), bind(), unbind(), and more truly makes being unobtrusive super easy.

I can achieve unobtrusiveness by placing javascript logic at the end of base view/template file (Example):

<script>

$(document).ready(function() {

$(”.someDomClass”).click(function(e) {

// Do some stuff

e.preventDefault();

})

})

</script>

Above technique is common place now, but jQuery makes it concise and easier to debug.

Conclusion: jQuery is awesome and worthwhile investment, for my career and for fun.

When performing query(), SQLAlchemy does not execute __init__ of the corresponding ORM objects.

Thus, if you have some logic inside __init__, those won’t get executed.

To have the desired behavior, you need to put such logic inside a function that takes no arguments, then, attach @orm.reconstructor on it.

Reference:

It’s nice that Pylons include nosetest and TestUnit as part of its testing framework.

Unfortunately, using those for unit testing inside Pylons is not trivial, not obvious, and inconvenient.

For examples:

  • I can only run nosetests on top-level directory because config is expecting ‘test.ini’ file. That’s inconvenient.
  • It is not obvious how build sqlalchemy’s engine inside tests/__init__.py. Ideally, I can build the engine based on test.ini configurations.

To answer those questions, this is how my __init__.py looks like: [gist]

The __init__ file solves various problems:

  • I can run nosetests anywhere inside project’s directory tree.
  • With simple convention, __init__ will look for test.ini file on top-level directory.
  • SqlAlchemy engine is built using configuration set in test.ini

I hope this snippet can help readers in getting up to speed in Pylons even quicker.

For the longest time I kept staring at ‘plain text mode’ while editing Mako templates. No Mas!

TextMate bundle for Mako template has existed.

To install:

  • cd ~/Library/Application\ Support/TextMate/Bundles/
  • svn co http://svn.makotemplates.org/contrib/textmate/Mako.tmbundle

After Reloading you bundle, syntax highlighting is available under HTML (Mako).

Reference:


Do you have that problem? I do.

EDIT(05/31/2009): Even better solutions:

Hyphenator.js: http://code.google.com/p/hyphenator/

OR:

General CSS solution:

overflow: scroll

/EDIT

The HTML solution:

use <wbr>. (But you have to figure out yourself where to put the tag)

The IE-specific CSS solution:

word-wrap: break-word

PHP solution:

wordwrap(’your_very_long_string_here’, 15) // Break after 15 characters

Python solution:

import textwrap

textwrap.fill(’your_very_long_string_here’, 15) # Break after 15 characters

References:

Original Article here: http://lafalafu.com/krc/privilege.html

The article is thoroughly descriptive and I didn’t even realize some of them until I read it.

By default Mako HTML escapes all output.

To NOT have this behavior, change the setting of TemplateLookup in environment.py.

Resources:

distance_of_time_in_words is a useful function that converts boring looking datetime into something more attractive (and SEO optimized) like: 30 seconds ago.

Pylons gain this functionality via WebHelper which blatantly inspired by Rails.

But, out of the box, this functionality does not exists in my templates. To enable it, I need to add this line in helpers.py:

from webhelpers.date import distance_of_time_in_words

Resource:

WebHelpers Documentation

There are so many micro-blogging services nowadays. Sooner or later there will be an open source application for it.

And that application is called Laconica. It is written in PHP.

I haven’t try to install it yet, but it sounds fun.

Resource:

The project’s Trac

Older Posts »