Searching tv shows in chinese video sites

Posted on October 29th, 2008 in Hacks, Other | No Comments »

Say you want to watch your favorite tv shows online, (hulu is not available in other place, those people think that the only country in the world is US), and you really want to watch it. You can go to Chinese video sites like youku.com and search for the shows that you want to watch, all you have to do is locate the search box and start searching. But how?

Usually they would name tv shows like heroes 第三季 07, or heroes第三季 第07集, now what does this mean? The first Chinese words, 第三季, means the 3rd quarter or the 3rd season, then the 2nd Chinese words, 第07集, means the 7th part or the 7th article or 7th set. Now what if i want to watch the 2nd episode in season 2? You would search something like ‘heroes 第二季 第2集’ or ‘heroes 第二季 第二集’ .

If we put it into a mathematical formula it should be something like
let search = x 第y季 第z集
where x is your favorite tv shows
y is the season number
z is the episode number

And here are the numbers for you to substitute from
1 = 一
2 = 二
3 = 三
4 = 四
5 = 五
6 = 六
7 = 七
8 = 八
9 = 九
10 = 十

So getting heroes season 1 ep 9 is like
search = heroes 第一季 第九集

What about numbers getter than ten? To get numbers beyond 10 you have to mix them in the formula
let num = x十y (the second character is not a plus but the Chinese ten 十)
where x be the multiplier of ten except 1, you will understand why except one later on
where y is from one to nine, then y would be added to the results of x十

Say you want to search for the 25th, it should be
二十五
Why? x is the multiplier then 2(10), 二十, is 20 then add 5,五, then its equal to 25, 二十五
Thirty four would be 三十四
Forty nine would be 四十九

You could simple rephase the formula to
let num = (x multiply to 10) plus y

Now from 11 to 19, you don’t need to add 一 to the front coz its the same with or without it.
And so 18 would be 十八
Fifteen would be 十五

If you find this way to complicated then you can use Google Translate, btw i’m not Chinese, i just studied in Hong Kong when i was small so i do know their language a bit.

Hope it helps and lets all hope that big media company would realize that there people outside US.

Ubuntu 8.10 on my laptop

Posted on October 27th, 2008 in Announcement | No Comments »

Brought a new harddisk for my mac laptop and installed mac leopard and ubuntu 8.10 ibex, dual booting it using refit. Ubuntu Intrepid Ibex would be released 3 days from now and i’m using it right now, hah. The thing i liked about it is the tab navigation for nautilus (file manager) and since i used the 64bit version i does feel faster. But it drawback is i have to install the 32bit version of flash, if anyone has a tutorial on install the 64bit flash version and it’s better do comment, thanks. Another thing i liked about it is the new xorg, and this time compiz can display not just cube desktop but also sphere desktop and cylinder desktop which totally looks good. I’ll still need to put back my files from my other harddisk so expect me lessen lessen my blog in the following 1-2 weeks. Thanks in advance and do support open source software.

Why you might hate the template system in django

Posted on October 26th, 2008 in Programming | 2 Comments »

Okay first of all I did try hard to love it but there are just so many annoying things about it that i really don’t like and here are some of them:

1) They have so many if statement that actually brakes the beauty of python, so you have if, ifchange, ifequal, and ifnotequal. Instead of just doing something like
{% if thisVariable == thatVariable %}

2) You cannot pass multiple arguments to custom filter, you can only pass 1 or 2 arguments, i don’t know what they were thinking when they decided this, but i hope they fix this quickly coz not all of time you only have to pass 1 or 2 arguments. (http://code.djangoproject.com/ticket/1199)

3) Templates are so strict that you cannot use underscore on an object. While this is good in terms of security and design, it adds up to your production time. Solving this would bring us to the next number

4) You need to use filter even if you don’t like to, say you just like to compare 2 numbers, ideally if #1 would be followed then its {% if a > b %} but nope, you have to do it on your custom filter. See everything that is not on the build-in filters of django you have to do it on your own even if that feature is part of python.

5) You cannot have 0 arguments on filters, say you just want to check if something is logged in or not, you cannot call the filter with {{ is_login }} but you need to pass a dummy argument like {{ 1|is_login }}

Now i know im just new with django but this stuff makes me feel that i’m not using python anymore, i say this when compared it to other templating system like smarty. Its a template engine but somehow you still feel that your using php. I hope django fix their template system

Auto Increment in App Engine

Posted on October 23rd, 2008 in App Engine, Google | No Comments »

So you want to implement auto increment on your datastore? Here is a simple tutorial of how to do it on App Engine. This auto increment will use integers, this does not cover more advance auto increments one like UUID.

For our example we would use this datastore model:
class Post(db.Model):
title = db.StringProperty()
body = db.StringProperty()

Then you would save records like with something like
post = Post()
post.title = "Example"
post.body = "This is the body"
post.put()

Then you shall see this saved on the datastore. But where did i declared the id? App engine by default will give each record a Key, having said that each row by default will have an auto incremented integer. To retrive a row by the id you would do something like
currentPost = Post.get_by_id(<id of the post>)

What if i fetch from the model, how can i get the id?
query = datamodel.Post().all()
for result in query:
self.response.out.write(result.key().id())

How can i get my auto generated id on templates?
{% for post in posts %}
{{ post.key.id }}
{% endfor %}

Use HTML on App Engine

Posted on October 22nd, 2008 in App Engine, Google | No Comments »

App Engine by default uses django, a Python web framework that’s a bit like Rails or CakePHP, most of the tutorial on the App Engine Documentation would not teach you to use Templates except the main Using Templates part. While this tutorial is good, it would not teach you how have a more optimized version. Here is how i did, i suggest you to read the App Engine Using Templates Tutorial:

import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
def page_display(page,file,values={}):
template_values = {}
template_values.update(values)
try:
template_values.update(page.template_values)
except:
pass
path = os.path.join(os.path.dirname(__file__),file)
page.response.out.write(template.render(path,template_values))
class MainPage(webapp.RequestHandler):
def get(self,page):
self.template_values = {
"message" : "Hello World",
"message2" : "Hello"
}
page_display(self,"templates/index.html")
def main():
application = webapp.WSGIApplication(
[
('/', MainPage)
],
debug = True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == “__main__”:
main()

As you can see if you have a lot of classes it would be a easier to remember and use
page_display(self,"templates/index.html")
then
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))

Alternate row colors in App Engine

Posted on October 20th, 2008 in App Engine, Google, Programming | No Comments »

You have a senario where you need to have alternating colors in each rows of data in app engine or django, how can you achieve this? Here is a simple solution on doing it (This took me more than 30 mins to find out the solution coz most of the time they will give you php’s solution on alternating rows)
{% for video in videos %}
<div class="row {% cycle odd,even %}">
{{ video.title }}
<div class="youtubeLink">
<a href="{{ video.youtube_id }}">
{{ video.youtube_id }}
</a>
</div>
</div>
{% endfor %}

The main solution is this code
{% cycle odd,even %}

What this do is that it cycles around each row and returns the right index (odd or even). And with this function you are not bound to just 2 selections, if you want more you could just do something like
{% cycle one,two,three,four %}

Hope this helps.

IE6 Not Supported Anymore

Posted on October 19th, 2008 in Announcement | No Comments »

Over the pass few months my browser share had always been firefox with 68%+. And in order for me to have an easier life, i’m turning off IE6 from the music section, expect the blog and all other sites under monmonja.com will follow with no IE Support especially IE6, for IE8 it must be standard complaint for my site to support it. It’s a tough decision but IE6 must be stopped from making web developer’s life harder and this is my way of expressing it. So if your using IE6 its time to get a real browser get firefox, opera, safari or chrome.