Friday, September 5, 2014

The stigma of asking question.

Everyone, at one point or another, was new in a certain environment and everyone, at one point or another, felt helplessly lost.  While searching the web is a good skill to have, it's not always the skill that everyone learns early in their tech journey.  I, myself, have asked ridiculously simple questions that I could probably find answers to by searching on the web for a few minutes.  However, due to the fact that I was new, lost and did not have good enough search skills, I resorted to seeking help at places such as StackOverflow.  While some people were very generous with their time and knowledge, others felt as if it was worth it putting me down, rather than helping out... keep in mind that it would take the same amount of time for them to help me.

I understand the notion of feeding the vampires and some cases are very obvious.  There are some people that post a two sentence question without any showcase of effort and expect everything to be done for them.  No, I'm talking about the people that have shown effort and just need a little bit of a push in the right direction.  I am not going to go into discussion as to why some people resort to bashing at the poor newcomers, rather than giving them a helpful hand, since there are too many reasons, but I will ask that we, those who have acquired enough knowledge to succeeded, assist those who are at the beginning of their journey.

Mind you, I am not a saint, and I too, have bashed at those who have asked for help.  However, I have recently revamped my thought process and decided that rather than put people down, if I believe that they have not asked the question properly, I will assist them in rewording it.  If, however, I see that they've put in good effort, I will provide them with my time and knowledge and make sure that they're provided with a kind transition into this wondrous world of programming and technology.  I see far too many people down-vote posts on StackOverflow without providing any comments or helpful hints, thinking that the person on the other side magically knows what to search for on the web.  If they're new, they might not be aware of the exact key words they need to provide for the search.  At the same time, they could be helplessly tired and in need of a little bit of assistance.  When I was taking six classes in a single semester, working full time and studying on Pluralsight, I felt numb, physically and mentally, most of the time.  It is due to my experience that I know how some of those people may feel and I would rather be helpful than bashful.  I urge other to follow a similar path.  I'm not asking to give handouts, I'm asking to be helpful -- at the very least, point them in the right direction.

Tuesday, August 5, 2014

Tackling Time Zone APIs with REST and C#

I've been working on a portion of a side project that requires local time information based on specific latitude and longitude.  There are many services available there, but due to the budget restrictions, I needed to find something free.  After looking around, I was able to find a short article by Jason Watmore, where he describes how one can obtain time data using Google's TimeZone API, RestSharp and C#.  It took me an hour or so to get it to work, mainly due to the fact that he had a mislabeling in his code (I don't want to call it a bug, because the way he used it, there was no bug; but, the way I did, it presented one).  Either way, he was quick about replying to my comments on his blog and shortly after we were able to solve the issue. If you're interested in that conversation, you can read our comments on his blog.  So, I'd like to take this opportunity to thank Jason for giving me his time and providing me with excellent starting code.

Google, while has a wonderful API, has a limit of 2,500 requests per day for free users, so I wanted to try a few other APIs.  The two that I landed my eyes on were TimeZoneDB and GeoNames.  TimeZoneDB does not have use limit on the registered key, beyond spamming it with queries; however, it is run privately by an individual and it's free only for non-commercial use.  GeoNames, on the other hand, is well known, has been around for a long time and will continue being around for a long time -- or so we can hope.  The catch with GeoNames is that they have a limit of 30,000 requests per application per day.  An application is defined by the username, so I am not sure if there is a limit on usernames.

The wonderful part about GeoNames is that you may obtain an offline dump, so that you have a local database to query without a limit..  GeoNames time zone information also includes things such as sunset and sunrise, which the other two APIs do not.  However, GeoNames is missing a very important future and that is inability to query for a specific date at a specific location.  Any query for a specific location will return the current date and time there.  You may insert a parameter to query for sunset and sunrise on a specific date, but that does not do me much good in my situation.

In the meantime, I will provide you with my code: You'll need to provide your own key for the GeoNamesGetLocalDateTime method and your own key for TimeZoneDbGetLocalDateTime, so the output window at DotNetFiddle is not going to be accurate until you do.  Those services are easy to sign up for for free. The Google portion is largerly based on Jason Watmore's code, so the credit for that goes to him.  Furthermore, do not forget to install RestSharp -- you can do it very easily through NuGet in Visual Studio.  I did not comment excessively, due to the fact that most of the code is very self-explanatory, but if you have any questions, feel free to leave a comment and I'll respond.

Sunday, July 27, 2014

I love Git.

I haven't posted in a while, due to the fact that I've been extremely busy.  Recently, I was invited to join a pretty cool aviation simulation project.  Since I served in the U.S. Navy for five years as an Air Traffic Controller, I was very excited to join in.  However, most of my excitement wasn't necessarily due to the nature of the project, but due to the fact that I was given an opportunity to learn some team collaboration skills and tools.

One of the first tools that I was exposed to was Git.  Mind you, I've heard of Git before, but I thought that being a solo programmer, I wouldn't need it.  Boy, was I wrong...  Version control tools such as Git are worth their weight in gold and then some.  I instantly fell in love with ability to branch, merge and review old commits.  It allows me to review all of the notes I've placed in my commits.  That, right there, is actually a very important step.  Some people provide very minimal effort to their comments, but they serve as an invaluable tool of tracking the changes beyond what's in the code.

Furthermore, Git serves as a historical documentation of what I've done and why I should get paid for my work.  From here on, I am planning on using Git or similar tools to keep track of my projects and I recommend that anyone, no matter the size of the team, gives these tools a try.  There are many other tools besides Git, such as Mercurial.  I have it installed, but haven't had the time to try it out; therefore, I can't comment on it.  However, if you wish to learn more about their differences, here's an excellent post:

As far as using Git, I take advantage of the nice interface provided by SourceTree, coupled with BitBucket.  GitHub is an excellent choice as well, but that is not what my current team uses.  If you don't want to download SourceTree, Git installation package offers an ability to install Git GUI along with its Bash, which works very well.  That is what I used prior to installing SourceTree and I did not have any problems with it (I just wanted a bit more functionality and visual comfort).

To get started with Git, here are a few valuable links:

Free Git book:
Free Git Videos:
Git Reference Page:
Git Cheat Sheet:

Thursday, May 22, 2014

Initialization of Auto-Properties in C# 6.0!

Prior to C# 6.0 there have been only two reasonable options for initializing auto-properties.  One is through the backing field:

   public class Person
        private int _age = 23;
        public int Age
            get { return _age; }
                if (value != _age)
                    _age = value;

...and the other is through the constructor:

   public class Person
       public int Age { get; set; }

       public Person()
            Age = 23;

This might not seem as a huge deal if you're dealing with a few properties, but what if your object has a dozen or more?  One of my current applications is using a few Model classes that contain a relatively large number of properties and it becomes cumbersome to instantiate them.  I instantiate them through the constructor option and this becomes even a bigger hassle because I have to make sure that every one of those properties is in fact instantiated within the constructor.  Thus, I spend a lot of time going back and forth, making sure that both properties and their initialization are in sync.

However, in May 2014 issue of the MSDN Magazine, Mark Michaelis announced that C# 6.0 will feature auto-property initialization:

   public class Person
        public int Age { get; set; } = 23;

It's that simple!  Furthermore, if the property is declared as read-only (lacking the setter), it will still be assignable at the declaration time, very much like the assignment operation in the constructor.

There are many other features that are being added in C# 6.0, but the auto-property initialization is the one I got excited over, due to the fact that it'll decrease my workload and make it easier to make my software.

Sunday, May 18, 2014

Update on the battery life of my new MacBook Pro 15 Retina using Windows 7.

I promised that I would let you know how long the battery lasts on my new MacBook Pro 15 Retina after a few weeks of field use.  I am pleased to report that under the moderate-to-heavy use the battery life has ranged anywhere from three hours during borderline heavy use to approximately four and a half hours under the moderate use.

Operations ranged from giving PowerPoint presentations, while running Access database and the showcased application in the background, to a full-on Windows Presentation Foundation development with Visual Studio 2013 and Blend open at the same time.  Note that I had my brightness set at 80%.  The laptop was able to handle everything without any notable issues and the typing experience felt great.  The touchpad functioned fantastically and I didn't feel an urge to use a mouse.  This was something I was worried about, because I'm a heavy mouse user, but after using this laptop's touchpad I now feel very much relieved.

The only draw that I noticed was the fact that I could not use the Delete button the same way as in the Windows environment.  Rather, it functions as a Backspace.  I haven't researched into a way of changing it to function as a dual button by having to press the function key for the second functionality, because it hasn't bothered me that much.  However, I'm sure there is a way.

I can't believe that I'm saying this, but I'm actually very satisfied with this Apple purchase.  I feel like I've spent a lot of money on something that's of high quality.  I wish I felt the same way about that Lenovo T440s I ended up returning.  I really wanted to like it, but it felt too cheap and the touchpad was beyond horrible (see my previous post regarding the issues).

Thursday, April 24, 2014

The search for a perfect developer laptop.

I haven't posted any updates lately, due to the fact that I've been incredibly busy with the two programs I wrote.  They are currently being beta tested at two of our locations and are soon going to be adopted at eight to nine additional locations.  One of the problems I've experienced was not being able to fix any sort of bugs at those two locations during deployments.  Both of them are approximately 90-100 miles away from my house, so I had no choice but to either wait until I can deliver the patches by driving to the locations or do it remotely via VPN.  Obviously, the second choice sounds like a better idea, but I couldn't test the releases remotely and sometimes the connection would time out during the transfer, causing more headaches.  More often than not I wouldn't have anyone at location that could assist me, because it's hard to find anyone with a good technological background that doesn't get lost at the "right click." :)

A natural solution was to acquire a laptop.  I had an ASUS Q200, but the poor fella couldn't keep up very well, even with just Visual Studio being the only program open.  Compiling basic programs became too frustrating and lengthy.  Don't get me wrong, it's a nice little laptop... for web browsing, some video streaming, email and light office work.  However, it did not belong in the software development realm.  So, I ended up selling it to my mother-in-law, who is making a good use of it now.  I began looking for a replacement and could not decide what I wanted.  I knew I needed something that had an approximately 14-inch or greater screen and could handle having Visual Studio and Blend open at the same time, without much struggle.

I ended up getting myself a Lenovo T440s.  I've never owned a Lenovo or an IBM laptop, but I've heard a lot of good things about their products and their support.  After two weeks of waiting, because my shipment got delayed in China, I finally got my laptop.  It was gorgeous.  I love the minimalist, business-like look.  My self-built desktop is of similar design.  I am not a fan of flashy lights or gimmicky additions.  T440s was very light and felt of superior quality; that is, until I began using it.  I was shocked by how cheaply the touchpad was made.  It felt as if I was robbed.  On my desk I had a $1,500 laptop with a 2-cent touchpad.  It was horrible.  Upon pressing it even lightly, it produced a horrible ratting and loud sound, similar to that of a cheap spacebar.  I haven't heard such sound in a long time, due to the fact that I use a Logitech G710+ mechanical keyboard with my desktop and my wife uses a MacBook Pro (early 2012 version).  Her touchpad has a nice, firm feel to it.  Every click actuates sharply, without any annoying after-sound.  It's my fault, really... I did not do my homework.  If I have, I would have found out about this issue on the Lenovo forums.  Many people are experiencing the same issue.

Furthermore, T440s has horrible problems with touchpad drivers, which cause the cursor to jump around erratically for no reason.  Opening or closing things became extremely frustrating, because of constant miss-clicks.  At that point I didn't even care about the sound, but I could not handle the driver issue.  I ended up following some of the tips online and got it to approximately 80% efficiency.  Still, I was upset that I spent a considerable amount of money on something that did not work properly out of the box.

I promptly contacted the support and explained the issue, thinking that it would get resolved rather quickly, due to what I've been hearing from others.  The gentleman on the line confirmed that the sound was very odd and that the model next to him did not sound anything like it.  I could not hear his clicks, while he clearly heard the rattling sound coming from my side.  I took great care not to press the touchpad too hard, because I did not want to produce an unlikely sound.  I wasn't trying to make anything up and I wanted to see if it was just me.  Maybe the sound was normal and I was simply being over-dramatic.  However, he confirmed my concerns.  The next morning I received a box for the laptop to be sent to the repair center and I was told that I would be updated on Monday regarding its status.  When Monday came, I waited until later in the afternoon and called them.  I was notified that they just received my laptop and that the repairs have began.  I was a bit frustrated that they couldn't start repairs on Friday, since I sent it out in the morning on Thursday, but it was not a huge deal.  What was a huge deal was the fact that when I got it back that Wednesday, the touchpad was exactly the same and they actually mis-aligned the keyboard bezel.  So, on the left side it was slightly overhanging and on the right side it was bulging up as if it was forced to the body.

Along with many other things during the process, that was my final straw.  I began looking at other laptops and couldn't find anything that was comparable in quality or performance.  The only brand that stood out was Apple.  Yes, I said it - Apple.  If you know me, then you know how I feel about Apple and about its fanboys.  However, I could never argue with the quality of their hardware.  At this point, I did not care that MacBook Pro 15 Retina (2.3 GHz i7 quad-core, 16GB RAM, 512GB SDD) was made by Apple.  It could run Windows 7 using bootcamp from what I've heard and I wanted to give it a try.

I've heard mixed reviews and I was worried.  Some people have mentioned that the battery life was horrible while running on Windows, others said that there could be significant display issues due to the Retina display, others mentioned that the whole process was a driver nightmare, but I was willing to give a try. Worst case, I could always return it.  Boy, was I surprised. Within an hour, I had a fully functional Windows 7 running on my new Mac.  The only issue I had was the fact that the resolution was awfully huge, and even though Windows scaled up everything to 150% (maximum on Windows 7), everything was still a bit too small, even on the 15" screen.  So, I reduced the resolution down to 1920 x 1200 from its 2800 x 1800 default.  A second part to that problem was that the DPI scaling by some programs was not done properly - chiefly, Chrome.  All I had to do was right click the executable and prevent the DPI scaling.  I then set the default zoom to 150% and it worked like a charm.  My Windows Experience Index on this laptop is 7.2, with everything except the video at 7.9 (video was 7.2 and WEI is always set to the lowest score).

To my surprise, Visual Studio 2013 and Blend had no issues at all.  They started within split of a second and everything worked flawlessly.  I tested the battery under full brightness, full-on performance settings using the Battery Eater and got approximately one hour and 15 minutes out of it.  This is actually really good, considering that even under heavy development I would never stress this computer as much as that piece of software did, unless I was trying to render something in Blender, which I would probably do only if I'm doing something on my desktop; and even if I had such process executing on my laptop, it would probably be plugged in.  So, I expect approximately four to five hours of use out of it.  I would be happy with anything over three.  I wish Apple allowed a swappable battery.  I loved the fact that T440s has an internal battery and an external battery.  Therefore, you can actually hot-swap your external battery, without having to shut down the laptop.  I'll have to look for a battery pack to go into my laptop bag, I'm sure there's something out there.

I must say, though, that Lenovo actually did a better job as far as battery goes and produced one hour and 42 minutes under a similar load.  However, it was not as powerful as the Mac, and the rendering during the stress test was becoming choppy every five minutes.  One other thing that Lenovo did much better was its cooling.  The entire time it stayed relatively cool and produces very little fan noise.  MacBook Pro, on the other hand, was very loud and extremely hot underneath and relative hot on the keyboard, as it squeezed every bit of power out of its four physical cores (eight total, due to hyper-threading).  It would be unfair to compare their hardware performance, but Lenovo did not have anything for T440s that could match the MacBook Pro 15 Retina.  PCMark gave the Mac a score of nearly 6000 (just under) and mid 3000 to the Lenovo machine.  I wrote a quick C# console program that used Fibonacci sequence of 50 numbers to test both machines.  Mac was able to produce all 50 integers within 15 minutes and a few seconds, while T440s took well over 20 minutes and actually almost hanged towards the end.

To be completely honest, if T440s did not have such a horrible touchpad, I would stick with it, because it has a phenomenal battery life, a hot swappable external battery pack (so I could carry up to two spares, due to the fact that they're very light and slim), I love the way it looks, it has a decent performance, amazing cooling and it's very light.  On top of that, it cost me approximately $1,500 after taxes (with 4GB RAM and 512GB hard drive), which is $1,000 less than MacBook Pro 15 Retina.  I would add an extra 8GB stick (the 4GB is soldered onto the board) and replace the HDD with a 256 or 512 SSD, which would still bring me well under Mac's price tag of over $2,500 after taxes and with a student discount.  However, that touchpad made it completely unusable and I am pretty darn satisfied with with Mac's performance, its screen real estate and its painless incorporation of Windows 7.  While I have bashed Apple plenty of times and I'm still sticking to most of what I've said, I will not hesitate to obtain a product of high quality.  This Mac is just that.

As a .NET/WPF developer, I've been frustrated with Microsoft plenty of times for some of the most insane bugs that I've found in WPF, which Microsoft is brushing off as of no importance.  However, there are plenty of things to like about Microsoft and Windows line (especially XP and 7).  I'm not going to list them here, because it does not pertain to the discussion, but I point this fact out so that you may understand why I'm not completely alienating Apple.  Yes, I disagree with some of their ideologies and the way they do business, but if they produce a good product, I will give them kudos for it and I will gladly adopt it.  In my opinion, MacBook Pro 15 Retina is an excellent product, comparing to a lot of its competition out there.  Of course, take what I just said with a grain of salt.  I don't have the time or the resources to test all of the available products out there, but I thought I'd share my personal experience and opinion.

I honestly did not think that I was going to like having a Mac that runs Windows, but it somehow works out very well.  An added bonus is the fact that I can switch to Mac OS to test out a ported app.  I was eyeballing the Mono project for some time and that'll give me an opportunity to test it on Mac. My next goal is to figure out how to install a Linux distro onto it, so that I can have all three.  I've heard that Parallels can do it, but I haven't had a chance to try it.  I may revisit Lenovo years from now, when they fix their touchpad problem, but for now I'm pretty satisfied with my perfect developer laptop - MacBook Pro 15 Retina running Windows 7.

UPDATE (04/24/2014):  I am not sure if Chrome was updated, but it no longer shows up blurry even without disabling the DPI scaling.  So, things just got pretty awesome. :)

UPDATE (04/27/2014):  For the past few days I've been trying to test how much time I can get out of this MacBook Pro 15 Retina.  I can report that the average battery life has been approximately two hours under heavy load.  That was with 60% display brightness and 30% dimming brightness after two minutes.  Not anything spectacular, but the fact that constant work was performed for those two hours has to be taken account.  In reality, when I begin using it out in the field, it'll probably last me 3-4 hours of moderate usage.  That, of course, is an estimate, and I'll update you after I test out it for the next few weeks.  I really wish it would have a swappable secondary battery pack like T440s, but everything else on it is amazing.  Next test will be light-to-moderate usage in home environment.  Note that, as I've mentioned, the actual field test won't be reported until after I test it out for a few weeks.

UPDATE (06/26/2014):  Well, I'm happy to report that after testing the in-home moderate usage, I was able to get four hours and thirty-five minutes out of the fully charged battery and that's not even fully discharged ( I didn't feel like going lower than 10%).  Usage consisted of downloading and installing programs, while running Visual Studio 2013, for the entire duration of the test.  I needed to install all of my productivity and development packages, so it was perfect timing.  I'll report back with the in-field findings in two weeks.

Saturday, March 15, 2014

It gets easier.

While attending college, I have been a witness to an interesting phenomenon.  A usual programming class in the Riverside Community College District would start off with approximately 30 students, give or take a few. After the initial weeding out of the ones that thought this would be an easy A, a usual class would consist of approximately 20 students.  What I've noticed is that by the end of the semester, some of the classes would have 10-15 students left.

Of course, some students realize that programming is not something they enjoy and drop a related class.  That is definitely the right thing to do when you sense that it's not your cup of tea.  One of the worst things is to waste your life away on something you don't enjoy doing.  Is a few weeks enough time to truly see if it's something you'd enjoy?  In my opinion - no.  However, I'm not here to talk about those type of students.  I want to talk about the ones that enjoy doing it, but are too scared to press on.  I lost count of the number of students who claim that they'll never get to be "good at it," or they're "not smart enough."  Wrong!  Everyone is smart enough.  Some people are naturally better at certain things, but almost everyone is able to get good at something they enjoy.  First steps are always the hardest.  It's boring and repetitive to learn fundamentals of anything.

At Big Bear Mountain
A good way to beat the notion of not being good enough to achieve something or being afraid to take on a new challenge is to just start doing it.  I am naturally pretty poor at balancing.  I am very stiff and failed many times on a skateboard.  Therefore, when I started snowboarding, I thought that it would be just to say that I've tried it, and not something I would do as a hobby.  After large number of face-plants and an almost torn knee, I got to the point where I'm very confident on the snowboard and make newbies turn their heads as I scream by them at full speed.  I stuck to it and I got good at it.  Snowboarding became my winter season hobby and I love it.

How did I get to the point where I realized that the biggest obstacle is my own mind?  Through my life experiences.  When I was 17, I joined the U.S. Navy.  When it came time to pick my rate, I chose to be an Air Traffic Controller.  My English was poor (I've only been in U.S. for three years at that time), and I was a fairly timid teenager, but I scored very well on the ASVAB. Air Traffic Control (ATC) had one of the highest attrition rates in the U.S. Navy (not counting the SEALs, of course), with approximately 40% of the personnel making it through the training program.  It sounded like a fun challenge, and it's not like I could get fired from the Navy - I would just get stuck with a different rate. I graduated in the top five of my class and within a few years I made a rank of Second Class Petty Officer (E-5).

When I left the Navy, I wanted a job that paid well, but I did not want to do Air Traffic Control.  Air Traffic Controllers get paid very well, but I was bored with it.  So, I eyed the California Highway Patrol as my next target.  The pay was good and the CHP Academy is one of the toughest law enforcement academies in the world.  With an approximate attrition rate of 40-50%, it sounded like a fun challenge.  I graduated as number 23 out of 165 in my class (we started out with 240).

Thus far, I have been choosing pretty tough careers and I've excelled in all of them.  Was it because I'm smart or strong?  Well, I'm not stupid - but it's not the reason. The reason is that I give my 100% to everything I do.  When things get tough, I don't give up.  It is tough to adopt this sort of mindset, but once you start practicing it, things will get easier.  All of a sudden, obstacles become fragile and almost anything seems achievable.  This mindset helped me a lot during my transition into software development.

When my classmates began dropping out when pointers became a thing of sorcery and impossible to understand, when memory leaks due to un-disposed objects became a thorn in the side, I simply held my breath and pushed on.  I knew that, even though I was getting lost and did not understand some of the information, I would get it some day.  Looking back at any of the concepts I struggled with previously, I smile, due to the warm and fuzzy feeling of knowing that it's because I stuck in there.

Good things are rarely easy.  Don't give up.