What is 4277075694

This entry was moved to NISHIO Hirokazu's blog


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.


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


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?


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.


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])

>>> 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(","))

>>> total = 0
>>> 999
>>> total += _
>>> _ / 2
>>> total += _
>>> _ / 2
>>> total += _
>>> _ / 2
>>> total += _
>>> _ / 2
>>> total += _
>>> _ / 2
>>> total += _
>>> _ / 2
>>> total += _
>>> _ / 2
>>> total += _
>>> _ / 2
>>> total += _
>>> _ / 2
>>> total += _
>>> _ / 2
>>> total


Haskell Quiz Answer

This entry was moved to NISHIO Hirokazu's blog


Real Point-free Haskell Program

This entry was moved to NISHIO Hirokazu's blog



Prelude Control.Applicative> let superdot =
(((<*>).(((<*>).).(((.).).).(.)))<*>const const)
Prelude ...> :t superdot
superdot ::
(b -> b -> c) -> (b1 -> b) -> b1 -> b1 -> c
Prelude ...> superdot compare snd (0, 1) (0, 0)

Hi, it is NISHIO Hirokazu. I just needed "dot" operator for 2-args function.

Prelude ...> let superdot = \f g x y -> f (g x) (g y)
Prelude ...> superdot compare snd (0, 1) (1, 0)

Why such a function isn't in Prelude?


Haskell Quiz

This entry was moved to NISHIO Hirokazu's blog


Haskell's random

Hi, it is NISHIO Hirokazu, Haskell newbie. Today I post a small code. It's not a bug. It's a feature of Haskell.

$ ghci
GHCi, version 6.8.3
Prelude> import Random
Prelude Random> let g = mkStdGen 1
Prelude Random> (fst (random g)) + 0
Prelude Random> (fst (random g)) / 1
Prelude Random> (fst (random g)) * 1
Prelude Random> (fst (random g)) * 1.0

Yes, it is a feature. Haskell's random changes its behavior by what type inferred. See The Haskell 98 Library Report: Random Numbers.



What The Fuck --- Twitter Trending from Japan('BEAT CRUSADERSが' and 'のTwitter廃人度は')

Hi, this is takano32.

Today's Twitter Trending in Worldwide is such as picture.

Many people are saying "What The Fuck? 'BEAT CRUSADERSが' and 'のTwitter廃人度は'".

There two words are Trendings from Japan.

'BEAT CRUSADERS' is rock band and they are active in Japan.
Today, BEAT CRUSADERS is publishing their breakup at official Web site.
And many Japanese shout "BEAT CRUSADERSが解散!?" in Twitter.
This means "Is it really breakup of BEAT CRUSADERS!?".

'Twitter廃人度' means how junky for Twitter.
A Web service telling fortune is a one of the most hot twitter service in Japan.
Today's trending fotune-telling Web service is Twitter廃人度チェッカー --- Check how are you junky for Twitter.
Many Japanese are check themselves and tweet their results in Twitter and make Twitter Trending 'のTwitter廃人度は'.

Many Japanese are affected by trend easily and a number of Japanese Twitter user is increasing.
So a number of trending words in Japanese may increase in the future.

Thank you.


Another Demo movie of "Muroto for iPad"

This entry was moved to NISHIO Hirokazu's blog


FIX: ImportError: cannot import name ImmutableList

Hi, it is NISHIO Hirokazu. I'm moving my Django app into Google App Engine with Django-nonrel. I encountered the error and it took a lot of time from me. Google search didn't know anything about the problem.

The version of Django in Google App Engine is 1.0. Thus that of Django-nonrel(djangoappengine) is 1.2. It is the root of the problem.

Of cource, some code to avoid such a versioning problem was wrote in Django-nonrel. See djangoappengine/main/main.py

parent_dir = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
f parent_dir not in sys.path:
sys.path.insert(0, parent_dir)

# Remove the standard version of Django
if 'django' in sys.modules and sys.modules['django'].VERSION < (1, 2):
for k in [k for k in sys.modules
if k.startswith('django\.') or k == 'django']:
del sys.modules[k]

If sys.path doesn't have the path to Django in Django-nonrel, it add the path. If already old Django was imported, it remove that. But unfortunately, in my case, sys.path has the path, and the path to Django in Google App Engine preceded, but it's not imported yet.

It's mystery. I can't tell why it happened. But it actually happened.

I wrote a workaround for the problem. It bring the path to correct Django always on top.

parent_dir = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
if parent_dir in sys.path:
sys.path.insert(0, parent_dir)

FIX: DatabaseError: Non-nullable field id can't be None!

Hi, it is NISHIO Hirokazu. I'm moving my Django app into Google App Engine with Django-nonrel. I encountered the error and it took a lot of time from me. Google search didn't know anything about the problem.


I want to add "oldid" field to keep relation information between models. Unfortunately "User" models are not mine, just be imported from django.auth, so I inherit it to add the field. It was the root of evil.

I hope it helps you :)




Hi, this is takano32.


Today's topic is "home-less", this is Japanese English and it means "Homelessness".

Ueno is one of the most famous home-less city in Japan.
And many other cities are having many home-less near by railway station.

The photo in this article is taken at Shibuya in Japan.
But Shibuya is famous by having many teenagers.

Here in Shibuya have many teenagers and also having many home-lesses.
It's very interesting Japanese city has many faces on each aspects.


ruin(破滅) lounge @ Shibuya

Ruin Lounge is a new style of gallery.

I'm a Ruin Lounge member.

There are many computers.

Geeks are making visual processing software every day,

So that the visual effects will become more and more cool.



How I fixed TemplateNotFound error

Hi, it is NISHIO Hirokazu! Yesterday I deployed my brand-new application with kay-framework, but it doesn't work. It said TemplateNotFound occured. It worked on my local server.

It came from very simple mistake! I used Deploy button on my GoogleAppEngineLauncher. It run "appcfg.py update" directly. However, we should not use "appcfg.py update" directly. Use "manage.py appcfg update".

Jinja2 (used in Kay) pre-parse templates and compile them to python codes. You can do it to run "manage.py preparse_apps". And when you do "manage.py appcfg update", it also do preparsing. Unfortunately I did "appcfg.py update" so the lack of preparsing phase caused TemplateNotFound.


Japanese Food "OYA-KO-DON"

Originally uploaded by takano32
Hi, this is takano32.

Today, i introduced one of the most popular japanese food called "OYA-KO-DON".

"OYA" means "parent" and "KO" means child, and then "OYA" means meat of chicken and "KO" means crash eggs in this case.

"DON" stands for "DONBURI", means a cup of rice and other foods. in this case "OYA-KO" is other foods.

Yesterday, i ate "OYA-KO-DON" and my friends were feeling very happy for having "OYA-KO-DON"!

Thank you.



A Quiz like an IQ test

This entry was moved to NISHIO Hirokazu's blog


Can you say what this graphics is?

This entry was moved to NISHIO Hirokazu's blog