Home / Archive by category "Programming" (Page 3)

Connecting to the Google Calendar API from C# or VB.NET

The Google calendar API is at its root very powerful, but you have not worked with XML/HTTP, cookies or authentication in the past learning the raw API can be  daunting. Fortunately Google provides a free .NET library, so you can interact with a user’s Google Calendar using intuitive .NET classes and methods.

To get started, download the .NET client API from here:


Add references to the Google libraries in your project, and use or import these in your code

using Google.GData.Client;
using Google.GData.Calendar;
using Google.GData.Extensions;

The library provides a “Service” class to handle connecting to and authenticating with Google:

Service service = new Service("cl", "companyName-appName-1");
service.setUserCredentials("useremail@userdomain.com", "userpassword");

You then execute a query on the service. The query will return a list of AtomEntry objects, which are handy wrappers for standard RSS Atom entries. For example, this returns a list of all items in the user’s calendar:

FeedQuery query = new FeedQuery();
query.Uri = new
AtomFeed calFeed = service.Query(query);
foreach (AtomEntry entry in calFeed.Entries)

There are similar methods for adding, updating, or deleting calendar items. For example:

AtomPerson author = new AtomPerson(AtomPersonType.Author);
author.Email = "useremail@userdomain.com";
entry.Title.Text = "Lunch at Bully's";
entry.Content.Content = "Eat lunch with Fred";
When eventTimes = new When();
eventTimes.StartTime = DateTime.Parse("7/13/2009 12:00:00 PM");
eventTimes.EndTime = DateTime.Parse("7/13/2009 1:00:00 PM");
Uri postUri = new Uri("http://www.google.com/calendar/feeds/useremail@userdomain.com/private/full");
// Send the request and receive the response:
AtomEntry insertedEntry = service.Insert(postUri, entry);

Google provides extensive documentation and sample code, in a dazzling variety of languages. Even Objective-C for you Mac developers.

As with any scenario where the data can be updated from multiple locations, your application will have to implement synchonization logic. The items you upload one day could be deleted from the web or from the user’s iPhone before your next sync. But fortunately the sometimes daunting task of communicating with the remote service is trivial in this case.

A Handful of New Web Application Tools

  1. People like graphs. A graph or a chart can show exactly the same data as a table, but in a far more efficient and human-friendly manner. HTML is great at displaying tabled but not at charts, but now we have a very simple jQuery plugin that will generate charts and graphs directly from HTML tables. Just install the jQuery visualize plugin and call a table’s .visialize() method, and viola – instant charts. Yes, it’s really that easy. Put it on one of your sites today, tell your boss it took hours, and take a long lunch instead.
  2. Need to do a screen capture of a web page, but away from your regular computer? With Aviary’s Talon, you can do a screen capture of any web page directly from a web browser. I can see using this is you need to do screen captures from a portable device like an iPhone or netbook PC, or if you want to do a screen capture for a different screen resolution.
  3. Ruby on Rails developers should really check out LESS – an “extension” to CSS that adds what CSS should have such as variables.
  4. Anemone is a free, multi-threaded Ruby web spider framework from Chris Kite, which greatly simplifies your web spiders. For example:
require 'anemone'

Anemone.crawl("http://www.example.com/") do |anemone|
  anemone.on_every_page do |page|
    puts page.url

Programming for the MagTek USB Credit Card Readers

If you are tasked with integrating credit card “swiping” into a .NET application – I strongly suggest starting with the Magnetic Swipe Readers (MSR) from MagTek. While your mileage may vary, this is the one product I have been able to integrate with my application easily, and without any additional libraries or cumbersome third party libraries. That is, provided you remember two things:

  1. Purchase a HID (Human Interface Compliant) version of the MSR – NOT a keyboard emulation product. And
  2. Download the excellent HIDLibrary from Mike Obrian, which provides all the code you’ll need for inetgrating the reader into your .NET application.

There are no third party libraries or software needed. Windows should recognize the reader as a HID device when it is plugged in, and the HIDLibrary code should be able to interface with your reader. There are even samples and classes specific to MagTek MSRs on the library download page.

You will need to do a little research into the data format for credit card track data – data comes in a long binary array that must be converted toa  string, then parsed to separate the tracks and account number data. Here is a document describing the data format for credit card tracks to get you started.


HIDLibrary has been moved to GitHub, and updated since this post.

Payment Processing: An Introduction

For the past several weeks, I’ve been tasked with integrating payment processing into a desktop program. In the past I have added payment processing to several web sites, but integrating with desktop applications introduces many new complications. Not the lest of which is hardware, hardware, hardware. The good news is that you can buy just about any payment processing hardware you’ll need on eBay for about 5-25% of the retail cost. This makes it easy and very cost effective to add support for a multitude of devices in your application, if clients require that. The bad news is that many of these devices require a unique API, and come with scanty or no documentation. But once you get everything working together it’s a beautiful thing. Payment processing is the lifeblood of any business, and by making it more efficient, cost effective, and less error prone you are doing your clients a great service.

This will probably be the first in a series of posts on the subject, so here are my initial observations.

Any Payment Processing solution requires at least two modules:

  1. Data Input: This could be as simply having users enter credit card or EFT (banking) information into a form. However, if at all possible you should support a hardware-based solution such as a Magnetic Swipe Reader (MSR) or Magnetic Ink Check Reader (MICR). For credit card transactions, most payment gateways provide significantly lower fees for swiped credit card transactions due to lower error and fraud rates. While the fees for EFT transactions may not be lower for your payment gateway, the ease of use and lower error rates make MICR readers a great addition to your application.
  2. Payment Gateway: Once you have the users credit card or bank information, your application must communicate with a payment processor or gateway that handles all the details about validating the card, funds, and transferring funds from the customer’s account to the merchant account. In my experience this is the easy part – most payment processors supply a rich and well documented API compleet with sample code, controls, and libraries. If they do not, choose a different one!

6 Amazing Techniques to Staying Happy During a Stressful Project

Another good post from Zen Habits. Here’s an excerpt:

2. Break The Project Down Into Tiny Chunks
The length of my list on any given day would scare even Warren Buffett. I expect too much and never feel satisfied.

Instead of getting a whole bunch of stuff done, my brain often shuts down in response to my overwhelming list. I need to figure out a way to reduce those negative thoughts by listening to them and reasoning with them. I have tried being a big bully and forcing myself to do work, but this technique always lacked results.

I’ve created a routine that allows me to handle my work load. When I realize that I have overextended my “to do” wish list, I stand up, breathe deep, and let out the air as I take a moment to refill my glass with water.

I then break down my first big task into twenty minute chunks. When the project seems more manageable, I pick an easier 20 minute chunk and accomplish it. By doing this I boost my confidence and get my emotions back into a positive state.

Mishmash of recent discoveries

Cleaning out my google reader feed, I came across a few discoveries that will help any web designer or coder:
How to Get Started with iPhone Dev

This is by far the best introduction I’ve seen to iPhone development. If you’re a traditional Windows or web programmer without much experience coding for the iPhone, this is a great place to get started. If you’re coding a full iPhone application or just optimizing a web site for the iPhone/iPod platform, you’ll want to read this page and bookmarka  few of the links it points to.


Royalty-free “submit” buttons. Seriously, it doesn’t look like there’s not much to this site, but he provides the original PSD files for each shiny, glossy button. Save oodles of time designing buttons for your web site.


Now that you have shiny buttons, you need spiffy backgrounds.


Manga-style twitter avatars, anyone?
5 Easy ways to get Solid Backlinks to your Site

Most traditional SEO is wrong. If you’re looking to build more links to your web site, this is an excellent place to start.


I recently completed a project using CodeIgniter, “an open source web application framework that helps your write kick-ass PHP programs”. In short, it’s for PHP as Rails is for Ruby – a simple yet powerful framework for writing MVC (Model-View-Controller) web applications. I’ve worked with other application frameworks in PHP before, but CodeIgniter was the first that I’d voluntarily use again. Most frameworks are horribly bloated tools that take far too long to learn, setup, and deploy.

CodeIgniter is a breeze to set up. It is entirely self-contained, so all you need to do is download the zip file, extract, and upload to your server. There is one configuration file to edit for your application, one to edit for your database, then you can start adding your code. If you’re familiar with the MVC style of coding everything quickly falls into place. If not, it seems like an excellent way of learning MVC.

The one small gripe I have is that the documentation could be better, and I’d rather it not be included in the default download. ther than that it’ a fantastic framework, even for your smaller projects.

Simple tips to land more freelancing jobs

For years I’ve done a little consulting or freelance work on the side. The variety helps break up the monotony of the Day Job sometimes, and of course the added money is always nice. It seems that despite the so-called “bad economy” and “evils” of outsourcing, it is still quite easy to find freelancing work today. Here are few tips I’ve found useful:

  1. Familiarize yourself with the basics. There are at least half a dozen major web sites that help freelancers hook up with jobs on-line. Scriptlance, RentACoder, and eLance are just a few that pop to mind, but there are many others. All of these work in a similar fashion – freelancers fill out a profile and bid on projects posted by employers. Sometimes it is free to do so, and sometimes the sites take a percentage of any final project.
  2. When signing up for any one of the numerous on-line job boards, take the time to fill out your profile in detail. Take as much care in setting up your profile as you would a resume for a job you really want. The best employers will take the time to read your profile in addition to the bids, so make sure it’s good.
  3. Think about what the employer is looking for, and if you are truly the best fit for this job. Often employers are simply looking to outsource a job for $20 that would cost $1000 to complete at a fair wage. Others are looking for free services, or others are proposing jobs that would require a large team of programmers. Don’t be tempted to take on work that is beyond your skills, or would not be worth your time.
  4. Ask questions, and engage in a dialogue. The simple act of asking for clarification on a project shows that you took the time to read and understand what the employers has posted – unlike most other bids that are a simple copy and paste.
  5. Proofread, and use proper spelling and grammar. Since you are competing with hundreds of shops overseas, the simple act of appearing professional and fluent in the language can give you a leg up over most other bids.
  6. I posted about this in the past, but don’t forget to make use of twitter. This can be one of the most efficient ways to find jobs quickly.
  7. Also, don’t forget about craigslist. You can set up a simple RSS feed of any search in craigslist to find part-time or telecommuting work in any craigslist city.
  8. Finally, shy away from any projects that seem vague or ill defined. If the employer cannot clearly explain the project in the initial bid, there is a very good chance that the job will end up being far more complex that you imagine. A post for “simple web site” can easily turn into a nightmare if ill-defined.