2010-08-04

Thing you should know before moving your Django app into Google App Engine

Django's model has "id" field. It is auto-increment, unique integer for each models. GAE Datastore also has "id" field. It is *not* auto-increment, unique integer for *all* models. And you can not set the field as you want. This is annoying.

If you use Django's "id" field in permalink etc. (as I did), you need to add some field like "oldid", move old "id" value in it and write some code to put such a value in new coming items. For your information, when you can't inherit User models, you need to make a wrapper model. And also, you should change all code searching items with "id". You should change all "get_absolute_url" methods to use "oldid" in place of "id".

That is not all problem you should overcome. GAE Datastore doesn't allow inequality filter on more than one fields. If you use it, you should change the logic. Some of them are solvable with result caching. If you use SQL directly for speed-up, it won't work. Some query take more time or doesn't return correct value and there is DeadlineExceededException. You need tune-up in GAE way. You can't know how much items in your Datastore if it is more than 1000, in such case count() always return 1000.

Three month before, I thought it is easy task. Now I am convinced that I should rewrite the app. I hope it helps some people like me.

2010-07-30

List of abbreviations you may see in source codes

Hi, it is Dr. NISHIO Hirokazu. I'll teach to young programmers on Security and Programming Camp 2010. The youngest student is 13 years old. I suddenly thought if I was 13 years old now, could I understand several abbreviations in source code, for example, std, tmp, ptr, ary, btn, cpy, cmp, snd, and so on.... No no no no, I can't! I'm Japanese! I just learned "Good morning, Tom. This is a pen." yesterday!

I searched a list of abbreviations, but I can't find it. So I made it:
List of abbreviations you may see in source codes
You can post new items from here

2010-07-29

LISP as pretty girls

Hi, it is Dr. NISHIO Hirokazu. Today I saw unbelievable news.

http://journal.mycom.co.jp/news/2010/07/27/007/index.html (in Japanese)



An idol group "LISP" has sat up! In the news:



  • It was named after a term of artificial intelligence programming
  • Its concept is "connect with you", intend to "communicate with fan every day"
  • In order to keep connecting with fans, the members of LISP always be with small laptop, using Twitter and web radio.
  • On 7/30, LISP official site named "LISP OFFICIAL WEB SITE ~room and computer and LISP~" will be open. In it, free fan club "familisp" comes.


Members said:

  • It is fun if we discuss with you what LISP you want to see, what LISP is fun, etc. (Azusa)
  • I want to think with you the pose of LISP! (Azusa)
  • LISP is just a newborn, but we want to progress step by step with your encouragement! (Yuuri)


There were also some novels (S-Expression Communication) from 2006. You may know, intense, close communication is an advantage of LISP. I love read-eval-print-loop. Now I'm interested in whether she supports macro to make her appearance my own?

2010-07-20

My Favorite Weather Forecast: Fire! Buccal cone!

It is the weather forecast on Kansai area, Japan. Buccal cones are six tentacles of a clione, which come out to catch other plankton.

2010-07-13

Python Lost $20 Quiz

You can get $999 on the first day, and get a half of it (floored, that is $499) on the second day, and get half ... eventually how much you get in total? You received an e-mail, the payment in each days are printed in it, comma-separated. You split it with comma, eval and sum. Your answer is $1970. Oh, really is it correct?



>>> def format(xs):
return ",".join("%03d" % x for x in xs)

>>> format([123, 456, 789])
'123,456,789'



>>> def list_gen(n):
while n:
yield n
n /= 2

>>> list(list_gen(64))
[64, 32, 16, 8, 4, 2, 1]



>>> email = format(list_gen(999))
>>> sum(eval(s) for s in email.split(","))
1970



>>> total = 0
>>> 999
999
>>> total += _
>>> _ / 2
499
>>> total += _
>>> _ / 2
249
>>> total += _
>>> _ / 2
124
>>> total += _
>>> _ / 2
62
>>> total += _
>>> _ / 2
31
>>> total += _
>>> _ / 2
15
>>> total += _
>>> _ / 2
7
>>> total += _
>>> _ / 2
3
>>> total += _
>>> _ / 2
1
>>> total += _
>>> _ / 2
0
>>> total
1990