Friday, May 31, 2019

NodeJS HTTP Server Timeout

In Nodejs an HTTP server created by http.createServer() has a default timout of 2 minutes (12000ms). I have an HTML client that calls the server through a GET request and the server starts a batch file that takes more than 5 minutes to finish. After two minutes, the server hits the timout and does some sort of restart (I guess), calls the batch file again and this continues ad infinitum, none of the client GET requests getting a return!

Solution: server.setTimeout(0); //disables timeout

Build Visual C++ Project from Command Line

Previously I showed how to build a couple of files from command line. To build a whole Visual C++ project from command line, I tried msbuild. However, I had no luck with it because I got "error TRK0002: Failed to execute command...". Then I used devenv and it worked perfectly. The following batch script did the job from a normal command line:

@DevEnvDir="c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\"
@set PATH=%DevEnvDir%;%PATH%
@cd c:\temp\DeleteMe
@call devenv DeleteMe.sln /build "Release|x86"

Saturday, May 25, 2019

The secret to happiness

I have finally discovered the secret to happiness and I would like to share it with you [drumroll...]: It is doing the simple things every day! That doesn't sound very inspiring, does it? People expect some heroics that they have to do only a few times and then become fit, successful, effective, i.e. most of the prerequisites for a happy life. And they like explanations like genius and luck because it absolves them of guilt. Examples of simple things resulting in huge benefits in the long run:
If you are among the 90% who say that they don't have time, my answer is that your priorities are not right. What could possibly be better than investing in your health and child? Watching movies?

I once had a conversation with an uncle, about 65 years old. He said that he would give everything he had to be 20 years younger. He was in good health for his age. I asked him "uncle, 20 years from now, you will say the same thing again. Do you live your life in a way that someone would give his everything for?" My uncle kept silent...

Interestingly, when you tell others about learning how to fish, instead of having been handed a fish, they all nod in agreement. In reality, they want the fish! Recently I was chatting with my aunt, whose daughter plans to study abroad. I was giving advice about what to do. My aunt got impatient and said "Şamil, don't tell us what to do, do it for us". I became indignant and replied "if it was possible, you would be happy if I entered the university exam in her place, wouldn't you?!" She sheepishly said yes.

Seeing how difficult this simple action is for most, I became more motivated to instill perseverance in my child. And as you know, the only way to teach a child anything is to do it yourself and be an example first.

Saturday, May 11, 2019

Dünya'nın en güzel şarkısı

Deniz Tekin'in yorumuyla "Sezenler olmuş" şarkısını Dünya'nın en güzel şarkısı, güftesini de Dünya'nın en güzel şiiri ilan ediyorum. Şiirin birinci ve ikinci kısmındaki simetriye dikkat: Birinci kısımda "sen bendesin", ikinci kısımda "ben sendeyim"...



Bunu seven şunu da sevdi: Seni Kendime Sakladım - Duman (Oğulcan Başarı & Evrencan Gündüz)

Matlab: Save workspace to text file

In Matlab you can easily save workspace to a mat file. If you want to write workspace variables to a text file:

Friday, May 10, 2019

Letters to a novice programmer

Novice programmers create a lot of garbage code. Recently I refactored the code of a novice and reduced it by more than 10 times (360KB --> 30KB)! The most important rule for a novice would be to express the solution to a problem in as little code as possible. He should always ask himself "do I really need to write this line of code, can I combine those repeating sections to make it a function". All that code has to be debugged, reviewed, tested and maintained by yours truly.

Dear novice, treat code as something smelly and ugly, which is especially true for the code you produce and try to minimize it, remember how perfection is achieved. It is not your fault. If you follow my advice, you will soon become much better.

Thursday, May 09, 2019

Visual C++ DLL

When coding a C++ project that uses an existing dll, you also need to have the lib file to be able to build your project. Once you have built your project and created your exe, you only need the dll, not the lib.

Bonus: stringstream is slow, char* is faster.

Friday, May 03, 2019

The most important characteristics of an entrepreneur

I have worked with different types of entrepreneurs over the years and came to the conclusion that the most important characteristics of an entrepreneur is to have high energy and low pride. By low pride I mean not being offended easily. Average intelligence is enough until you want to exceed the 100M$ mark. In terms of monetary value:
  • High Energy + Low pride = 100M$
  • Medium Energy + Medium pride = 10M$
  • Low Energy + Low pride = You shouldn't be an entrepreneur
  • High Energy + High pride = You shouldn't be an entrepreneur
  • High Energy + Low pride + High intelligence = No upper limit to the wealth you can create