Monday, March 25, 2013

Test Driven Development in C


Found a good slide-show of Test Driven Development in C that doesn't use any heavy-weight libraries and figured I'd share...


Wednesday, March 20, 2013

RC2 Encryption in C

I recently had to implement a the RC2 Rivest (Block) Cipher in C. I didn't find too many examples so I figured I'd post mine here. This is a 64-bit block cipher with a variable key size.

This example uses the OpenSSL library.

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "openssl/rc2.h"

#define BITS 64

UBYTE *rc2_encrypt(const UBYTE *key,  UINT32 key_size,
       const UBYTE *data, UINT64 data_size)
{
    RC2_KEY rc2_ks;
    UBYTE *output;
    UBYTE iv[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    if (key_size % 8 != 0)
    {
        printf("RC2 key size should be a multiple of 8!\n");
        return NULL;
    }

    output = (UBYTE *) malloc(data_size);
    if (output == NULL)
    {
        printf("Out of memory!\n");
        return NULL;
    }

    RC2_set_key(&rc2_ks, key_size, key, BITS);
    RC2_cbc_encrypt(data, output, data_size, &rc2_ks, iv, RC2_ENCRYPT);

    return output;
}

UBYTE *rc2_decrypt(const UBYTE *key,  UINT32 key_size,
       const UBYTE *data, UINT64 data_size)
{
    RC2_KEY rc2_ks;
    UBYTE *output;
    UBYTE iv[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    if (key_size % 8 != 0)
    {
        printf("RC2 key size should be a multiple of 8!\n");
        return NULL;
    }

    output = (UBYTE *) malloc(data_size);
    if (output == NULL)
    {
        printf("Out of memory!\n");
        return NULL;
    }

    RC2_set_key(&rc2_ks, key_size, key, BITS);
    RC2_cbc_encrypt(data, output, data_size, &rc2_ks, iv, RC2_DECRYPT);

    return output;
}

Cheers!

Cherry Blossoms Bloom Dates Have Changed

Washington DC in beautiful in the spring.  Usually come the beginning of April I look forward to taking my wife and daughter to see the cherry blossoms.  We were excited to go this Saturday because they were expecting an early bloom.  But I just found out that they expect the bloom period to be April 3-6.  I guess we'll have to wait a couple weeks. :(


Sunday, March 17, 2013

Migrating from Google Reader to Feedly

Google announced on March 14th that they will be shutting down Google Reader on July 1st.  This was surprising to me because I've been using Google Reader for years.  But I guess if they can't get a lot of users then it's not worth keeping up.

Recently I posted an article reviewing an RSS feed reader called Feedly.  I've been using their reader on my iPad, Android phone, and just recently they've developed a Chrome client (much thanks!).

So I immediately wondered - what will happen when Google Reader shuts down??  Since Feedly is getting all my RSS subscriptions from Google, will the world end for Feedly when the infamous July 1st comes?

It turns out... not so much.

Feedly has us users taken care of.

It turns out that the developers of Feedly have been expecting for Google Reader to run it's course and have been working on a project called Normandy which is a clone of the Google Reader API.  When Google Reader shuts down, Feedly will transition over to it's new backend.  All without us users ever knowing the difference.

That's great service!

So if you're a Feedly user, who relies upon Google Reader for subscription information, don't fret - you need not do anything.  For all others who only use Google Reader, sign up with Feedly now and the transition will be seamless for you.

Tuesday, March 12, 2013

Sparrow: An Awesome Email Client for Gmail

When I first got my iMac back in January I started using the default email client that comes with all Apple computers.  I found that it was adequate but nothing special about it.  So I started looking in the App Store for alternatives.  I recently come across a great email client by Sparrow.

I was almost turned off by the extremely low 2.5 stars (yikes!) it was rated but then I started reading the comments.  I found that in October there were a lot of comments written up against the application stating that it was crashing, slow, or that it wasn't supported.  When I scrolled down I then found comments from people who had no idea what others were talking about, that the app worked flawlessly.  So what gives?  Why are all these people having issues but others aren't?

My suspicion was that someone is posting false comments and down-voting the application.  The first comment you read is negative and shows "83 of 93 customers found this review helpful".  It's hard to believe that this is true when there are more recent comments within the past couple months that praise the application.  Instead of bypassing this one, I decided to see for myself.

What I found was a very well designed UI.  I didn't experience the issues that others supposedly where having.  Perhaps they were running on older hardware or an older version of OS X.  I found that the application was very responsive and lightweight.  The interface is easy to figure out and just as easy to configure.


Here's what I liked most about the interface:
  1. Gmail integration is excellent.  For those of you who have a Gmail account you'll find that you can label and star emails, see your priority inbox, use one-key shortcuts, and use your contacts.
  2. The application connects to your Facebook account!  This is great for accessing emails and associating photos of people you might not have in your Google contacts list.
  3. Notifications on OS X work great.  A small pop-up is displayed on the top right of my monitor when emails are received.
  4. Sharing is fast and easy.  This email client allows you to integrate with DropBox to share files without having to attach them.  Instead it uploads to the cloud and provides a link to your recipient for them to access it.
  5. The conversations feature of Gmail is also available making it easier and faster to browse mail and respond quickly.
I've been using it steadily for the past 2 weeks and have not experienced any issues yet.  

The only downside to this application was that it cost me $9.99 to purchase.  Which normally isn't bad, especially when it's worth the price.  I don't mind supporting developers who have done a fantastic job. 

Update:  I did recently find out that back in July 2012 Sparrow was purchased by Google.  This is good news for the Sparrow team but probably not so much so for the Sparrow application.  Undoubtedly Google will use the team to work on other projects involving email and let the application degrade.  Which is exactly what we saw when Google released it's upgrades to it's Gmail mobile application a couple days ago.  

For now I'm extremely pleased with the application and hoping that development will continue forward, regardless of what company owns the software.

Got anything better that you'd like to recommend?  Let me know! 

Invest in Yourself - Run a Marathon

Last year my friend and colleague, Alex, signed up for the Baltimore Marathon. The Baltimore Marathon is a popular 26.2-mile long course that travels through the heart of Baltimore and attracts around 5,000 runners each year. Alex wanted to use the Marathon as a motivator for getting himself out of bed every morning and hitting the streets so that he could shed the 40+ pounds that it would take him of achieving his goal weight. Loosing 40 pounds is no small feat, nor is running in a full marathon, but Alex wanted to do both. And that's exactly what he did. 

Alex told me of the mornings he would get up at 5:00 AM to get himself dressed and go out for his morning runs. His weekly workout regiment was to run 4 short runs (easy or tempo runs), 1 long run (10+ miles increasing by 10% each week), and 1 bike ride (15+ miles) for cross training. If he got too tired or his body ached too much he would take a few days off so he could avoid injury. For 9 months, starting in February 2012 until October 2012, Alex kept this pace until the Baltimore Marathon occurred. Alex ran his race and he finished in a little over 4 hours and 17 minutes, which is a pace of 9:50 per mile!

Alex truly showed me what anyone could do if they have the will and desire to invest in themselves. Alex has 2 little girls, a wife and a demanding job as a software project manager. Training for a marathon takes time, especially long runs that could take over 4 hours to complete. However, his family didn’t sit idly by; instead they coached him by showing their support and giving him confidence that he needed more so than hydration (which is a must).

Before the race Alex lost the 40 pounds and achieved his goal. He even gained a better understanding of eating right and how fun running can be. However, a month after running in the Baltimore Marathon he was hit by a car during one of his weekly bike rides and injured his knee. The doctor told him that he would have to stop the running, but could continue biking. He was glad that he could continue working out, even if he couldn’t run in another marathon.

On a funnier note...

Before Alex told me about his goal of running a marathon and his new running hobby I thought he might have been experiencing some major health issues. During our weekly status meetings I noticed that he recently buzzed his hair and continued to loose weight. His cloths were really baggy too. Then one day, it struck me – he’s got cancer! Just by coincidence, a couple days later Alex came over and began talking to me about his new workout regiment. I immediately was relieved and then amazed at how hard the guy has been working.  Kudos to you Alex and to your family who supported you!

After talking with Alex a few times he invited me to run with him in the marathon.  But it was much too late.  I would only have 9 weeks to train in and I would probably have injured myself I did.  It was a good call.  However, it did inspire me to go ahead and register for the 2013 Baltimore Marathon.  For the last 2 years I've thought about it and I kept telling myself that I need to build up to it, build up my mileage, and I need to get comfortable with a half-marathon (13.1-miles).  Well I did that last year and I no longer have any excuses.  I'm doing it. 

Monday, March 11, 2013

Google has Updated Gmail's Mobile App

This morning Google released updates to the Gmail mobile app for Android, iPhone, iPad, Blackberry, and Kindle Fire users.  The improvements are nice touch to an interface that has went far too long without a makeover.  The pale blue colors of the older interface are gone and replaced with a smooth, crisp, look and feel that is very similar to the Sparrow email client that was developed for the iPhone.  Which isn't surprising since Sparrow was recently purchased by Google in July 2012.




The Gmail client still allows users to work in both an online or offline mode.  Users can also label emails, move to folders, mark as unread, or mark emails with a star to remember for later.




The only feature that this interface is still missing under iOS is the back and next buttons.  Android has the back button built into the hardware but this is still a nice feature that should be a native application function.

I'm glad to see Google updating their user interfaces.  If only they could update their regular email client, along with their Calendar and Contacts applications.  The Sparrow team has done well with this interface... hopefully they continue.  :)

Thursday, March 7, 2013

Telecommuting Is Here to Stay

Recently the new CEO of Yahoo!, Marissa Mayer, put out an internal memo banning employees from the right to work remotely.  Mayer's decision to do this was based on the desire to increase company productivity and have better communications.  I agree that there is a benefit to working closely with other software developers.  The ability to bounce ideas off of one another and help inspire and teach each other is highly rewarding, both to the company and to the employee as a professional.  It's also true that developers sometimes need to better communicate with each other and with customers.  However, I disagree in the way that Mayer chose to orchestrate these changes.

According to the memo issued by Jackie Reses, the head of HR at Yahoo!, she states that:
Beginning in June, we’re asking all employees with work-from-home arrangements to work in Yahoo! offices. If this impacts you, your management has already been in touch with next steps.
This means that everyone who works remotely, stay-at-home mothers, people who live offsite, etc., all need to report to a Yahoo! office.  This seems to be a quick-fix type of solution to a cultural issue at Yahoo! with communication and productivity.  The company obviously has issues with people taking advantage of the right to work from home.  Many companies do.

Just the other day I had an issue with an employee who didn't want to show up for a meeting.  Instead this person wanted to call in.  Under usual circumstances of the person being out of town on business or at home with a sick daughter (which I had to do on Tuesday) I understand the need to work remotely.  However, this person was literally 15 minutes away from the office, at their home.

Taking away an entire company's right to work remotely should be a last resort.  And perhaps it was Yahoo!'s last resort, but it should have been a issue discussed with the employees instead of a top-down command from an executive.  Employees are a company's most valuable asset.  Treat them as such.  Talk with them over social media - Facebook, Google+, etc. instead of issuing a 20th century memo.

Regardless of what's going on at Yahoo! telecommuting is here to stay.  Here's why...

According to Global Workplace Analytics, who has aggregated data from over 500 studies, here are the main reasons for companies to pursue or keep work from home programs:

  • National productivity would increase by $334 billion to $467 billion a year through telecommuting.  Based on the average teleworker salary, the increase would add up to over 6 million man years of work.  Cost savings could bring back many jobs that have been lost to foreign labor.
  • Telecommuting reduces traffic jams.  Traffic jams ob the U.S. economy of $78 billion/year on productivity.
  • Telecommuting reduces our foreign oil dependence by saving 281 million barrels of oil worth $22 billion in oil imports while slowing global warming.
  • Telecommuting takes pressure off our crumbling transportation infrastructure.  New roads are being built based on the needs of 10-20 years ago.  Less that 6% of our cities have kept the pace with demand over the past decade.
  • Employees are happier with telecommuting.  79% of people want to work from home and 36% would choose it over a pay raise.  80% of employees consider it a job perk.
  • Telecommuting reduces attrition.  14% of Americans have changed jobs to shorten their commute.  46% of companies that allow telecommuting say it has reduced attrition.

They also list the fallacies of telecommuting, but the list of pros far exceeds the list of cons.

Ultimately the decision to allow employees to work from home must be done on a case by case basis.  Not all employees are self-directed enough to get things done and ignore home distractions.  But there is a strong case with plenty of evidence to conclude that telecommuting is good for both employees and the company.  I'm certainly in favor of it and I hope managers of other companies see it's value.