Wishful Coding

Didn't you ever wish your
computer understood you?

This is How I Want to Write Markdown

Most websites us a split-pane approach to Markdown editing. You enter your text in one field, and the resulting HTML appears in another.

I think this is silly UI, and would like to see websites adopt the iA Writer approach to Markdown editing.

Sadly, I don’t know of any library or parser that lets you do this, so I started writing one.

This thing is currently easier to break than to use, partially because my approach is broken, partially because the content editable API is broken, and partially because it’s just a one-day hack.

Attending Hacker School

As a male without $6000 in savings.

Hacker School is awesome, so if you enjoy coding, you should apply, but what really prompted me to write this post is that someone on Reddit or HN said giving grants only to woman is unfair to men who need it.

While I do think it’d be good to have more gender balance in programming, giving grants based on need only to woman seemed unfair to me too. After three months of Hacker School, there are 2 things that altered my opinion on the matter.

First-hand stories of all the crazy little subtle male culture bias. There is no way I can second-hand this to male readers, but let me say there is a lot more to it than just getting the job and getting promotion.

“Affirmative action.” Discrimination is a big part of American culture. If you think giving grants to woman is discriminative to man, you would be completely right.

But it’s okay, because woman are a minority. Affirmative action is a very normal and accepted thing over here, and it’s just that, discrimination in favor of the minority.

I still managed to make it

New York is both more expensive and cheaper than you can possibly imagine.

If I would have rented a decent room and ate out like everyone else, I would not have been able to do this from my savings. But the thing is, you don’t have to do all that.

The first thing to do is to contact all your relatives in and around New York. I’m basically staying here for free in exchange for some help with AERO on my free days. I do have a long commute, but I have a Kindle and a Gameboy with Pokemon.

My friend Six has taken an alternative route, and is just crashing on couches and roofs, with Couchsurfing as a backup. With a lot alumni living in the city, and a dangling fire escape here and there1, this is perfectly doable. However, it might be less pleasant in the Fall batch.

A good lunch can easily cost you $10, but it doesn’t have to. You can buy bread, there is a fridge, microwave and hot plate2, use them. Me and Six had a lot of cheap and delicious meals that way.

I hope that helps.

  1. WARING ERROR WARNING WARNING don’t do that, unless you want to get in trouble. Alumni roofs are okay though. 

  2. Well, there was, until something started to smell. I’m convinced that’s the trash/fridge though, not my hot plate ;) 

The Multiple Index Problem

I would like to name this problem in functional programming. There has been some talk aout how Clojure solves the Expression Problem, but th Multiple Index Problem has deserved so little attention it doesn’t even have a name.

A simple example of multiple indices can be seen in relational databases, where you can querry a table like SELECT * FROM foo WHERE id=1 but you can add an index to the table and querry on other fields like SELECT * FROM foo WHERE name="Pepijn".

If you would translate this to hash maps, in imperative languages, you could do the following

>>> val1 = []
>>> val2 = []
>>> index1 = {1:val1, 5:val2}
>>> index2 = {"pepijn":val1, "ben":val2}
>>> index2["pepijn"].append("foo")
>>> index1[1]
['foo']

If you want to do this in a functional language, you’re out of luck. In the most basic case, you’d have to add some indirection.

user=> (def index [[], []])
#'user/index
user=> (def index1 {1 0, 5 1})
#'user/index1
user=> (def index2 {"pepijn" 0, "ben" 1})
#'user/index2
user=> (def new-index (update-in index [(get index2 "pepijn")] conj "foo"))
#'user/new-index
user=> (get new-index (get index1 1))
["foo"]

Next up, I’ll show 2 cases where this is a real pain, rather than just anoying.

Dijkstras Algorithm

Dijkstras algorithm is used to find the shortest path in a graph. It is fairly easy to implement using a vector, but also very slow.

Every itteration you need to find the closest unexplored node. With he flat list, you need to walk them all.

The way to solve this is to use a Fibonacci Heap, which has constant time and logarithmic time opperations for getting and decrementing the lowest key.

However, it has no methods for lookingg up other keys, other than… walking the tree? The way this is done in imparative languages is to just have pointers to the nodes, but in a functional language, youre stuck walking the tree.

This defeats the whole purpose of using a Fibonacci Heap. Is it at all possible to implement Dijkstra in a pure functional way in an optiomal time complexity?

I ended up using a mutable heap and just not decrementing keys. Yuk!

You can see the code me and Mary wrote at Hacker School at her github(fibbonaccy and flat array), and mine(Using PriorityBlockingQueue)

Collision Detection

I struggled with the same problem in my Clojure game engine, before I realised this was a repeating pattern.

So I started out modeling my world as a list of objects, but quickly found that the bat needed to know where the ball was, so I turned the world into a hash map of IDs to objects, and all was good.

Until I needed to do collision detection on more than a dozen objects. If you just compare all objects to al others to see if they collide, you’re doing O(n2), which is no good.

Lukily there are datastructures that do spatial indexing. Indexing… see my problem?

I wrote a Quadtree in Clojure, but as soon as I stuck all my objects in the tree, there was no way to look them up by ID.

I think I ended up doing some black magic to sorted maps to have lookup by ID and okayish collision detection.

That is all I have to say about the problem. I don’t have a soltuion or a satisfying workaround. You can try adding intermediate indices, or introducing mutability, but it’s painfull.