Author Archives: Afzaal Ahmad Zeeshan

About Afzaal Ahmad Zeeshan

Student, Self learner, Pakistani - by nationality, Ahmadi - by belief, Software and web developer for .NET framework and for other frameworks. Mobile developer for Android, iOS and other MAUI-based generic mobiles. Teacher for new developers, friend for everyone, loves everything.

Another good library for developers — Easy solution

Today, I am happy to share the blog about a .NET library for developers that enables them to create documents in different formats for office and online use. Spire.Doc library is a library for developers trying to solve the interoperability problems with Microsoft Word, PDF, Rich Text Format and HTML format. It was a very amazing library as I went through it and the developer of library has provided a very efficient solution for the API guide along with the product itself.

I have written the review for the API and provided a simple, but a very general example of the usage that a developer can try out, in their applications, for dynamically generating the PDF file and sending it to client. Perhaps, I missed most of the things about the term dynamic in the review post. But, you know… You can always add variables instead of hard-coded strings and objects. Among review, I have provided a couple of scenarios in which the API is very much useful,

  1. Converting documents from one format to another
  2. Reading existing document, or making changes to them
  3. Generating documents on run-time
  4. Sending dynamically created office format files to potential clients
  5. Many more

So, read my review at: [Review] Spire.Doc .NET library for cross-file format document creation and share it with your friends also if they are new to this library, or are still wasting their time thinking what to do and how to solve the interoperability problem with Microsoft office and other file formats. I have provided most of the information bundled into sections. If you find a part missing, or faulty, do hit me with a comment reply. I would look into it.

I will post more stuff for developers, soon!

Count your 9s before blaming your CPU

Recently I was working on a Windows Forms application and I tried to create an async model, to see how long does it take to perform the loops. Although it doesn’t take much time for our CPU to calculate the results for our general loops; thousands, or hundred thousand maximum. I created the model for performing the loop as,

// loops, seconds are defined to be long variables.
private async void runAsync() 
     long res = await result();  
      resultLabel.Text = String.Format("Result of {0} loop addition is {1}.", loops, res);  
      // Done.. Stop the timer..  
      timerLabel.Text = String.Format("{0} seconds took to calculate result of {1} loops", seconds, loops);  
      seconds = 0;  
private async Task<long> result()  
     long res = 0;  
     return await Task.Run(() =>  
          for (var i = 0; i < loops; i++)  
               res += i;  
          return res;  

Well, it probably does what it is asked to do so. The only case of interest is, when the value is given to the loop. Let me show you the results for each of these cases…

Having 0-8 9s.

In case of 9s from 0 to 8, the execution takes only a fraction of one second.

Continuing to 8th result now,

Quite similar behavior being shown in these cases. Which shows that CPU is pretty much fast to calculate this much loops easily and to provide the result; if the result is not correct, please avoid mentioning it.

Adding a 9th 9

With a new 9th 9 being added to the loop; the results now amplify, instead of 1 2 or 3 seconds, it takes up to 8  seconds to execute the loop and provide the results.

That shows the significance of a 9 in the row of loops…

Adding a 10th 9

By using another 9 in the loop, I was finally able to manage to make the CPU work for a longer time… Much much longer time. My CPU doesn’t provide any result for this calculation, and took more than 7 or 8 hundred seconds.

Not bad, eh?

I will not say, CPU was not efficient as it was able to calculate the results for 0-8 9s and then started to topple the time by an increment of each 9 (each 9 made the first 9 in the left side tens, from ones, and hundreds from ones and so on making the loop counter to be billions). The number for the loops was, nine billion nine hundred ninety-nine million nine hundred ninety-nine thousand nine hundred ninety-nine. Which is quite reasonable for the CPU to take this much time.

This reminds me of the “Transistor as an amplifier“, current moves and at a critical level, voltage rises and just keeps rising… I am really glad I found this and took time to write a blog about it. 🙂 Hopefully, next time you will count your nines before saying your CPU is fast!

Multitasking in our brain, can it be compared to that of a computer?

Quite a lot of similar news posts, researches and other paper is available to talk about how worse creation of God was, as a comparison to that of creation of His creation. Some news suggest that brain is no good as compared to a CPU. The funny part about this is that most of these authors are from Universities, playing their much vital (and respectful) role as a professor in psychology or computer science sections. I know, it is a great way to inspire people and gain recognition by giving away a thesis paper or a post with “Science research” tag on it, most engaging I believe.

But we’re actually missing a lot of things… Our computer machines were built right on the base on our body; human anatomy I am talking about. What do you think made the pioneers call CPU, the brain of computer? All of the underlying concept and functionality is similar… It is only the broader look of the machine which attracts you to the goodness of machine. I have not yet quite possibly seen any difference until now. Let us walk through a quite scenarios to talk about the difference… Or more specifically the similarities of a brain to a CPU; computer’s brain.

Multitasking — What is it?

It would be better to first define the term Multitasking itself before going on to comparison about what they are in brain and the CPU. Multitasking is a term coined by computing, in which different (or quite generally and possibly) processes or functions or programs are executed (or performed) simultaneously; concurrently at the same time. You can take the example of this in your modern graphical user-interface based operating systems, where you can run different software at the same time without having to worry about the underlying stuff; such as memory management or clock ticks by the CPU. Operating system does all of this stuff for us, all we have to do is, click on the program to run another program.

At a broader level

Now that the actual concept of multitasking has been shared, it is time to judge a brain’s capability to that of a CPU’s. Let us first of all talk about the broader level of comparison.

A brain, well… Let me talk about my brain while I am writing this post… I am listening to Eminem’s Rap God; awesome song by the way, I am writing this post, I am also chatting with 2 friends of mine and yeah I am also having another article in the queue for code reuse. All of these right at the very same time. I am not getting puzzled, neither am I tripping or loosing the grip from any of these processes; specially that Eminem’s song process. Now let me talk about CPU, my CPU (Intel i5) is performing well a lot of underlying process… But I will talk about those which I am running (because brain also manages the blood, body temperature, sensors and all and I won’t try to count them similarly the OS-based processes are not to be counted in this war), such as I am installing Android SDK, I am playing the music, I am writing this post and I am also having that other article stored and waiting for me to get back onto it and complete it.

From this above paragraph, it is clear to see that at a broader level of comparison, they’re totally alike. There is no difference between any of them, and you can say CPU works as brain.

At a micro level

Now let us talk about what happens at a micro level in both of these objects; CPU and brain. We all know, most of the devices (more specifically CPU) can execute one command at a time; it can be better described by the machine cycle, which is,

  1. Fetch — from RAM to the CPU registers
  2. Decode — Into operator and operands
  3. Execute — perform the operation
  4. Store — It can be a display operation, or to store the data in the RAM back.

Above can describe how the CPU works, and how it executes one command… To be specific, it also takes 4 steps to add 1 with 1; 1 + 1 = 2. We make it better, through pipelining to allow the processor to process 4 different commands in one cycle. Same thing comes with brain, brain performs one task at a time, but all of this happens in a very fast (but not very much fast). According to this very clear and fine research and calculation, our brain, can perform 20 million billion calculations per second. Intel’s i7 processor is capable of performing 298,190 million instructions per seconds; please see Wikipedia page for more.

Personal views…

Now this section might be about my personal views about science searches now a days. But you should read it anyways.

I would like to dis agree to those professors, who believe that human brain is not capable of doing anything… Are you serious? What you think helped humans create these high-speed computers you’re trying to embrace now. No matter how fast you can build the machine, it can never even touch or demonstrate the greatness of the creator. As it has been made clear enough that on the macro level they both act similar, or might even look like CPU is being fast enough to handle multitasking approach, but it is not the case. At the micro level, you will find out that brain is faster. How does then CPU win the race at the macro level?

That is because we… Humans; of this age are just too lame to be fast enough. I am having a very solid excuse for this statement. We, at a very tender age try to ask for a calculator when we have to multiply 23 with 4. I know that is somewhat confusing but, if we focus on it then we can easily get the answer, 92. Just a little focus can enable our mind capabilities which have been sleeping ever since our primary education, because of a computer the calculator. Although performance of our mind can be decreased with aging, but that still is not the case when CPU can over our capabilities. Not only this, stress can also bring down the muscle to a low performance stage, after all it is a muscle; genius one.

Although computer scientists believe that a dual-core is capable of performing two tasks at a time, well… Two brains can then perform two different actions simultaneously. What’s the big deal then? Nothing… No matter how better they perform, how fast they try to make their CPU and machines, they can never reach the strength at which human brain can act. Our brain is the fastest intelligent thing on this planet, we just need to blow away the dust of laziness from our brains. Also, what did Eminem say in his Oscar winning song, Lose yourself? “You can do anything you set your mind to, man!”

New year in approach!

Many people have been talking about this new trend, this new baby-year that is about to come has been on lips of many young girls, and hearts of women! But who knows how is it going to be, diabolic, parodigal, or what else would it be? I am not going to say the same that people have been saying, like, “Happy new year – 2015!” well this is the simplest, many have even said, “Good bye 2014, hello 2015!” that made 2014 cry, I can feel it.

What I am here to say, is that, this 2014 was not bad… it finally made us realize our faults and our gaping holes in our systems. Think of it like, the 1st January 2014, people around the world were saying “May this year bring harmony and peace to all of your!” and what were we even doing? Most of us, were developing weapons, writing theoretical bombs and most of us were trying to perform our own ritual to make our God happy, to make sure we’re having a true religion, obviously a lot of true religions. So, how would we even believe that our year would bring peace and harmony. “Pen is mightier than sword”, how would it be mightier, when it is trying to write alogrithm to create a bomb?

2015, I have no blame for you, I know you’re going to be a next year for us to focus on our own goal and what we were created for. 2014, you’ve been really harsh on us. I know, it was also our fault, human is to err, no, human is to err and blame others. Hopefully, when we err this time we won’t blame others instead we would change our own self. Finally, “Happy new year fellows!” may you have a great year, to celebrate your life, to prove yourself, to do what you want and to bring peace and harmony! No pun intended.

Don’t be shy – afraid

Most of the new programmers who’re new into this field are usually concerned about their information and knowledge about programming and the concepts. I, have been a part of this community where people; usually with no knowledge on language, are acting like they’ve mastered the skills and are already the perfect programmers.

They try to act like programming was the first thing they ever did, even before the po-po ca-ca; ewww! No one did that, usually I get to hear a lot from friends, some speciall friends and buddies that they’re perfect in this thing, they hacked this, they cracked that software, they successfully sent a bug to that and all that.

But, guys listen up! This is not a race to prove yourself. I don’t even know why and when did I change myself and became an optimist of the computing industry and the divine software programmer. But, yes I am a good guy and I believe that the new thing that you do, you learn, you test or you show off is nothing to smile or dance for. You’ve got a lot of new things in front of you, to prove yourself at, to prove that you’ve got enough guts to prove your perfection in every stage.

A master is not the one who can write the software application with first attempt, he is not the one who can crack a software, neither is the one who can easily hack into his neighbour’s Wi-fi connection and nor is the one who can hash the password of the friend – ewww, a programmer is never a criminal.

I can’t afford to live a life where I am never going to see an error again. I still love those nights when I pulled my hairs in agression when a simple “System.NullReferenceException” made me stay awake entire night and understand and fix the error. That taste, that feeling is just perfection and no other feeling can even match it. Feeling of getting an error in your programming is the feeling of having those masalas added to your chicken – hmmm, yummy!

A master is the one, who gets to learn from his mistakes, who is not afraid to make a mistake even if that causes a havoc in his life, those mistakes make him understand what programming is what he needs to do what happens when he does what and all other such concepts. A master can never be a pessimist, that is why mostly people don’t get to this stage and it is never about the fame – we all are after. Once fame gets in your head you can never show your best and your skills will start to wither away. You can try pissing yourself off – run for fame, it will run away, run for your self show your best, fame will come for you, searching like a dead zombie searching for flesh.

A programmer can never think of anything bad, he is the one who is responsible for a good computing world – for a good environment for people to come and sit together share their views assets and others. If criminals would start to create internet and other technology assets there won’t be anything left at all to smile at – to have our faith in. We build programs, not for fame, we build it because we want to, we start a new framework and foundation because we want to help our fellows get more sleep at night, not to get a chance to come on the television to tell our cell phone number to the public – specially the women. Do think about your identity first, computer programming is not a field for fame or money. We are a family, don’t call us a community, it is a family, where elders are respected, juniors are taught and everyone loves everyone! There is no offense, no hate and just a happy and peacefull environment – untill people who love fame enter.