The Mandelbrot Set in WPF

I am fascinated about the Mandelbrot set, since I first saw a video about it at my university. It is so elegant, so beautiful but the cherry on the cake it is that it’s infinitely complex. Throughout my years I implemented the rendering many times. Every time somebody says Math is boring, I flip out my phone to prove them wrong with some images. You can read a lot more about it here.

In WPF there are three main ways to do rendering.

  1. Control composition: You assemble your hierarchy of UI elements (from XAML or code) and you let the engine take care of layouting and rendering for you. Great if you want a lot of user interaction.
  2. Drawing Context:  You use primitives like Lines, Rectangles, Pens and Brushes and you do most of the positioning yourself. It is the basically the GDI rendering from WinForms and involves overriding the OnPaint() method. Great choice when you want to create from scratch a control like a chart.
  3. Image generation: You define the color of each pixel on a surface. This is how game engines do rendering. Great choice when you want to create Heat Maps or Image manipulation

I created a simple WPF application that renders the Mandelbrot Set into a WriteableBitmap.

Continue reading

Cleaning hacked WordPress sites

A few days ago a dear friend of mine asked me to take a look at their website. According to them the guy who was administrating it didn’t had much security knowledge so they got hacked. I needed to assess the damage and tell them if it can be recovered or not. My first thought was that “great another university student after which I need to clean up shit” but the story got really interesting for me. The site was hosted on WordPress, exactly like my blog. I instantly got interested since I had the impression that there is not much you can fuck up in it. I’m new to WordPress so my incentive was to learn how can one you end up hacked and more important how can you restore your work.

Initial assessment

I opened the page in chrome and the dev tools to check network activity. The site was loading some shady javascript in the form of <script src=’[shady source]’ type=’text/javascript’></script> and its initial load took more than 40 seconds.

Great, some hacker sprayed every page with bullshit, no wonder the site loads slowly. So it was clear we need to do some cleanup. I requested access to their admin page and after I logged in I started to look around weird stuff. The option that everybody can registered was checked and there were two users registered with shady names so I deleted them. The site wasn’t big so I pulled up my sleeves and wanted to go mopping up but even the editor was slow (40 seconds slow).

I’ve checked page revisions and it was clear when the malicious parts were added in, but I didn’t had the possibility to revert to a backup since they were editing it after the slowdown (which later you will understand why).

Continue reading

Try a leaner code review process

What are code reviews?

Code review is a very common and important process throughout development phase where code developed by individuals gets peer reviews in order to improve the overall quality of the source code.

Is there a problem with this practice?

Not per se, I’ve seen it poorly implemented too many times. Close your eyes and imagine you are sitting in a kickoff meeting and you hear something along this line. Usually from a very eager, but inexperienced team leader.

“I would like that every line of code to be reviewed by the entire team. Everybody makes mistakes, even senior developers do, and even junior developers can have valuable feedback, so everybody should participate in reviewing.”

Don’t get me wrong, I like this way of thinking. It comes from a very noble place. Unfortunately when put in practice with a mid-size team, you will see some shortcomings surface.

Continue reading

SOLID Principles – In conclusion

This series certainly was a challenge to write however it was a lot of fun. But before we say good by to it, i would like to leave you with some thoughts.

In my first 5 years of software development I worked at a company with a few colleagues from the university where I studied. We didn’t had anybody around who could teach us what to do and what not to do. When I changed the company I worked for I considered myself to be in a great disadvantage but it turned out to be very beneficial for me. I made all the mistakes a developer can make, I saw how my own code can turn against me, and become my own nightmare after a year or two.

Because of this, when i first read these principles it was easy to reflect on what situation I could have avoided if I knew better, so I started to adopt them instantly. In a weird way, i feel lucky about my initial years. What i also learned that the success of a project doesn’t hang as much on immaculate code as i thought initially.

I know these days, these principles are thought at the university and even on internships. Since they are hard to understand and even harder to put in practice, they can cause a lot of frustration for people early in their careers. I advise you to have patience with yourself.

Don’t expect that you will understand them just by reading about them. You cannot understand boxing advice from a book. They will make more sense once you spend a few rounds in the ring, especially after you get punched in the face a few times.

I also advise you to study more from different sources, eventually you will find some explanations that will make sense to you. Also don’t run directly to your technical lead when you face a dilemma. Try out your ideas, see where they lead, draw some conclusions and undo all if necessary.

So hang in there and try to respect these principles as much as you can. See you soon!

SOLID Principles – Dependency Inversion Principle


one should “depend upon abstractions, [not] concretions.”

Dependencies are practically anything that your class controls trough another class. For example if you need to manipulate a file, you will do this through a class which is exposed by the framework you are using. Here are a few common dependencies: Database, Network, File System, System information, Time, Printing, Mailing, Timers, External Hardware, External Services, etc.

Building upon the examples we discussed so far in this series, let’s add the following requirement. Our client wants to vary the percentage of discount given based on the quantity. Since he wants to modify this later for each warehouse he requested us to read this data from a CSV file.

In other words, our class needs to process some information. That information is currently stored in a file called “C:\abc.csv”. My first instinct is to open a files stream, read the information and then process it. Remembering what we learned so far we correctly identify that, fetching the data is a different responsibility then processing it, and we learned we should have only one. It is clear we need to separate these two, so we come up with something that looks like this.

Continue reading