What's your Rashee!!??!!

Mr. Ashutosh Gowarikar, you disappoint me. What a movie, "What's your Rashee?"!?!

I again made the mistake on spending movie on a bollywood movie! I just hope this does not become my habit.

A little homework for all those who have already booked the movie tickets & / or will be watching the movie.

To make the movie interesting & not feel disappointed after the movie, think of your friend, who is currently looking for brides / grooms. Imagine this is their story and start imagining from their point of view. How would s/he would react. I am sure that will make the movie more interesting.

Ofcourse, all this has been an after thought & I did not think of this while watching the movie, else I would have also enjoyed it a lot.

So, all those who want to see the movie, put on your thinking hats & go ahead to enjoy the movie.

Even the most distant dream can be realized with determination and persistence.

In 1883, a creative engineer named John Roebling was inspired by an idea to build a spectacular bridge connecting New York with the Long Island. However bridge building experts throughout the world thought that this was an impossible feat and told Roebling to forget the idea. It just could not be done. It was not practical. It had never been done before. Roebling could not ignore the vision he had in his mind of this bridge. He thought about it all the time and he knew deep in his heart that it could be done. He just had to share the dream with someone else.

After much discussion and persuasion he managed to convince his son Washington, an up and coming engineer, that the bridge in fact could be built.Working together for the first time, the father and son developed concepts of how it could be accomplished and how the obstacles could be overcome. With great excitement and inspiration, and the headiness of a wild challenge before them, they hired their crew and began to build their dream bridge.

The project started well, but when it was only a few months under way a tragic accident on the site took the life of John Roebling. Washington was injured and left with a certain amount of brain damage, which resulted in him not being able to walk or talk or even move.
 "We told them so."
"Crazy men and their crazy dreams."
"It`s foolish to chase wild visions."
Everyone had a negative comment to make and felt that the project should be scrapped since the Roeblings were the only ones who knew how the bridge could be built.

In spite of his handicap Washington was never discouraged and still had a burning desire to complete the bridge and his mind was still as sharp as ever.He tried to inspire and pass on his enthusiasm to some of his friends, but they were too daunted by the task. As he lay on his bed in his hospital room, with the sunlight streaming through the windows, a gentle breeze blew the flimsy white curtains apart and he was able to see the sky and the tops of the trees outside for just a moment.It seemed that there was a message for him not to give up. Suddenly an idea hit him. All he could do was move one finger and he decided to make the best use of it. By moving this, he slowly developed a code of communication with his wife.He touched his wife's arm with that finger, indicating to her that he wanted her to call the engineers again. He used the same method of tapping her arm to tell the engineers what to do. It seemed foolish but the project was under way again. For 13 years Washington tapped out his instructions with his finger on his wife's arm, until the bridge was finally completed.

Today the spectacular Brooklyn Bridge stands in all its glory as a tribute to the triumph of one man's indomitable spirit and his determination not to be defeated by circumstances. It is also a tribute to the engineers and their team work, and to their faith in a man who was considered mad by half the world. It stands too as a tangible monument to the love and devotion of his wife who for 13 long years patiently decoded the messages of her husband and told the engineers what to do.

Perhaps this is one of the best examples of a never-say-die attitude that overcomes a terrible physical handicap and achieves an impossible goal. Often when we face obstacles in our day-to-day life, our hurdles seem very small in comparison to what many others have to face. The Brooklyn Bridge shows us that dreams that seem impossible can be realised with determination and persistence, no matter what the odds are.

Moral of the story:
 Even the most distant dream can be realized with determination and persistence.

Original mail sent by Manish Balwani on Mensa India, mailing list.

--
Ships are safe in the harbour But that is not what ships are built for

Why text messages are limited to 160 characters

Technology

The business and culture of our digital lives,
from the L.A. Times

« Previous Post | Technology Home | Next Post »

Why text messages are limited to 160 characters

May 3, 2009 |  1:28 pm
Credit: Lori Shepler / Los Angeles Times

Alone in a room in his home in Bonn, Germany, Friedhelm Hillebrand sat at his typewriter, tapping out random sentences and questions on a sheet of paper.

As he went along, Hillebrand counted the number of letters, numbers, punctuation marks and spaces on the page. Each blurb ran on for a line or two and nearly always clocked in under 160 characters.

That became Hillebrand's magic number -- and set the standard for one of today's most popular forms of digital communication: text messaging.

"This is perfectly sufficient," he recalled thinking during that epiphany of 1985, when he was 45 years old. "Perfectly sufficient."

The communications researcher and a dozen others had been laying out the plans to standardize a technology that would allow cellphones to transmit and display text messages.  Because of tight bandwidth constraints of the wireless networks at the time -- which were mostly used for car phones -- each message would have to be as short as possible.

Before his typewriter experiment, Hillebrand had an argument with a friend about whether 160 characters provided enough space to communicate most thoughts. "My friend said this was impossible for the mass market," Hillebrand said. "I was more optimistic."

His optimism was clearly on the mark. Text messaging has become the prevalent form of mobile communication worldwide. Americans are sending more text messages than making calls on their cellphones, according to a Nielsen Mobile report released last year.

U.S. mobile users sent an average of 357 texts per month in the second quarter of 2008 versus an average of 204 calls, the report said.

Texting has been a boon for telecoms. Giants Verizon Wireless and AT&T each charge 20 to 25 cents a message, or $20 for unlimited texts. Verizon has 86 million subscribers, while AT&T's wireless service has 78.2 million.

And Twitter, the fastest growing online social network, which is being adopted practically en masse by politicians, celebrities ...

... and news outlets, has its very DNA in text messaging. To avoid the need for splitting cellular text messages into multiple parts, the creators of Twitter capped the length of a tweet at 140 characters, keeping the extra 20 for the user's unique address.

Back in 1985, of course, the guys who invented Twitter were probably still playing with Matchbox cars.

Friedhelm Hillebrand

Credit: Friedhelm Hillebrand

Hillebrand found new confidence after his rather unscientific investigations. As chairman of the nonvoice services committee within the Global System for Mobile Communications (GSM), a group that sets standards for the majority of the global mobile market, he pushed forward the group's plans in 1986. All cellular carriers and mobile phones, they decreed, must support the short messaging service (SMS).

Looking for a data pipeline that would fit these micro messages, Hillebrand came up with the idea to harness a secondary radio channel that already existed on mobile networks.

This smaller data lane had been used only to alert a cellphone about reception strength and to supply it with bits of information regarding incoming calls. Voice communication itself had taken place via a separate signal.

"We were looking to a cheap implementation," Hillebrand said on the phone from Bonn. "Most of the time, nothing happens on this control link. So, it was free capacity on the system."

Initially, Hillebrand's team could fit only 128 characters into that space, but that didn't seem like nearly enough. With a little tweaking and a decision to cut down the set of possible letters, numbers and symbols that the system could represent, they squeezed out room for another 32 characters.

Still, his committee wondered, would the 160-character maximum be enough space to prove a useful form of communication? Having zero market research, they based their initial assumptions on two "convincing arguments," Hillebrand said.

For one, they found that postcards often contained fewer than 150 characters.

Second, they analyzed a set of messages sent through Telex, a then-prevalent telegraphy network for business professionals. Despite not having a technical limitation, Hillebrand said, Telex transmissions were usually about the same length as postcards. 

Just look at your average e-mail today, he noted. Many can be summed up in the subject line, and the rest often contains just a line or two of text asking for a favor or updating about a particular project.

But length wasn't SMS's only limitation. "The input was cumbersome," Hillebrand said. With multiple letters being assigned to each number button on the keypad, finding a single correct letter could take three or four taps. Typing out a sentence or two was a painstaking task.

Sms-doc

A GSM document outlining the definition of SMS. Credit: Friedhelm Hillebrand.

Later, software such as T9, which predicts words based on the first few letters typed by the user, QWERTY keyboards such as the BlackBerry's and touchscreen keyboards including the iPhone's made the process more palatable.

But even with these inconveniences, text messaging took off. Fast. Hillebrand never imagined how quickly and universally the technology would be adopted. What was originally devised as a portable paging system for craftsmen using their cars as a mobile office is now the preferred form of on-the-go communication for cellphone users of all ages.

"Nobody had foreseen how fast and quickly the young people would use this," Hillebrand said. He's still fascinated by stories of young couples breaking up via text message.

When he tells the story of his 160-character breakthrough, Hillebrand says, people assume he's rich. But he's not.

There are no text message royalties. He doesn't receive a couple of pennies each time someone sends a text, like songwriters do for radio airplay. Though "that would be nice," Hillebrand said.

Now Hillebrand lives in Bonn, managing Hillebrand & Partners, a technology patent consulting firm. He has written a book about the creation of GSM, a $255 hardcover tome.

Following an early retirement that didn't take, Hillebrand is pondering his next project. Multimedia messaging could benefit from regulation, he said. With so many different cellphones taking photos, videos and audio in a variety of formats, you can never be sure whether your friend's phone will be able to display it.

But he's hoping to make a respectable salary for the work this time.

-- Mark Milian

100+ Useful Bookmarklets For Better Productivity | Ultimate List | Tools

 

In a nutshell, bookmarklets are small little applications you can place as browser’s bookmark bar and they each perform a specific function, depending on what they are coded for. Bookmarklets are usually written in Javascript and they are extremely easy to install/remove. Bookmarklets work in most common used browsers like Firefox, Opera and Safari but probably lesser support in Internet Explorer.

In this article, we’ll show you some of the most useful bookmarklets for designers, developers or even if you are a net surfer, they might just come in handy. Installing a bookmarklet is simple – all you need to do is drag them to your bookmark toolbar, that’s all.

Why bookmarklet are cool?

They are efficient! We figured you might compare it with add-ons and browser plug-ins. Here are some advantages of bookmarklets over plug-ins we can quickly come out with:

  • Hassle-less installation – Installing a bookmarklet is simple. All you need to do is drag it up to the bookmark toolbar. To remove them, just right click on it and hit delete.
  • Light – If you’ve installed more than 15 add-ons in your Firefox, you’ll probably find it slower to start. Bookmarklets are just couple of lines of Javascript codes. You can have 50 and Firefox doesn’t even lag a bit.
  • No updates – Most plugins require update especially when there is a new version of the browser. Boomarklet on the other hand, are less likely to require an update.
  • Cross Browser compatibility – Bookmarklets are written with Javascripts, they work in most browsers.

 

Social Bookmarking and Sharing

Here are a bunch of social bookmarking bookmarklets that might come in handy:

Browser resize

Here’s a complete article of browser resizing bookmarklets with positioning capability.

browser resize bookmarklets

 

Readability, Download and Prints

Shorten URL – In this case, we use bit.ly’s shortening bookmarklet. Click here for a list of URL shorteners with bookmarklet scripts.

Kwout – Make a screen shot of any website you are in with Kwout.

Print Screen – Another print screen bookmarklet. By Aviary.

Browsershot – Get a browsershot printscreen of any website.

Better Readability – This bookmarklet cleans up the page, leaving you with nothing but clean content for better readability. You can create a customized version at Arc90 Lab.

better readability

Tidy Read – Tidy up your page for better readability.

Remove bloat- Remove all occurrences of Flash, Java,and other third-party iframes.

Edit Website – Allows you to edit any websites you viewed. Original display will be restored upon refresh.
edit website

Customize Print – Allows you to customize the layout, fonts, colors, etc before printing a webpage. By printwhatyoulike.

Download as PDF (Firefox) – Convert and save page as PDF. Click here for bookmarklets of other browsers. By pdfdownload.

Download video – Supports YouTube, Google Video, Metacafe, Myspace, Break.com, Putfile, Dailymotion, Sevenload, MyVideo.de and Clipfish.de.

More: Zoom in, Zoom out, Remove background, Highlight links

Traffic, Password and Site Information

Zap Cookie – Removes cookies set by the site, including cookies with paths and domains.

Show Password – Set a password and forgot? This bookmarklet takes in your ***** from form field and output you the actual password.

get password

Site Info – A bookmarklet that gives you information (advertising network, platform, widgets, etc) of the website you are currently viewing. By sitonomy.

Site Info – Another bookmarklet to find site info By Buildwith.

Domain owner – Tells you who own the domain of the site you are viewing.

Delicious – Shows you who, how many people bookmarked the site in delicious.

Alexa – Shows you the Alexa ranking of the site.

Compete – Shows compete.com ranking.

Technorati – Find out more information about a particular blog. Click here for more Technorati bookmarklets.

AttentionMeter – Gives you the Alexa, Quancast, Crunchbase, Alexa and Technorati ranking of the site in a lightbox.

Uptime Check – Check if a website is down for everyone or just you. By downforeveryoneorjustme.

Design and Develop

Aardvark – Aardvark is a Firefox plugin that gives you HTML element details like ID, class, image, position, etc of the page you are viewing. Good news is, it also comes in bookmarklet format.

Layout Grid – Applies a layout grid image to the body of the page.

grid display

Disable Image, Remove Image.

Test Selectors – Test and play with selectors. By Westciv.

Spry Media – Created by Spry Media, this bookmarklet allow you to view a page in grid view, with ruler measurement, measuring points with units and much more.

XRAY – See box model for any element on any site. By Westciv.

Reload CSS – Reloads CSS every 2 seconds. Useful for those who’s constantly editing on the design and need a fresh look at the effects.

Validate RSS – Check site RSS validity with feedvalidator.org.

Validate CSS – Validate site’s CSS. More CSS bookmarklets – View CSS, List Compute CSS.

Validate HTML- Check if site is using valid HTML based on w3.org. More HTML bookmarklets – Show tables, Show table headings, Show table cells.

Dictionary and Translation

Quickly search and get answers from these online sites:

These following bookmarklets allow you to quickly translate a webpage from one language to another using Google translate.

You can also try this Auto Detect Language bookmarklet, or visit unusualbookmarklets for a complete set and various methods of translation bookmarklets.

Useful Tools and More Bookmarklets

How to Efficiently Manage Your Collection of Bookmarklets – Efficiently manage bookmarklets across all browsers and computers.

Translation Bookmarklets – Great list of various translation bookmarklets.

howtocreate.co.uk – More bookmarklets for designers and developers.

Blummy – Organize your bookmarklets, by Blummy.com.

blummy

webreference.com – How to create Bookmarklets.

Bookmarklets.com

Squarefree.com

PimpMySafari – Great collection of bookmarklets for Safari browser.

 

Urinal protocol vulnerability

When a guy goes into the bathroom, which urinal does he pick?  Most guys are familiar with the International Choice of Urinal Protocol.  It’s discussed at length elsewhere, but the basic premise is that the first guy picks an end urinal, and every subsequent guy chooses the urinal which puts him furthest from anyone else peeing.  At least one buffer urinal is required between any two guys or Awkwardness ensues.

Let’s take a look at the efficiency of this protocol at slotting everyone into acceptable urinals.  For some numbers of urinals, this protocol leads to efficient placement.  If there are five urinals, they fill up like this:

The first two guys take the end and the third guy takes the middle one.  At this point, the urinals are jammed — no further guys can pee without Awkwardness.  But it’s pretty efficient; over 50% of the urinals are used.

On the other hand, if there are seven urinals, they don’t fill up so efficiently:

There should be room for four guys to pee without Awkwardness, but because the third guy followed the protocol and chose the middle urinal, there are no options left for the fourth guy (he presumably pees in a stall or the sink).

For eight urinals, the protocol works better:

So a row of eight urinals has a better packing efficiency than a row of seven, and a row of five is better than either.

This leads us to a question: what is the general formula for the number of guys who will fill in N urinals if they all come in one at a time and follow the urinal protocol? One could write a simple recursive program to solve it, placing one guy at a time, but there’s also a closed-form expression.  If f(n) is the number of guys who can use n urinals, f(n) for n>2 is given by:

The protocol is vulnerable to producing inefficient results for some urinal counts.  Some numbers of urinals encourage efficient packing, and others encourage sparse packing.  If you graph the packing efficiency (f(n)/n), you get this:

This means that some large numbers of urinals will pack efficiently (50%) and some inefficiently (33%).  The ‘best’ number of urinals, corresponding to the peaks of the graph, are of the form:

The worst, on the other hand, are given by:

So, if you want people to pack efficiently into your urinals, there should be 3, 5, 9, 17, or 33 of them, and if you want to take advantage of the protocol to maximize awkwardness, there should be 4, 7, 13, or 25 of them.

These calculations suggest a few other hacks.  Guys: if you enter a bathroom with an awkward number of vacant urinals in a row, rather than taking one of the end ones, you can take one a third of the way down the line.  This will break the awkward row into two optimal rows, turning a worst-case scenario into a best-case one. On the other hand, say you want to create awkwardness.  If the bathroom has an unawkward number of urinals, you can pick one a third of the way in, transforming an optimal row into two awkward rows.

And, of course, if you want to make things really awkward, I suggest printing out this article and trying to explain it to the guy peeing next to you.

Discussion question: This is obviously a male-specific issue.  Can you think of any female-specific experiences that could benefit from some mathematical analysis, experiences which — being a dude — I might be unfamiliar with?  Alignments of periods with sequences of holidays? The patterns to those playground clapping rhymes? Whatever it is that goes on at slumber parties? Post your suggestions in the comments!

Edit: The protocol may not be international, but I’m calling it that anyway for acronym reasons.

This entry was posted on Wednesday, September 2nd, 2009 at 5:29 am and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Kyon Keeda Hai Aapko

One more amazing song from Quick Gun Murugun!

I just can't get over the music, such fantastic lyrics & good music! haha... ;-)

Kyon Keeda Hai Aapko

Bak Bak Hai Aapki Sun Li, Kis Khet Ki Aap Hai Muli
Tedhe Sawaalon Ke Hai Tedhe Jawaab
Miyaan Na Bibi Raaji Phir Bhi Lage Hain Kaaji
Itane Asamnjas Mein Hai (kyun Janaab -5)

Hona Hai Jo Usako Ji Hone De, Rote Hai Jo Unako Ji Rone De
Ungali Karate Kyun Har Jagah, Kyun Vichlit Hai Kyun Khafa
Kyun Keeda Hai Aapko, Kyun Pida Hai Khaamkha
Kyun Janaab - (4)
(sargam)

Jisako Jo Kehana Hai Kehane De, Kutte Ki Dum Hai Tedhi Rehane De
Kaam Se Kaam Apana Bas Rakhe
Ungali Karate Kyun Har Jagah, Kyun Chintit Hai Bewajah
Kyun Keeda Hai Aapko, Kyun Pida Hai Khaamkha
Kyun Janaab - (4)

Asantulit Sangat Hai, Pida Ke Aachumbak Hai
Chhode Apana Chirkut Bhram, Tyaage Sab Kaaryakram
Asamjas Hai Aapaka Kuchh, Karam Karein Na Soche Kuchh
Guthali Chhode Khaaye Aam, Aapse Meri Traahi Maam

Kaminey, a movie that leaves behind a bitter taste!

On the 'auspicious' day of 09/09/09 I dared to watch a movie by the name of "Kaminey".

One more of the badly made bollywood flicks. I don't know from which film the theme was stolen, but it being a bollywood movie, with such a pathetic ending, can be made, if you copy a western flick and modify it for the "Indian" viewers!

In the first few minutes of the movie, we wonder what is happening. Later as the movie progresses you start to understand a little. By interval, you start liking the movie a little. Story line seems a tad different from the normal. As the film comes to an end, you absolutely start hating the movie and yourself for spending Rs. 130 in E-Square on a Wednesday Night!! In the end all the bad guys, twin brother Hero's, a pregnant heroin & cops arrive in one of the slums of Mumbai. A high voltage drama over Cocaine starts, bullets are sprayed, there is fire & smoke from burning cocaine, all bad guys manage to shoot each other, a few cops are killed, but not a single bullet touches the heroin!

What an un-imaginable and amazing end!!

If anybody asks me to rate the movie, I will rate it as 3 / 5 upto just before the end, where the pregnant heroin suddenly picks a machine gun and starts firing at her brother. After that the movie rating plunges to about -5 / 5 so an overall rating is -1 / 5.

Get Thunderbird to minimizing to tray instead of closing « bigbrovar

bigbrovar

September 5, 2009

Get Thunderbird to minimizing to tray instead of closing

Filed under: Archlinux, Gnome, Guides, KDE, Ubuntu — Bigbrovar @ 7:49 am
Tags: , , ,

One of the first set of things i do when i install a fresh (k)ubuntu is change the default email client. Both evolution (ubuntu) and kmail (kubuntu) don’t just cut it for me, they always seem bloated and buggy. I am a KISS guy -not that kiss (fine am that kiss too but the kiss i refer here is the Keep It Simple Stupid kind of kiss :D ) hence i find thunderbird to be the email client that just suits my needs. It doesn’t try to take over the world or make dinner for me. Its first and foremost an email client and its keeps with the Unix philosophy of do one thing and do it well.

However one thing i have always wish it had was the ability to run in the background so that if i close thunderbird i want it to minimize to the system-tray/notification area and inform me real time when i have a new mail. Thunderbird has a small memory footprint hence am not bothered about it sucking up my system resources. For a very long time i took what life offered and made do with opening thunderbird to check for a new mail and closing it when i am done (i hate having my task manager side of the system panel filed up with running applications). Then one day i was like heck i have had enough and decided out to find a way to get thunderbird to do exactly what i want (run in the system-tray when not needed.) i did some googling and the name firetray came up, turned out it was just want i wanted.

Installation and Configuration

Firetray is an add-on for thunderbird and can be downloaded from here download and save the file to your hard disk. In Mozilla Thunderbird, open Add-ons from the Tools menu.

thunderbird tool

Click the Install button, and locate/select the file you downloaded and click “OK”.

thunderbird extensions

After this you need to restart Thunderbird for the firetray to start working. You might also want to go through the preference of firetray to configure how you want it to behave, for example by default thunderbird does not minimize to the system-tray when you close it. You can go through the settings and configure it to your taste. Here is how i have configured mine.

firetray config

Conclusion

I have come to find firetray a very valuable plugin for thunderbird.

firetray

It allows me to make Thunderbird run in the background and get out of my way. when they is a new mail, i get notified and it tells me how many unread mail i have in-box

One more cool thing i love about it is how it makes it easy to check for new messages and even send a quick email, By just right clicking on the icon on the system-tray

check-new-email

Ok that is the end of my rant. Hope this helps somebody.

FYI: Firetray can also be added to firefox, sunbird, seamonkey 2 and songbird, allowing to set up custom icon, minimizing to tray instead of closing, control playback using multimedia keys in songbird

Possibly related posts: (automatically generated)

Recently started using Thunderbird again on ubuntu. Found this article helpful, hence sharing.

Original post http://bit.ly/2PC4E7

Jannis Leidel - An autocomplete form widget for ForeignKey model fields

 

← An autocomplete widget for django-tagging ...

An autocomplete form widget for ForeignKey model fields

In my last post I showed you how to write your own widget for django-tagging form fields that uses the nifty jQuery autocomplete plugin to simplify entering tags. This time I’d like to take on a suggestion PatricK made in the comments:

my question is, if this could be done on a more abstract level for enhancing relations. when having a foreignkey, you get the browse-icon (lens) right near the input-field. it´d be awesome to search the relations just by typing something into the field … the autocomplete-functionality should then search the related entries on the basis of the defined search-fields.

Well, this is what I’m going to do today :)

Preface

Thanks to the way Django’s forms work, the following implementation should be applicable to your own Django code — but please bare in mind that this isn’t a copy and paste how-to. I rather encourage you to learn about the flexibility of forms, fields and widgets and how it’s used in the automatic Admin interface. You’ll be able to — and sometimes required — to customize the code posted below.

As an example I’m going to use the message system that is included in Django’s auth contrib app. As far as I know Django doesn’t provide an admin representation for the Message class by default because it’s supposed to be used programmatically (and is used by the admin itself, too). The model consists of two fields, a ForeignKey to a User and a text field for the message.

Use case

Since ForeignKey fields are rendered as select fields by default there is a good chance that they become unusable if there are a lot of possible choices. So in case you have a lot of users in your database for example it might be a bit cumbersome to choose a user from the ForeignKey dropdown menu. Django provides an option that allows specifying a raw_id_fields attribute in your ModelAdmin subclass that will tell Django to render the ForeignKey as a simple input taking the primary key of the refered object. The actual selection is done by clicking the browse icon next to the field and browsing the model with the standard admin interface in a popup. What I want to provide here though is a way to do that directly in place, in the original form.

Widget

We are going to use the jQuery and the great Autocomplete plugin again which does all the hard work. Please download the sources of the autocomplete plugin if you don’t have it already. It includes everything we need to get started. Copy all files and folders of the extracted jQuery Autocomplete zip file to the directory you specified in the MEDIA_ROOT setting. It should then contain: ‘jquery.autocomplete.js’, ‘jquery.autocomplete.css’ and a ‘lib’ directory with the other necessary files. In case you arrange your files differently don’t hesitate to change the paths below in the inner Media class.

It has been proven to be a good idea to put something like the follwing widget in the widgets.py of your Django app, but any place will do if you change the import paths.

from django import formsfrom django.conf import settingsfrom django.utils.safestring import mark_safefrom django.utils.text import truncate_wordsclass ForeignKeySearchInput(forms.HiddenInput):    """    A Widget for displaying ForeignKeys in an autocomplete search input     instead in a ``select`` box.    """    class Media:        css = {            'all': ('jquery.autocomplete.css',)        }        js = (            'lib/jquery.js',            'lib/jquery.bgiframe.min.js',            'lib/jquery.ajaxQueue.js',            'jquery.autocomplete.js'        )    def label_for_value(self, value):        key = self.rel.get_related_field().name        obj = self.rel.to._default_manager.get(**{key: value})        return truncate_words(obj, 14)    def __init__(self, rel, search_fields, attrs=None):        self.rel = rel        self.search_fields = search_fields        super(ForeignKeySearchInput, self).__init__(attrs)    def render(self, name, value, attrs=None):        if attrs is None:            attrs = {}        rendered = super(ForeignKeySearchInput, self).render(name, value, attrs)        if value:            label = self.label_for_value(value)        else:            label = u''        return rendered + mark_safe(u'''            <style type="text/css" media="screen">                #lookup_%(name)s {                    padding-right:16px;                    background: url(                        %(admin_media_prefix)simg/admin/selector-search.gif                    ) no-repeat right;                }                #del_%(name)s {                    display: none;                }            </style><input type="text" id="lookup_%(name)s" value="%(label)s" /><a href="#" id="del_%(name)s">
</a> <script type="text/javascript"> if ($('#lookup_%(name)s').val()) { $('#del_%(name)s').show() } $('#lookup_%(name)s').autocomplete('../search/', { extraParams: { search_fields: '%(search_fields)s', app_label: '%(app_label)s', model_name: '%(model_name)s', }, }).result(function(event, data, formatted) { if (data) { $('#id_%(name)s').val(data[1]); $('#del_%(name)s').show(); } }); $('#del_%(name)s').click(function(ele, event) { $('#id_%(name)s').val(''); $('#del_%(name)s').hide(); $('#lookup_%(name)s').val(''); }); </script> ''') % { 'search_fields': ','.join(self.search_fields), 'admin_media_prefix': settings.ADMIN_MEDIA_PREFIX, 'model_name': self.rel.to._meta.module_name, 'app_label': self.rel.to._meta.app_label, 'label': label, 'name': name, }

This widget renders ForeignKeys as hidden inputs and adds a second input field to search in the related model using asynchronous requests, sometimes refered to as AJAX. Once the user selects a result the widget will automatically set the hidden field to the primary key. When editing an existing entry this will automatically populate the search field with the correct verbose value.

Admin integration

As already stated we are going to create an admin class for the Message model to enable admins to create messages for other users that will be displayed the next time they use the admin (or any other site that uses User.get_and_delete_messages).

The best place for the admin class is an admin.py file in one of your own app directories because it’s then picked up by Django’s autodiscover() function.

import operatorfrom django.db import modelsfrom django.contrib.auth.models import Messagefrom django.http import HttpResponse, HttpResponseNotFoundfrom django.contrib import adminfrom django.db.models.query import QuerySetfrom django.utils.encoding import smart_strfrom yourapp.widgets import ForeignKeySearchInputclass MessageAdmin(admin.ModelAdmin):    list_display = ('user', 'message')    related_search_fields = {        'user': ('username', 'email'),    }    def __call__(self, request, url):        if url is None:            pass        elif url == 'search':            return self.search(request)        return super(MessageAdmin, self).__call__(request, url)    def search(self, request):        """        Searches in the fields of the given related model and returns the         result as a simple string to be used by the jQuery Autocomplete plugin        """        query = request.GET.get('q', None)        app_label = request.GET.get('app_label', None)        model_name = request.GET.get('model_name', None)        search_fields = request.GET.get('search_fields', None)        if search_fields and app_label and model_name and query:            def construct_search(field_name):                # use different lookup methods depending on the notation                if field_name.startswith('^'):                    return "%s__istartswith" % field_name[1:]                elif field_name.startswith('='):                    return "%s__iexact" % field_name[1:]                elif field_name.startswith('@'):                    return "%s__search" % field_name[1:]                else:                    return "%s__icontains" % field_name            model = models.get_model(app_label, model_name)            qs = model._default_manager.all()            for bit in query.split():                or_queries = [models.Q(**{construct_search(                    smart_str(field_name)): smart_str(bit)})                        for field_name in search_fields.split(',')]                other_qs = QuerySet(model)                other_qs.dup_select_related(qs)                other_qs = other_qs.filter(reduce(operator.or_, or_queries))                qs = qs & other_qs            data = ''.join([u'%s|%s\n' % (f.__unicode__(), f.pk) for f in qs])            return HttpResponse(data)        return HttpResponseNotFound()    def formfield_for_dbfield(self, db_field, **kwargs):        """        Overrides the default widget for Foreignkey fields if they are        specified in the related_search_fields class attribute.        """        if isinstance(db_field, models.ForeignKey) and \                db_field.name in self.related_search_fields:            kwargs['widget'] = ForeignKeySearchInput(db_field.rel,                                    self.related_search_fields[db_field.name])        return super(MessageAdmin, self).formfield_for_dbfield(db_field, **kwargs)admin.site.register(Message, MessageAdmin)

So this code does several things:

  • It inherits from the default ModelAdmin to be able to override the default widget.
  • A new related_search_fields class attribute that is a mapping between lowercase model names and a list of fields to searched in. It uses the same syntax as the search_fields attribute to speed up the lookups or restrict them if needed. The following example would only match the beginning of the first and last name of users:
related_search_fields = {    'user': ('^first_name', '^last_name'),}
  • It overrides the __call__ method to add additional URL handler to the admin to be used by the widget for searching. It will be waiting for requests on /<root-admin-path>/auth/message/search/.
  • The search view that constructs the querysets depending on the provided model and search fields and returns the data as a simple string. The Autocomplete plugin can parse that and will display it in the selection.
  • A formfield_for_dbfield method that will override the widget of any ForeignKey field whose name is specified in the related_search_fields class attribute.

Once assembled the result will mostly look like that:

Please note that I use a different stylesheet for the Autocomplete plugin here.

***---***
Jannis Leidel - An autocomplete form widget for ForeignKey model fields http://bit.ly/iQifI

Fixed: Large font in the GDM login text field after installing xserver-xorg-video-intel

On Ubuntu Hardy Heron 8.04 LTS, with intel graphics card, some people might face a problem with the GDM.

Too big fonts + windows. To correct this issue,

sudo vi /etc/X11/xorg.conf

goto to the "Monitor" section and add
Option "DCC" "no"

This is a known bug, http://bit.ly/30DODY

About

A software professional & an amateur wildlife photographer