Author Archives: Nicolas Riousset

Wattpad API requests must contain a valid browser User-Agent header

Recently, I’ve been playing with the Wattpad API. I was interested in collecting stats about the most popular publications.
Wattpad_logo_svg
Even though the API is simple and well documented, all attempts to use it through a python script failed. Requests were rejected with a “403 Access forbidden” HTTP error. My first intuition was that the basic authentication was incorrectly specified, but despite the API samples, I couldn’t figure out what was wrong with it.

Using WireShark to sniff the API sample requests would have helped solving the issue, but since the API only supports https, sniffing wasn’t an option (I later realized that I could have simply disabled https, just to sniff the request, since I didn’t care about the response).

Eventually, the problem came from the User-Agent header. The python script used a default User-Agent, which was rejected by the Wattpad server. Impersonating a legitimate browser (ex : chrome) solved the issue, requests were immediately accepted.

Below is a Python sample.
Continue reading

How to execute the same SQL query on each database of a SQL Server instance ?

You want to execute the same SQL query on each database of your SQL Server. For example, because you have one database per customer and want to collect info about your customers’ databases version, size, etc.

The following T-SQL code illustrates how to get the number of tables in each database whose name starts with “RH”, and presents the result in one single recordset. Continue reading

When should you rewrite an application from scratch ?

Recently, I had to work on an old C++ builder 4 (1998) application. The IDE couldn’t be installed anymore on Windows 7, there were global variables and singletons everywhere, client-based compilation directives, no separation between UI, business logic and data layer, no class isolation, memory leaks all over the place, compiler failure as soon as the source code got too big, dependencies on obsolete COM objects, etc. A nightmare. It looked like the perfect example of an application that should be rewritten from scratch, and it made me wonder when is it a good time to completely rewrite a product ?

Short answer : Never.
Continue reading

Which command line parser for C++ apps ?

If you need to parse command line arguments in C++, don’t reinvent the wheel, use an existing library. That’s the kind of problem that seems so simple that it’s obvious you’ll quickly hack it. Then you face parsing bugs, spaces within parameters, special characters, optional parameters, config files, etc. Eventually you’ll switch to a library, so save time and do it from the beginning.

Many libraries are available out there for C++ applications, I’ll focus on two of them : Boost.Program_options and GetPot. Continue reading