Have fun with post build events

It’s important to have some fun in the project you work on. It helps in releasing some stress. Our project goes through a stressful phase now. Deadlines are getting closer and some of our arguments get more heated then they should. It would be a good idea that we go out for some beers but we work in different cities so it’s not that easy. After a meeting like I mentioned, a colleague and me thought it would be nice to play a little trick on another colleague. I took up the challenge and I promised I would think of something.

I figured, let’s me mess with him in a harmless but funny manner. My first thought was to implement some kind of Easter egg, but I didn’t wanted to affect the code. Our current client might not enjoy it as much as I would hope. So I had to think of something that only applies to him and not the code, so this is what I ended up doing.

for /f %%i in ('whoami') do (
IF "%%i" == “DOMAIN\user" (
IF %RANDOM% LEQ 12000 (
start chrome "https://youtu.be/_4IRMYuE1hI"
)))

These are a few simple CMD commands that you can place in the post build event for any Visual Studio project (other editors probably have a similar feature). You can collapse it to one line, I have it like this just to show you better what it does.

I wanted the trick to apply only to him without people around him knowing. The first command requests the currently logged in users name from the system. The second if checks the returned username and compares it to the targeted user. I wanted it to execute only roughly 33% of the time so I achieve that by rolling a random number between 0 and 32768. That is what the third check achieves. If these two conditions are met, I start chrome on a specific link: Beethoven’s 5th symphony. It is harmless, but I’m sure you can think of something darker, if you wish to do so.

This code will reach the server next week. I’ll keep you posted of its effect. Stay tuned!

Posted in Fun

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!