Back to writing

So apparently my last blog post was from 2012. That’s quite a bit of time.

flytrex drone

Since then I’ve:

  • Had a son
  • Sold my startup Desti to HERE
  • Moved with my family to Boston
  • Moved back to Israel, join Cymmetria, first as VP R&D and later as CTO
  • Had another son
  • Left Cymmetria and joined Flytrex as VP R&D

It’s not a long list, but it covers a lot of ground. Right now, Corona virus notwithstanding, I’m pretty excited about the work we do at Flytrex: we’re building a system for food delivery via autonomous drones.

Here is a short video that shows what we’re working on:

The video is by now 11 months old and the system changed a lot since then, and our main challenge right now is getting this system working in the USA.

Learning from my experience, I want to start writing regularly. To achieve that, while I will write mostly about programming, I will also write about other areas of interest. Let’s see where this new adventure takes us. Onwards!

Personal Programming Python Testing

My Bad Memory, High Load, and Python

About a month ago the new Ubuntu 8.04 was released and I wanted a clean install. I downloaded an image and burned it to a CD. Just before installing, I tried “check CD for defects” and found a few. Turns out (*) this was because of bad memory – and memtest confirmed it.
So I went to the shop, replaced the bad memory, and also bought two new sticks. I went home to install the new Ubuntu, and after the installation, Firefox crashed. After rebooting back to memtest, I saw this:

memory errors in memtest

Back at the computer shop, they asked me to reproduce the errors. Just firing up the computer and booting directly into memtest didn’t seem to do the trick, so I suspected that I had to overwork my computer a bit to reproduce this.

Since I was at the lab, I didn’t want to muck around too much.
So I thought, “what’s the quickest way to give your CPU a run around the block?”
That’s right – a tight loop:

while True:

However, this snippet doesn’t really play with the memory.

The next simplest thing to do, that also jiggles some ram is the following (and one of my favorites):

In [1]: x = 4**(4**4)
In [2]: y = 4**x

I will talk about this peculiar piece of code at a later post.

In any case, this snippet also didn’t reproduce the error. It is also quite unwieldy, as it raises a MemoryError after some time. Later at home I tried two more scripts.
The first is a variation on the one above:

x = 4**(4**4)
while True:
        y = 4**x
    except MemoryError:

I ran a few of those in parallel. However, my Ubuntu machine actually killed the processes running this one by one.

The second is smarter. It allocates some memory and then just copies it around:

import sys
import copy
megabytes = int(sys.argv[1])
x1 = [["a"*1000 + str(i) for i in range(1000)] for j in range(megabytes)]
while True:
    x2 = copy.deepcopy(x1)

After both of these scripts didn’t reproduce the problem and it still persisted arbitrarily, I returned the computer to the lab. Turns out that the two replacement sticks and the two new sticks weren’t exactly identical, and that was the cause of the problem. So now my memory is well again.

As for the scripts above, I once wrote a similar script at work. I was asked to help with testing some software in some stress testing. The goal was to simulate a heavily used computer. A few lines of Python later and the testing environment was ready.

(*) – Finding out that it was a memory issue wasn’t as easy as it sounds. I didn’t think of running memtest. I checked the image on my HD with md5, and the hash didn’t match. I downloaded a second image, and again the hash didn’t match. I checked twice.
At this point I was really surprised: not only the second check didn’t match the published md5, it also didn’t match the first check. Some hours and plenty of voodoo later, a friend suggested running memtest, and the culprit was found.

Origami Personal

Exam is Done

A few hours ago, I had my exam in functional analysis. This should be the last exam for the semester.
Now I should have more time for my projects.

Currently on my radar: a startup, diStorm, and maybe a website. Of course, I expect the startup to eat a lot of my time. For now I’ll just have to see how it goes.

On another subject, I wanted to show instructions for the origrami lottery-spider. It turns out that this fold is modular in the sense that a piece of 1:n paper generates a critter with n+1 pairs of legs.
Here’s a proof of concept with a ratio of 1:8 (click for a larger version):

origami caterpillar

I’ll be making the instructions as soon as I get new batteries for my camera, and some spare time. (The caterpillar ate my batteries, along with my functional analysis books.)

Assembly Compilation computer science Personal Programming Python

Writing a Quad Interpreter

My compilation homework is writing a compiler from simplified CPL to Quad, a made up assembly language. The compiler was going well, and when it started to emit code, I naturally wanted to test it.

The problem is, I work on Ubuntu Linux, and the only available Quad interpreter was for Windows. Trying to run it with Wine didn’t work, and I gave up on it pretty quickly. I also didn’t want to start working on Windows. So I sat down for half an hour and wrote a Quad interpreter of my own, in Python.

Afterwards, I thought of publishing it, and sat down to write a step-by-step mode as well. I didn’t implement breakpoints, although it is quite easy.

The compiler is working now, although I do have to do the finish. Since it is a homework assignment, I will not be publishing it, but I will publish the Quad Interpreter. I hope it benefits you.

A note of caution though: I didn’t test it thoroughly . The most I did was running it with some toy programs and the output of my compiler to see if it works. It does, and that’s enough for me.

Humour Math Personal

Fibonacci meals

Lately I’ve been reminded of the existence of Fibonacci meals. For a long time, I despised those, but now that I’m preparing my own food most of the time, I’m aiming for them, to save time cooking.

A Fibonacci meal is an element of a sequence defined to be:

a(0) = some food
a(1) = some food
a(n) = a(n-1) + (a(n-2) as sauce)

Very simple, and very effective. You can find those in various places, such as camps, school cafeteria, etc…

Generally this sequence does not converge, however there is a special case for cakes and desserts:

c(0) = some cake or dessert
c(1) = some cake or dessert
c(n) = c(n-1) + (c(n-2) as icing)

This sequence does converge, to the chocolate ball. (in Wikipedia, Chokladboll).

Game Development Personal Programming Python web-design

Misc. Projects: a preview for the new (academical) year

So now it’s been too long since I’ve written a post, and that’s mostly because I haven’t been programming lately, as I’ve been busy with buying a car\moving\studying. This is going to change now that I’m finally settling in.

There are however few directions I’m going to go about, and I’d like to mention them here. If you are interested in reading more about any of them, just drop me a line in the comments, and that direction will get a bit more attention.

The first direction (and the most serious one) is a website I’m building. I’ll still not talk about the website itself, at least until a beta version is done, but I will say I’m doing it with TurboGears. I’ve always looked for a good Python framework for writing websites, and for now, TurboGears seems to do the trick, although I’m just starting with it. I am going to write a little bit about my experience with TurboGears, and my opinions. Stay tuned.

Another subject that I thought of writing about is a small tank game I wrote with pygame. This game actually works, although I didn’t do the finish. I intended to make it multi player (over the ‘net) but then found out that it is really not that simple. So I intend to work it out sometime in the future, and write about it. For now, I will say a few words about the game. It started when a friend of mine said that he wanted some simple tank game for one-on-one games, with some certain behaviors (such as bullets ricocheting off walls). I heard him talking about it, and told him, “hey, that’s really simple, I can do that”, so I went home, and during five days, one hour a day, I worked it out. That was an interesting experience in itself. Maybe I’ll write a little about that as well.

Other small projects I’ve been working on include doing some more IMDB mining (which I started to talk about), and maybe expanding that to as well. One thing I find missing in Amarok, is choosing music according to musical relations between singers and bands. Maybe I’ll even write a plugin :)

Some other ideas I had include 3d l-strings. I actually implemented those, but to my disappointment, they didn’t turn out as aesthetically pleasing as I’d hoped. Still, it was a curious result (with PyOpenGL doing the drawing). I wanted to implement more simple fractals. I’ll probably write more of those when I break from writing more serious projects. Other small ideas I had include more ascii-art, for example, ascii-art drawing of some vector image format seems very interesting, or maybe a 3d engine (maybe with cell-shading) which renders the result in ascii-art, and then writing an FPS with it… The options are endless!

All of this of course if I have the time when I’m not working on one of the other current projects, which include distorm, and my studies. Among the courses I’m taking there is a seminar on graph algorithms, a course in compilation and a course in cryptography.

This is going to be a very interesting year indeed!

Origami Personal

A new origami fold: Squirrel

Finally, got my computer hooked up to the ‘net, and I’m almost finished with moving. Yipee.

This fold was actually the first fold I did that had four limbs and actually resembled something. Although the proportions are not the best I still like this fold. It is not really complicated, and once you get the trick of the wings, you can get to it from the bird base quite easily. The same technique is also very useful for creating other four legged creatures (some of which I will also show).

A finished squirrel

(click on the image for folding instructions).

Personal Programming Python

Testing, 1 2 3, Testing

Finally, I’m after the test in complex functions. Not that it went as well as I wanted, but hey, you can’t have it all. Maybe gonna try again sometime later. In the meantime, I got this “today is the first day of the rest of your life” feeling. After finishing with my previous work, and the previous semester, I’m going to move to Haifa (with my girlfriend) in less than a month, start the next (and last) semester soon, and also start real work on some real projects (one of those being diStorm). Here’s to starting and ending things.

On the flipside, after finishing the test, I had some testing issues to work out. See – let’s say you got a piece of code you change. Well, the obvious thing to do is make sure it works. It is also good to find all the places that reference that piece of code, and make sure these are updated, and test those as well. It is even better if you also have some unit-testing code available (built using the easy-to-use unittest module). It’s even better if your test code actually checks the relevant pieces of code.

But alas, it can all fail due to human stupidity. In that particular instance, mine. After all this work, not running the damn unit-test code is just plain stupid. So, I hope I’ve learned my lesson. Again. Never commit untested code.

And while we are on the subject of testing, check out, over at Ned Batchelder’s place (I also happen to read and like his blog). Coverage is an excellent tool to improve your test code. Just run your test code with, likewise: -x

and then run: -r

and get some nice looking, informative results:

Name                                        Stmts   Exec  Cover
exptree                                        65     33    50%
exputils                                       85     48    56%
template_gen                                  100     67    67%
test_exputils                                  41     41   100%

Excellent. You can also get an annotated version of the source, telling you which line was run, and which wasn’t. It just doesn’t get anymore useful then that. So happy testing. I hope you fare better then me.