SEPTEMBER 30, 2010
jQuery Title Alert
A little more than a year ago I wrote a small jQuery plugin at ESN where I work, called jquery-titlealert. It provides functionality for flashing a notification message in the browser title.
Title alert notifications can be useful when you want to notify a user of some kind of web page event (for example an incoming chat message), when the user has another window, or another browser tab, in focus. Especially if your site uses real-time functionality, like contact lists, user chats, etc. Which, BTW, can easily be achieved using Beacon Push, which is a real-time website service we run at ESN.
Get it
Download v0.7 here. The source code is hosted at GitHub.
Last update: 2010-10-07
How to use it
First, include it on the web page (make sure jQuery has been previously included on that page):
<script type="text/javascript" src="jquery.titlealert.js"></script>
Then you will be able to flash a notification message in the browser title by running:
$.titleAlert("New chat message!");
Or with some options:
$.titleAlert("New chat message!", { requireBlur:false, stopOnFocus:false, duration:4000, interval:700 });
The plugin provides options for setting different timings and intervals, as well as functionality for stopping the message flashing when browser window gets focused. See below for all details.
API
$.titleAlert(message, options);
| message | A string the message that should be flashed in the browser title. |
| options | JavaScript object containing options |
Options
Here are the available options that can be set in the option object.
| name | default | description |
|---|---|---|
| interval | 500 | The flashing interval in milliseconds. |
| originalTitleInterval | null | Time in milliseconds that the original title is diplayed for. If null the time is the same as interval. |
| duration | 0 | The total lenght of the flashing before it is automatically stopped. Zero means infinite. |
| stopOnFocus | true | If true, the flashing will stop when the window gets focus. |
| stopOnMouseMove | false | If true, the flashing will stop when the document recieves a mousemove event (i.e. when the user moves the mouse over the document area, regardless of what window is active). |
| requireBlur | false | Experimental. If true, the call will be ignored unless the window is out of focus. Known issues: Firefox doesn't recognize tab switching as blur, and there are some minor IE problems as well. |
Compatibility
Title Alert works with jQuery 1.3 and 1.4. It's tested in Firefox, Chrome, Internet Explorer >= 6 and Safari.
JUNE 18, 2010
URL Shorteners Suck
Ever since the rise of twitter, when URL shortening services got an extremely big popularity boost because twitter chose to shorten their URLs for technical reasons while ignoring user experience, the web has been polluted with shortened links.
- I want to be able to see where a link goes before I click it.
- I want to be sure that my links continue to work indefinitely.
- I don't want random companies to track my internet usage.
URL shortening services interferes with all of my above statements. So please. Do. Not. Use. Them.
Let's just hope that the upcoming release of annotations for tweets functionality could help decrease the use of these horrible services.
How ever, there is a GreaseMonkey script that I've been using, called TinyURL Decoder, that changes URL shortened links into the real URL that they point to. It just solves one of the problems with URL shortening, but at least you can see where the links go.
MARCH 03, 2010
Favorite Django Tips
A few months ago I found a really useful Stack Overflow Question. Here are my favorites from the answers.
Use render_to decorator instead of render_to_response
This decorator is found in the app django annoying, and is a very nice shortcut for declaring what template a view should render.
Instead of returning the response of render_to_response, you just return a python dict which will be used as the template context for the template specified as argument to the @render_to decorator. If anything else than a dict is returned, normal view processing will occur, so this won't break redirects or any other cases where you might return a HttpResponse (for example normal render_to_response code).
Anyway, here is an example on how to use it:
@render_to("list.html") def list_posts(request): posts = BlogPost.objects.all() return {"blog_posts": posts}
This equals to:
def list_posts(request): posts = BlogPost.objects.all() return render_to_response('list.html', {'blog_posts': posts}, context_instance=RequestContext(request))
Update (22/4): Marcin Nowak notified me that the render_to decorator breaks Django Reusable App converions, so I made a fork of django-annoying where I modified the render_to decorator to support template_name and extra_context keyword arguments.
Load custom template tags in all templates
Custom template tags that you use all over your templates can be auto loaded. Just add the following in a module that is loaded (i.e. your urlconf if you want the template tags to be loaded for the whole project)
from django import template template.add_to_builtins('project.app.templatetags.custom_tag_module')
Use relative paths in settings.py
I hesitated about adding this tips, since I think it's quite obvious, but since so many people on Stack Overflow has voted it up, I guess there are people who use(d) absolute paths in their settings.py.
Don't use absolute paths in settings.py (i.e /home/jonatan/...), instead use relative paths so that the project will work wherever it resides.
import os.path TEMPLATE_DIRS = ( os.path.join(os.path.dirname(__file__), "templates"), )
JANUARY 08, 2010
MMS Decoder 0.82, and website back online
During the holiday I finally got to finish the re-make of my website, and I'm very happy to announce that it is now up and running on Python/Django. The biggest change here is that I've added a blog where I will write programming/web development/python/django/javascript/tech stuff. How ever, I predict that I will not write blog posts very often, but hopefully when I do, they will be interesting.
Powering this blog is a slightly modified version of Nathan Borror's Django Basic Apps. I'm planning to release my modified version (nothing fancy, just some small personal preference changes) as a GitHub fork when I get time.
New version of MMS Decoder (0.82)
I've released a new version of MMS Decoder that fixes a bug with decoding MMS messages encoded by an iPhone, as well as some other bugfixes and improvements.
Here are a few selected entries from the commit log:
- Fixed correct decoding of From-value.
- Changed default type of the part database column, in the example application, from blob to mediumblob.
- Adding different MMS PDUs I've collected during the years. Very useful for debugging.
MMS Decoder on GitHub
I'm also quite happy to announce that I have now created a GitHub project for my MMS Decoder. This way it will be much easier for people to make patches, and for me to incorporate them in the code, by forking me. So go ahead and fork me on: http://github.com/heyman/mms-decoder. (Or just follow me if you want to know when a new version is released).
If you just want to pull the GIT repository here is the URL:
git://github.com/heyman/mms-decoder.git
ABOUT ME
My name is Jonatan Heyman, and I'm a programmer. I'm also a climber, and I listen to
a large number of indie pop tunes. You can read more about me on the about page.
