Mon, 31 Aug 2009 15:30:00 GMT

Setting Up a Repository on GitHub

GitHub offers free open source project repository hosting using the git protocol. Git is specifically designed for distributed development of software.

Creating the Repository
To create repositories on GitHub, you'll need to create an account. Once you have an account you can go to your GitHub homepage and click the link to create a new repository. Fill in the name of your project and optionally, a description and project URL. Now you have a repository.

Setting Up Shared Keys
Git connects much like ssh and uses shared keys to confirm the remotely connected computer is who they say they are. For your local git to connect to GitHub it is necessary to generate a shared key and tell GitHub what it is. To generate you own shared key, follow the instructions below:
cd ~/.ssh/
ssh-keygen -t dsa
You can hit enter through all of the prompts. You will now have two files: id_dsa is your private key and id_dsa.pub is your public key. The contents of id_dsa.pub is what GitHub need to know. On your GitHub account page there is a link to add a public key. Click that and copy the contents of id_dsa.pub into the key field and add a name to designate what computer the connection will come from. Then click the add key button. You can now connect to GitHub.

Setting Up Git
You will need to tell git your user name and email so that it can appropriately attribute your code contributions to the repository. You can do this with these commands, filling in your own information where necessary:
git config --global user.name "My Name"
git config --global user.email "MyEmail@SomeHost.com"
Note: This has set the settings globally. It is possible to set this up per project.

Commiting to the Repository
Now you need to go to the root directory of your project. If you don't have one yet you should create it. Then you can use the following commands to commit your initial project to GitHub, replacing with your GitHub username and with your repository project name on GitHub:
git init
git add --all #only do this if you have files already
git commit -m 'first commit'
git remote add origin git@github.com:/.git
git push origin master
You have officially set up your local repository and set the master to your GitHub repository.

Working with Git
From now on you can commit to your local repository with the following command:
git commit -m "A message explaining what you did"
Then, to push it to GitHub use the following command:
git push

Sun, 30 Aug 2009 14:24:00 GMT

Javascript Key Events

I just recently spent a while learning the mechanics of key events in javascript. There are many incompatibilities between each of the various browsers, which makes the task somewhat difficult.

Getting the Key
The first problem I encountered was how to get the key from the event. Internet Explorer uses event.keyCode to store the numeric representation of the key. Mozilla historically used event.which, but now uses either event.keyCode and event.charCode depending on the circumstance. However, event.which is still supported and always contains the key code, whereas only one of either event.keyCode or event.charCode contain the key code. Because of these oddities, it is necessary to use some logic to figure out exactly what has the key we want. For that we do the following:


We can check if event.which exists. If it does we are on Mozilla and will get the even.which property to get the key code. If it doesn't exist then that means we are on Internet Explorer and we need to check the event.keyCode property.

Difference Between Key Events
Keyup and keydown are rather different from keypress. Both keyup and keydown's key codes map to the specific keyboard that the user is using. Meaning there is no consistent way to determine the key between any two computers. However, the keypress event behaves differently. Instead of the storing the numeric representation of the keyboard key, it stores the UTF-8 encoding of the character which is easy to determine across different systems. The lesson here is that if you want to know if a key was pushed or released, but don't care what it is, you can use keydown and keyup. When you must know the key value that is being typed using keypress is the only reliable option.

Shift Key
All browsers have support to figure out if the shift key is being pressed for each of the event types. The problem is that there is no way to tell what the original unshifted key is, because the event will only tell you the shifted key code. For letters, it is simple to convert back to lowercase with String's toLowerCase() method, however, for the number and symbol keys, the only way I could think of is to have a translation table. As a result I came up with this:
However, I'm using an American standard keyboard. If another keyboard setup has other keys that are modified by the shift key, this will not solve the problem.

I discovered all of this while writing an extension to the Prototype framework. I'll be releasing this on GitHub under the name of blacksmith in the near future. The project home will reside here.

Fri, 28 Aug 2009 23:09:00 GMT

Creating a Rails App (Ritter2 Part 1)

Note: This guide assumes you already have Ruby, Rails, and MySQL set up. For an excellent guide on how to do so look here.

Create a Project
This will be the first part in my series on how to create a Twitterish Rails application. The steps here are for creating this application, but they can also generally be used for any Rails application. Just about every Rails application has the same basic setup. The first thing you want to do is actually create your application. On the command line type:
rails -d mysql ritter2
That will generate all of the basic files you need for your application. I specified that I wanted to use MySQL as my database. The default for Rails is SQLite.

Start Your Application
At this point you have a working Rails site, but it doesn't do much. Go into your ritter2 folder and enter the following command:
script/server
That will start up an instance of your application, which you can access at http://localhost:3000. Nothing too exciting here, except that you have a running server in two commands. Go ahead and kill the server with Crtl-C.

Setup a Database User
Now we're going to setup the database for our Rails application. The first thing I always do is generate a new user for my Rails application to use. You can do that with the following:
mysql -u root -p
You will be prompted for your MySQL root password. After that you can enter the following commands:
grant all on *.* to  "ritter2"@"localhost" identified by "ritter2";
exit;

Setup Rails Communication to the Database
Now we need to tell Rails how to connect to the the database. We do that in the database.yml file in the config directory of our application. Open that up and put in the username and password for each database. Here's an example:

Create the Database
Now we want to tell Rails to create the databases. To do that run the following command from the application root:
rake db:create:all
That will create your databases for you.

In the next part of this series I will go through some of the key aspects of setting up authentication for a Rails application.

Tue, 25 Aug 2009 13:39:00 GMT

Some Words Bare Repeating

When I was in elementary school we had a special speaker come. He was a story teller who had an odd trait. He would repeat everything he said three times. Finally, he explained this to us. He said the first time was so that we would hear it, the second time was so we would listen, and the third was so that we would remember it. He repeated the explanation three times and needless to say, I never forgot it.

Marketers have the same sort of goal as that story teller. They want you to remember what they tell you so that you will use that information when you make a purchase. It used to be true that they could do that directly through advertisements. That is no longer the case anymore, since very few people let a marketer get past the hear stage. Seth Godin's concept of permission marketing is one example of a way to bridge the gap from hearing to listening and the purple cow is a great way to get that permission. The next gap is covered by the idea virus of your purple cow.

You as a marketer are not the person who will make people remember your product. Direct advertisements do not work. The only thing you can do is get people to listen. Once you have done that, the people who have listened will make others remember for you.

If you want to learn more about the purple cow and ideas that spread you can check out my notebooks section where I'm currently taking notes on Seth Godin's Purple Cow.

Mon, 24 Aug 2009 15:53:00 GMT

Reading List

I just wanted to write a quick post and let everyone who is following this know that I have updated the notebooks section with books that I am planning to read. If you have a suggestion of a book that I should read and write up notes for, leave me a comment. If it sounds like something I am interested in I may add it.

Sun, 23 Aug 2009 20:21:00 GMT

Ritter

Once upon a time I wrote a Rails application called Ritter. It was for my Principles of Information Systems class and in my opinion exhibited everything that class was about. It is a twitter clone (approximately) smashed together with my alma mater, RIT. Anyways, the reason I bring this up is because I'm planning on writing a series of articles on how to write a similar application.

If you want to see a live demo you can check it out here.
The source code is available on github.

Sat, 22 Aug 2009 14:58:00 GMT

Notebooks

I watched a wonderful video post on Charlie Hoehn's blog where he describes how he takes notes on every book he reads. It allows him to have the best knowledge from dozens of writers nearby and on hand in his trusty notebook. I really like this idea. I have read quite a few books that were amazing and invaluable in helping me be the person I am today.

I'm a bit more technically minded than Mr. Hoehn though, so I've decided to use evernote.com to record all of my notes. The side benefit of this is that I can also share these notebooks with the world. Each of my notebooks will be categorized by topic (eg, marketing, fitness, etc...) and each note in the notebook will reference a different book. Currently I have a marketing notebook and the first book that I've started this process for is Seth Godin's Purple Cow.

You can access my marketing notebook here.
My list of note books can be accessed here.