Category Archives: Coding

The iPad as a High-Latency Second Monitor with Air Display

At work, I’ve been experimenting with standing while coding. ?I do find it far more effective than the alternative, and as an added side-bonus, I don’t feel crippling exhaustion when I get home. ?Unfortunately, the effect of the loss of a second monitor is quite pronounced. ?Whereas I could previously keep information split between two monitors with ease, I am forced to resort to Expose or the Gnome equivalent. ?Not good.

My use of two displays is generally as follows.

Display #1 – Actual work being done.

Display #2 – Information about models / classes / etc… that I don’t get automatically from my text editor (Sublime Text 2)

The iPad through Air Display sucks for #1; the lag is real and irritating. ?For #2, however, it shines. ?I have it open to the appropriate page right now, and it probably helped me shave about 15-30 minutes of research off my daily routine.

Considering how rarely I want to change the content on screen #2, I wonder if using an e-ink screen could be plausible in the near future…

Django Views As Classes with Python’s __call__ Magic Method

I have been using Django off-and-on for about 2 years now. I am really liking the direction, but what bugged me (for the longest time) is the re-usability of the view section.

For those unfamiliar with Django views, they are not strictly “MVC” views. If anything, they act more like controllers, and I treat them as such. It should be a piece of cake to reuse code between these, but usually what happened was that I would define a bunch of private view functions and have them referenced by various view functions. It wasn’t exactly the shining pinnacle of my development career.

While reading the code for django-jqchat while working on a project for my client, I rediscovered the python __call__ magic method. This basically permits you to call an instance of an object like a function. With a little effort, I managed to re-organize the code to make it a little more easy to parse. This is not complete and not debugged, but maybe you will find it useful.

Github Gist Link

Force Multipliers and Japanese Programmers

日本語で説明ポスト

Yesterday, over coffee, “R” and I traded stories about Akiba, board games and business. However, the main thing that we wound up talking about was programming, or more exactly, why Japanese companies produce lots of code and little progress. To make a long story short, I’ve come to believe it is a failure of management. A failure to facilitate coding through the use of frameworks that amplify work output.

I mentioned the usual generalizations (Japanese aren’t good coders, the Japanese work environment involves a lot of talking and little doing), but “R” mentioned how he worked in a company where they produced a lot of good code and the project managers took care of the insufferable 3 hour meetings – and to be fair, I have too. So why the problem?

The first clue to us both started with frameworks. “R” spent weeks at one company trying to add table joins to a system which simply had nothing of the kind built-in. This reminded me of similar headaches while spending an year of my own time developing Pinki and only having a small search/listing website by the end.

The big clue to me was Fujitsu – and how they constantly had dozens of systems programmers working on Symbian and other tinpot mobile OSes for each of their feature phones. Particularly with feature phones, there was very little difference between handsets, but programmers had to spend obscene amounts of time doing low-level programming to enable old software to run on new hardware. It was rare for me to see anyone going home before the last train. (These were some of the best programmers in Japan, and they had families – even the “overtime bonus” was not reason enough to stay. )

What all these examples have in common is how companies and people brazenly avoid using programming force multipliers. Fujitsu still uses the old/creaky Symbian OS to this day, even though it is a pain to develop for and has little support / community left (particularly in comparison to Android and Win7). I was stupid enough to try to build a website without a framework, and had to re-solve a half dozen problems. R’s former company had settled on some Japanese-language only ghetto framework even though it had no proper DB layer.

My hypothesis is that a lot of Japanese companies produce little new because they have people solving solved problems over and over again. This is probably because of their inability to assimilate newer frameworks with better communities that automatically solve many of these problems for them.

Maybe this is because the English language barrier. You have billions of English speakers and X% are good programmers. Even if 2X% of Japanese speakers were good programmers, you will never have the depth of talent needed to develop native Japanese language versions of computer languages & the community that goes with them. You are restricted to a subset of frameworks, good or bad, that you can explain to your Japanese unilingual boss. He probably is severely risk-averse and is too old to be familiar with current programming technologies and shortcuts. How do you get him to let you program in Python/Django when he is still using Excel as a datastore (a shockingly common issue in Japan!)

I hear the weeaboos across the world now screaming “what about Ruby!”, but Ruby just proves the point. A Mormon Japanese dude (read: English literate, world-focused, non-Otaku, non-loner mindset) coupled with an excellent framework that gained fame world-wide (Rails). It’s nice that there are great Japanese Rubyists but they are not responsible for the popularity of the language.

There are alternative explanations – no money for advanced training, corporate mandates from backroom deals, fear of open source software, incorrect initial assumptions (IE: Japan is the source of all sorts of world class code), but none of them resonate with me.

If I’m right, the solution isn’t that hard. Give the Japanese programmers proper force multipliers in the form of good frameworks and libraries. Give them good training so they aren’t dependent on Google translator-fu. You will see an improvement.

-edit-

This one post got about 10,000 hits through a kind link on Hacker News. You can follow the discussion there. I do not necessarily agree with everything, but it is all generally thought provoking.

-edit #2-

I’m… honoured to see that somehow this made its way to Slashdot Japan, and was translated into Japanese. どうぞよろしくおねがいします。

-edit #3-
みんなさん、ようこそ。 もし不明なところがあれば、是非日本語でコメントをしてください。

Solr, Django and Haystack – Problems with installing the schema onto a core (Core0)?

In short: Please be sure to have all your files in the proper directory. You can do this on a standard Ubuntu install by typing in:

cp /usr/share/tomcat6/solr/conf/*.txt /usr/share/tomcat6/solr/core0/conf/

[line]

I was setting up Solr on Haystack for a personal project of mine. Unfortunately, it was giving me a major headache – it would constantly give me this error message.

ERROR:haystack:Failed to add documents to Solr: [Reason: ERROR:unknown field 'django_id']

Doh – looks like I had forgotten to copy in the schema.xml file right?

./manage.py build_solr_schema > /usr/share/tomcat6/solr/core0/conf/schema.xml

However, this didn’t help.

Failed to add documents to Solr: [Reason: /solr/core0/update/]

Turns out core0 had vanished from the solr admin page. Furthermore, there was no error log to give me any hints. However, if I deleted all of the “text” fields, it seemed to work fine. Turns out, the text field parsers have certain text files associated with them that need to be in the core directory as well.

Duplicated Folder Names, Nginx, and the difference between Alias and Root

While this is something quite simple, I have run into this a lot online. The solution is actually quite simple, so I thought I’d point it out.

The problem: someone wants to serve a subdirectory. As a result, he sets up something like this:


location /download/ {
root /home/example.com/download/
}

He restarts Nginx. No problems. Unfortunately, when he tries to get something from the directory (http://example.com/download/file.zip for example), he can’t download it! Worse yet, when he looks at the error log, the result is puzzling.

open() "/home/example.com/download/download/files.zip" failed (2: No such file or directory)

WTF? Why is download duplicated in there?

Some people I’ve seenhave advocated the boneheaded idea of moving the file to the subdirectory and living with it, or even worse, setting the root to /home/example.com. The actual answer is to use the alias keyword in the config file.


location /download/ {
alias /home/example.com/download/
}

As you can guess, root doesn’t affect anything in the URI you pass. It uses /home/example.com/download as the ROOT for the website, and then appends the second “/download/” afterwards. Alias strips off the /download/, leaving you with the remaining file path you needed to get the file.

If you have had this problem, read the Nginx docs! They aren’t too hard. (God knows, I should be reading them more.)