2010-11-30

What is 4277075694

This entry was moved to NISHIO Hirokazu's blog

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

2010-07-12

Haskell Quiz Answer

This entry was moved to NISHIO Hirokazu's blog

2010-07-02

Real Point-free Haskell Program

This entry was moved to NISHIO Hirokazu's blog

2010-06-30

superdot


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


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


Why such a function isn't in Prelude?

2010-06-22

Haskell Quiz

This entry was moved to NISHIO Hirokazu's blog

2010-06-09

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
-604496784
Prelude Random> (fst (random g)) / 1
0.35925462466181596
Prelude Random> (fst (random g)) * 1
-604496784
Prelude Random> (fst (random g)) * 1.0
0.35925462466181596


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

2010-06-07

2010-06-06

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.

2010-05-31

Another Demo movie of "Muroto for iPad"

This entry was moved to NISHIO Hirokazu's blog

2010-05-27

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.remove(parent_dir)
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.

Keep in mind: DON'T INHERIT DJANGO MODELS!

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

2010-05-26

2010-05-22

home-less

Hi, this is takano32.

R0025618

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.

2010-05-17

ruin(破滅) lounge @ Shibuya

Ruin Lounge is a new style of gallery.

I'm a Ruin Lounge member.
http://chaosxlounge.com/artist.html

There are many computers.

Geeks are making visual processing software every day,

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





2010-05-13

2010-04-16

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.

2010-03-12

Japanese Food "OYA-KO-DON"


R0022988
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.


R0022991

2010-02-08

A Quiz like an IQ test

This entry was moved to NISHIO Hirokazu's blog

2010-01-06

Can you say what this graphics is?

This entry was moved to NISHIO Hirokazu's blog