Author Archives: James Lin

Bitwise and Enum

It’s been so long that I haven’t touched C# and today I got the chance to use it again, as you know, Enum is kind of popular in C# and for sure I encountered the bitwise operation again. To quickly pick it up again, I came across this awesome article http://weblogs.asp.net/wim/archive/2004/04/07/109095.aspx

Category: C#

My firefox memory leak has been resolved…

If you have google toolbar installed, disable it, then restart firefox. See if it improves your memory usage. It worked on mine. Hope this helps. If it works, please leave a comment and let others know.

Django common dictionary available to templates

We need to leverage TEMPLATE_CONTEXT_PROCESSORS, the following example uses the “home” application add this to settings.py TEMPLATE_CONTEXT_PROCESSORS = (“django.contrib.auth.context_processors.auth”, “django.core.context_processors.debug”, “django.core.context_processors.i18n”, “django.core.context_processors.media”, “django.core.context_processors.static”, “django.contrib.messages.context_processors.messages”, “home.context_processor.remote_ip”) in home application, create a python file called context_processor.py in the context_processor.py add a function like this: def remote_ip(request): return {‘remote_ip’: request.META[‘REMOTE_ADDR’]} for any templates needs to use this processor… Read More »

PHP Snippet: Get dates from a given range

function get_range_dates($start, $end){ $days = array(); $start_tmp = explode(“-“,$start); $end_tmp = explode(“-“,$end); $start_time = mktime(1,1,1, $start_tmp[1], $start_tmp[2], $start_tmp[0]); $end_time = mktime(1,1,1, $end_tmp[1], $end_tmp[2], $end_tmp[0]); while($start_time <= $end_time){ $days[] = date(“Y-m-d”, $start_time); $start_time += 86400; } return $days; } //calling the function get_range_dates(‘2011-02-01’, ‘2011-03-08’); Result: Array ( [0] => 2011-02-01 [1] => 2011-02-02 [2] => 2011-02-03… Read More »

Category: PHP