Make a RAM disk on Mac OS X 1.5 or later

Create the RAM disk:

diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://1165430`

(the magic number 1165430 is explained here as the number of 512 byte sectors. The string “ramdisk” is just the name of the disk, which will appear under /Volumes after creation)

Write some stuff to the RAM disk:

echo "hello RAM disk" > /Volumes/ramdisk/hello.txt

Eject the RAM disk:

diskutil eject /Volumes/ramdisk

Gathered from here and here so that I remember for later.

On Linux

Found this guide for creating a RAM disk on Linux, but have not tried it yet.

Calling a Python LP-solver from a PostgreSQL function

Prepare the database by installing PL/Python and a function:

AS $$
  import subprocess
  output = subprocess.Popen (
    stdout = subprocess.PIPE, 
    stderr = subprocess.STDOUT
  # Parse string OF comma-separated floats
  RETURN map(lambda x: FLOAT(x), output.split(","))
$$ LANGUAGE plpythonu;

Install LP-solver (cvxopt):

pip install cvxopt

External Python script (save as /usr/local/trystuff/

from cvxopt import matrix, solvers
solvers.options['show_progress'] = False
A = matrix([ [-1.0, -1.0, 0.0, 1.0], [1.0, -1.0, -1.0, -2.0] ])
b = matrix([ 1.0, -2.0, 0.0, 4.0 ])
c = matrix([ 2.0, 1.0 ])
# Print string of comma-separated floats
print ",".join([str(x) for x in sol['x']])

Try it:

SELECT unnest(hello_lp());

Introducing the Web Co-Processor

Here is a project I’m working on called the Web Co-Processor (credit for name goes to Marcos Vaz Salles). There is a demo you can try if you clone the project.

Read the following four bullets and you’ll understand what the web co-processor is about:

  1. A person opens a webpage in his browser
  2. The webpage has a small javascript code that opens a two-way connection between the browser and the server using a websocket
  3. The persons browser is now a core in the web co-processor
  4. A core can execute javascript on behalf of other web cores (or the server), and store transient data

If you are thinking botnet, you are forgiven. The idea is similar, but the intent different. Although I came up with the idea independently, I have found out that other people have thought about similar ideas before.

I’m serious about this idea. I think the idea of massive numbers of transient cores and memory offer some very interesting challenges. I’m keeping a lid on the ideas I have for the web co-processor, but you can follow my github repostitory to get updates as stuff happens. Action is expected to be sporadic but relatively intense.

Feel free to clone

git clone

Sequential writes leveldb versus system_x

OK, calling it a benchmark is a bit of an overstatement. It’s taking two different database libraries for a quick spin, and seeing how fast they can write a bunch of integers to disk. A second benchmark checks how fast we can read them.

In this mini-test, I’m running leveldb against a new embedded database library, let’s call it system_x. The purpose is really just so that I can remember some rough numbers regarding these useful database libraries.

I used the time command to gather results, which shows real, user and sys time spent.

Continue reading “Sequential writes leveldb versus system_x”

A presentation on spatial indexing

A friend of mine, who is the CEO of a company that develops an embedded database, asked me to do a presentation on spatial indexing. This was an opportunity for me to brush up on R-trees and similar datastructures.

Download the slides

The presentation introduces R-trees and spatial indexing to a technical audience, who are however not spatial indexing experts.