Blogs

C++11 std::thread and exceptions

As many of your may be aware, C++11 now offers capabilities related to multi-threading applications. They offer multiple schemes, async and thread.

I would think that async is safe, from what I have seen, but std::thread is not.

Before you call one of your thread object destructor, you must make sure it was stopped. There is a list of the states the thread needs to be in so it does not terminate your process calling a destructor:

  • it was default-constructed (i.e. no thread was actually started,) as in:
void main()
{
   std::thread default_constructed;
   // ...

Another reason why printf() is better than std::cout

As I am working on a client / server system, I was printing out some info to see where I was getting stuck and noticed that all the messages got mangled really bad.

I was using statements such as:

std::cerr << "got message: "
          << message_name << "\n";

The problem with the implementation of cerr is that it actually prints each part one by one. This means the console gets locked and unlocked many times (which is slow!) and another process may write in between each one of your message chunk.

This is where a printf() is better since it creates ...

Spelling in English, why is that strange to a French speaker?

I have noticed that when someone spells in English to a youngster (and therefore slowly), they are likely to spell words and cut them at what I consider strange places.

A word such as constitution is spelled the way I would also expect it to be spelled:

con • sti • tu • tion

That is exactly the way we would break up the word in French.

However, a word such as acknowledge is spelled breaking up the word as in:

ac • knowl • edge

This is how the words are broken up by syllables in English dictionaries... It certainly makes sense to a grown up who has seen the words ...

Superb Comment About Security on Apple Forum...

So, I was wondering how to get the MAC address on an iPad 6. When you first get the device, you HAVE to set it up. That means adding the necessary info for a connection. Up to here, you'd think, not too bad... only you have NO WAY to get the MAC address of the iPad until the connection is setup. Ain't that practical?

Thus I searched using Google and found the best answer ever from a person on the Apple Forum (I do not assume that it is an Apple employee, it may be anyone, obviously...)

There it is:

You do not need to input the MAC ...

Why would I want to use a static variable in a function in C++?

As I am working on a web application, I'm faced with a problem which is to at least most of the time, attempt to avoid accessing the database. This means reading certain data once and keep it in memory forever (until the process dies at which time the data can be lost, obviously, this is done the Unix way: process runs to generate the results and dies immediately once the result was produced.)

So, my general idea is to create a field in my C++ class and if necessary have a flag to know that the field was defined (i.e. some fields may remain the same even after we read the data so the ...

Logic and Speed on Computers

As I am working on a complex system that is in need of optimization, I look at the existing code and try to come up with changes that should make the code go faster.

So... today I noticed that I was doing a lot of string compare in this way:

if(path.startsWith("m2osw/redirect/"))
{
  if(path == "m2osw/redirect/permissions"))
  {
    // do something about m2osw/redirect/permissions
  }
  else if(path == "m2osw/redirect/journal"))
  {
    // do something about m2osw/redirect/journal
  }
}

Up to here, nothing strange and looking at the logic, this ...

Google is Full of Contradictions

Why is Search Engine Optimization (SEO) so complicated?

Of course, some people may tell you it's not. They are probably working on it daily, that's what a pro is. It's just in its veins and thus easy.

Okay, so, what's complicated?

First of all, things change. Probably a lot faster than you realize. That is, every single month, some parameters will be slightly different and make the same searches return different results. Or not. Because a user who's logged in is likely to see the same results he's got for a very similar or exactly the same search, especially when ...

ASCII Art Pony

Isn't that cool?

I just find it really facinating that some people have an eye to draw anything with anything (in this case, a little pony with wings using just ASCII characters.)

Have you ever tried to come up with a draw of your own that would look as good as this one?

      ,;;*;;;;,
     .-'``;-');;.
    /'  .-.  /*;;
  .'    \d    \;;               .;;;,
 / o      `    \;    ,__.     ,;*;;;*;,
 \__, _.__,'   \_.-') __)--.;;;;;*;;;;,
  `""`;;;\       /-')_) __)  `\' ';;;;;;
     ;*;;;        -') `)_)  |\ |  ;;;;*;
     ...

Browser Security: Passwords are not protected at all...

Firebug to the rescue

As a developer, I use tools that allow me to find out whether my code works as expected. This tool, Firebug, allows me, among other things, to look at a browser DOM and the content of all the variables.

Log In Page Safe!

The other day I went to a page that asks for your log in name and password. The page looks proper and the password, as expected, is hidden from praying eye while you type it. In other words, it shows bullet points for each character that you type. Perfect.

Phone Call Distraction

Now... imagine that I start typing my user name and my password, then ...

Learning more about convert from ImageMagick

As I often scan documents that in the end I want to get in Black & White and cropped, I decided to look at the capabilities of the convert command line tool so I wouldn't have to manually change those images.

With the Gimp I can load the image, crop it to only what I want to keep, then convert the page to black and white. However, to get a valid black and white image, you want to first apply a filter that looks like this:

Filter to prepare image for monochrome conversion.

This is done using the following convert command line option:

-level 55%,71%,1.0

This tells the convert tool to change all colors that have a level of 55% or ...