The empty member optimization

To understand the optimization, we need to understand what the empty member bloat is. Consider a class defined as:

class Foo
{
};

The C++ standard says that the objects of the above class should be uniquely identifiable. Even an class with no member variables would occupy 4~8bytes based on the platform due to byte alignment. A good example of empty classes are allocators or functors that does not have member data. I wont steal the thunder from this paper.


PixelPost, Flickr and everything else

At least, as a computer science engineer, I tend to think that ‘everything should just work‘ and ‘Hmm, it is so simple that why hasn’t someone thought of it before’. Most of the time it’s about google-ing skills and knowing where and what to look for. Anyway, this post it not about that. Here’s what I wanted to do and found the perfect tools for it. I wanted to upload my pictures in flickr and access it from my own web-site. The reason? Multifold. On flickr, the storage is cheap and almost unlimited. Its also about using the community support there. On the flip side, the GUI is not snazzy. It works alright, but it’s not super presentable. All I want is presentation layer for the pictures that I have already uploaded. One way to do it is upload the pictures in your own website, but then you lose the advantages of flickr. More so, on a philosophical note, why should I upload the same pictures? Twice. (Web-development was never the best skill set that I ever possessed so, I used to copy paste flickr URL into a file on my website and render all these URL-images.)  Never found time to better this until I found pixel post.

Ok, if you want results like these read on.

So, what do you do now? What you set out to do in the first place. Upload pictures on flickr and pull selective images from there on to your web-site. Simple? Yeah. Spent four hours doing it but, trust me - the sense of accomplishment was immense. Enough chatter, now lets get on with business.

  1. First download pixel post. Copy the files from here on to your website. Read the installation instructions. (Note: You’ll have to setup a MySQL database. Check with your hosting service.) The installation should 5-7 step process and should not take you more than 20 minutes. Now, that the easy part is out of the way. Let’s get some flickr modules.
  2. Download this pixelpost-flickr module. Unzip it. Refer to the README for some instructions. This part is might get you a little woozy if you not familiar with web-security, a.k.a authentication/authorization, public/private key encryption. Don’t panic. Follow the instructions you will be fine.
  3. The pixelpost-flickr module relies on the phpFlickr module to get images from your flickr account. You can download it from here. (This involves authorizing your website to access flickr.)
  4. Once you’ve installed both these modules. Be sure to turn on the modules from the pixelpost admin page (pixelpost -> addons -> turn on modules). The pixelpost module will appear under (pixelpost -> options ->importr). Fill in the “tags” that you want to import from flickr and the pixelpost-category that it should be placed into. Be sure to run (addons/importr/importr.php) to import your images from flickr. (You have to do it each time you upload a new picture in flickr. Pain, yeah?)
  5. This should enough to import your pictures from flickr to pixelpost. Since, I was craving to have the sexiest GUI (all my life) I browsed around until I found something that I liked.The guy built who it has a fancy and premium version of the same template, if you want it. Anyway, thanks to him for the template.

As a matter of fact, thanks to pixelpost, importr, yui, jquery, flickr and every technology that makes it work. (Though, it did come with some effort, hopefully, it gets better from here). Thank you, again. And, for the rest who want to set it up like I did, good luck.

stl FAQ

Random facts

  1. std::list.size() is O(n) operation. Use list.empty(), if you can.
  2. (multi)map and (multi)set are ordered containers. iter++ will move in the order of inserts.
  3. Never make create a container of auto_ptr<T>
  4.  std::remove() does not really remove. Use erase/remove idiom for contiguous memory (vector, deque) containers. Use Container.remove() for non-contiguous memory containers (lists). Do not use remove for any associative container (use erase)
  5. For all practical purposes, std::vector<bool> does not exit
  6. Use reserve if you know the exact number of elements in the container. Use swap to trim excess capacity

Writing exception safe code

Exceptions offer an elegant to roll up error state to the caller. Thank heavens we can do away with setjmp and longjmps. Mind you, exceptions are expensive (unwinding the stack is!) Use return code to handle error state, if need be. Yes, it’s not the easiest way to to trickle up an error.

Think about transactionality of the call. Does your function offer basic or strong safety or is it exception neutral? The standard containers require this by contract|function signature in all case. Here’s a pessimistic discussion about why we cannot rely on exceptions to make our software more robust. Years later, here’s a follow up, by Petru on how we can write ‘hard-working’ code to ensure atomicity and exception-safety by the RAI-idiom.


The type-safe bool in C++

Not that there were enough data-types in C already? Some arguments why a simple C++ class wouldn’t replace a bool. Here’s a discussion about alternative implementation for a type safe boolean, ranging from #defines, const int, enums to to what not?! After all these, we stop wondering?!


vim

vim - is definetly more powerful than I actually assumed. After you have basic stuff out of the way, here are a few things that you want to setup before working with large projects.

Tabs , cscope, marks, mouse, key mapping

Of course, all of this and more comes for free with eclipse, visual studio, etc. Oh, I forget they are IDEs and take five years to load.

Of course, I’ll post more when I configure my vi.

Hail, vi!

Naati Koodi Koora (Chicken Curry) - Type II

Use the same procedure here. Instead of the chilly powder use - one spoon of pepper powder and three green chillies.

Oh, yeah - you’ll love ‘em. Andra Style :-P


Naati Koodi Koora (Chicken Gravy)

1) garam masala two spoons
2) chicken masala two spoon
3) dhaniya powder two spoons
4) chilly powder     two spoons
5) grated coconut - one spoon
6) Ginger garlic paste  one spoon
7) salt (to taste)
8) onions - two
9 )tomatoes - half? [I use 3-4 spoons from the diced tomatoes can]

chicken - 1.5-2lbs

Preparation:
i. Cut the onions
ii. Put (1) through (9) in a mixer to make a paste
iii. Defrost the chicken
iv. Cut the chicken
v. Boil the chicken with just a little water in a cooker - until it seems cooked. [The chicken will begin to sweat - it will “yield” water]

Now you have “almost” cooked chicken and beautiful paste that you made in step ii.
vi. Put the paste in the cooker with the chicken. Add water to the paste to make it a gravy to desired “density”.
vii. Pressure cook it - for a single whistle. You don’t want more than one whistle because it chicken is already cooked. Ideally, you should get the gravy depending on how much water you’ve added in the first place, right?

You might want to add salt to taste, but it should do if you used the proportion that I mentioned.

I’ll post a picture in the coming posts.


Arches National Park

It was a hot day, close to 100F. I want to say cloudless but, that wasn’t true. Anyway, it was desert for as far as I could see. Lone standing rocks as if they were kept there on pupose or, as if someone had forgotten to get it out of the way. At the distance, looking at the colour of the rocks, you would tend to think the rocks are burning, trust me, they were.

Balanced Rock

I spent the whole afternoon driving around - rested at the Double arch for a while. Under the arch is the only shelter you would find in the piercing heat. The Delicate Arch was the big one everyone talked about. It is almost a symbol of Utah. (Wonder why everything is called an Arch?) I bet you have seen it somewhere! The walk to Delicate arch, if I remember right was close to 1.5miles from the road. I thought it was off-season at Arches, yet I couldn’t get parking to walk the trail. Disappointing. There was an Delicate Arch View trail a few miles down the road. It was a far-side view of the arch, across the valley. The valley was breath taking. Are you the types who is afraid of heights? Good luck looking down.

Lower View Point - Delicate Arch

Moab, Ut

This was my base station. Small town in Grand County, Ut with a population of five thousand (may be?) - two hours from Grand Junction. I had booked a room at a hostel in the city. I was apprehensive about staying here, but it turned out to be one of my luckier decisions. Great people , very helpful. They helped me plan the rest of the trip. It was an ideal place to stay because, it was ten minutes from Arches National Park and thirty minutes Canyonlands.  There are a plenitude of activities that you engage yourself with: sky diving, whitewater rafting, mountain biking. Oh, by the way, did I forget to mention? - it is an outdoorsy place!

Return top