Archive for the 'Programming' Category

REST links

Thursday, June 21st, 2007

Some cool REST links I’ve come across lately:

The anti-DRM revolution

Sunday, May 13th, 2007

In early May 2007 something amazing happened. Hollywood’s most guarded secret, the key to decrypt HD-DVDs, was found and released on the Internet, via the site digg.com. At first Kevin Rose, the Digg founder, felt pressured by Hollywood lawyers to take down the key, but this made Digg users go completely ballistic, and in the end Kevin posted the code himself saying something to the sort of “this may be the end for us, but at least we went down fighting” (see original post). The key in hex, in case you wonder, is:

09-f9-11-02-9d-74-e3-5b-d8-41-56-c5-63-56-88-c0

Even the iphone didn’t generate this much attention, the blogsphere was flooded with reactions from the two factions: “digg surrenders to mob” and “the truth will not be silenced”. I’m afraid I, with most techies and new media people, belong with the last group that thinks DRM is the Next Big Evil.

People went out of their way to spread the code, to the point of creating songs. The first song wasn’t really that good, but then Geoff Smith created a song called “Digg the Code” that Cali Lewis of the GeekBrief.tv podcast put video on…. What can I say, it’s awesome:

There are currently more occurences of this “secret code” on the net than there are HD-DVD players in the world.

Facebook’s cool cross-platform search field

Sunday, April 22nd, 2007

A while ago I discovered that by setting an HTML INPUT tag’s type attribute to search, Safari on OS X would show the OS X search widget instead of the standard boring HTML input field. Andrew Escobar has a good introduction and an example screenshot:

Safari search widget

This search widget is extremely user-friendly and space-efficient; there is no need for a “Go” or “Search” button anymore.

It also downgrades gracefully to a normal input field for other browsers, but this is unfortunately not enough:

  • There’s no placeholder text explaining what you can search for
  • There’s no magnifying glass or special styling giving a hint that this is a search box

Taken together it means you have to add explanatory text and a “Search” submit button after it for people to understand how to use it, destroying the user-friendliness and space efficiency and offered by the Safari widget.

I’ve noticed that more and more sites were using the Safari search widget without any “Search” submit button, so I figured they must have found a way to make it cross-platform. I spent some time on facebook.com today and noticed they had the Safari search widget… and… sure enough, for Firefox and IE a nice JavaScript version!

I decided to do some reverse engineering…

(more…)

Gone fishing

Tuesday, March 20th, 2007

I caught this very interesting announcement on the Django Developer group:

Google branching out into seafood

I like Django, and my unique experience having grown up in a fishing village should make the ideal candidate! If it wasn’t for the fact that I hate cod…

I wasn’t expecting to see Google go so far as to branch into seafood. No industry is safe anymore…

(more…)

Using Django admin’s search in your own views

Friday, December 8th, 2006

In liu of a real fulltext search engine for Django, you may just want to use the same simple search engine that Django’s admin uses. Unfortunately it’s not readily reusable, so you’ll have to pull it out of the ChangeList.getqueryset in django.contrib.admin.views.main.


  def django_admin_keyword_search(model, keywords):
      """Search according to fields defined in Admin’s search_fields"""
      if not keywords: return []
      fields = model._meta.admin.search_fields

      qs = QuerySet(model)
      for keyword in keywords:
          or_queries = [ Q(**{‘%s__icontains’ % field: keyword}) for field in fields ]
          other_qs = QuerySet(model)
          if qs._select_related:
              other_qs = other_qs.select_related()
          other_qs = other_qs.filter(reduce(operator.or_, or_queries))
          qs = qs & other_qs

      return qs
 

Alternate syntax for Django urlpatterns

Sunday, December 3rd, 2006

Django’s urlpatterns variable has traditionally expected callbacks to be specified as strings, and extra arguments (commonly used with generic views) to be passed as a separate dict, for example:


  info_dict = {
    ‘queryset’: Entry.objects.all(),
    ‘date_field’: ‘pub_date’,
  }

  urlpatterns = patterns(‘django.views.generic.date_based’,
    (r‘^(?P<year>\d{4})/$’,   ‘archive_year’,   info_dict),
  )
 

(more…)

Speaking in code

Tuesday, November 28th, 2006

Once upon a time there was a guy called Donald Knuth. Besides being the author of our discipline’s most prominent work, the Art of Computer Programming, he also invented Literate Programming, of which he says:

I believe that the time is ripe for significantly better documentation of programs, and that we can best achieve this by considering programs to be works of literature. Hence, my title: “Literate Programming.”

Let us change our traditional attitude to the construction of programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do.

The practitioner of literate programming can be regarded as an essayist, whose main concern is with exposition and excellence of style. Such an author, with thesaurus in hand, chooses the names of variables carefully and explains what each variable means. He or she strives for a program that is comprehensible because its concepts have been introduced in an order that is best for human understanding, using a mixture of formal and informal methods that reinforce each other.

(more…)


tracker