Archive for April, 2011

Installing Git on your Mac

Saturday, April 23rd, 2011

Github rocks. I started using it about a year ago and it has already saved my ass, I mean my code, from two computer crashes. Github is a service that lets you back-up and control versions of all documents associated to a project.

Git was created to support the Linux project. It is extremely powerful, it was built to enable collaboration between multiple users and even lets users create more than one concurrent version (or branch in git lingo) of the project. I use only a small part of the functionality offered by git,

I am currently working to set-up Github on my computer so that I can restore the code I lost during my most recent computer crash. Since I am having to re-learn the not-so-simple process of installing Github, I decided to create this simple tutorial to document my learnings.

My motives are only partially altruistic, I know at some point in the near future I will either need to restore my own code again and I’ve already had a few people ask for help to set-up GitHub on their computers. Here are the official installation instructions from GitHub.

Time Requirements: the answer to this question depends on what software you have loaded on your computer. If you have none of the required software it can take up to 5 hours (downloading Xcode can takes several hours). If you have all of the required software it can take you as little as 30 minutes.

Software Requirements: before you can install Github you need to have MacPorts loaded on your computer, but before you can do that you need to install Xcode. So start off by downloading both. You can download MacPorts from the link below. You will need to purchase Xcode from the app store on your mac. I recommend that you download the latest version of both to ensure that they will work together.

link to Xcode website |  link to MacPorts website

Note: Xcode takes several hours to download because it is huge (over 4GB). You can also get Xcode from your Mac install disc, though it probably won’t be the latest version and this could potentially cause issues.

Installing Software: once you have downloaded Xcode and MacPorts you are ready to get started. Github is installed by running a Unix command on the Terminal utility (more about the Terminal utility below the installation instructions). If you have Xcode and MacPorts installed in your machine skip to step 2.

  1. Install Xcode and then MacPorts to set-up your computer
  2. Open the Terminal utility, which can be found in the directory “Applications/Utilities”
  3. Type “sudo port install git-core” into the Terminal and press enter
  4. When prompted enter your password and press return (password will not show up)
  5. Wait for the installation process to end, which can take more than an hour depending on your internet connection

Terminal is an application that is included on all Macs. It provides users with access to the Unix kernel, so that they can run Unix commands and scripts. In order to use GitHub you will have to familiarize yourself with some basic Terminal commands. You will need to keep the Terminal utility open for the rest of the setup. Here is a link to one of my recent post with an overview of basic Unix concepts and commands.

Setting Up Github: once you have installed git you need to set your name and email address. This information will be used to sign files when you save them (or commit in git lingo) to a git repository on your computer, or upload them (or push in git lingo) to a git repository online. To set your name and email use the commands below on the Terminal.

git config –global user.name “your name”
git config –global user.email “your_email@email_server.com”

Downloading from a Repository: To download code from an existing repository you first need to get the project’s git URL. This URL can begin with “ssh://”, “http://”, “git://” or just a Github username. Then type the command below into Terminal utility and press enter. Git will create a new directory with the name of the project, and download all of the project files into that directory.

git clone http://www.sample_url.com/sample_folder/sample.git

Creating a New Local Repository: To create a repository from an existing project you need to navigate that project’s directory using terminal.

In the Terminal utility you can navigate through directories (or folders) using the “cd” command. Typing “cd folder_name” takes you to a folder called folder_name that exists within the current folder; typing “cd ..” takes you to the folder that contains the current one. You can also use the “ls” command to get a list of all the folders that are contained in your current directory. Once you have reached to the appropriate directory just type:

git init

Git will reply with “Initialized empty Git repository in .git/” and you will notice that a new hidden folder labelled .git has been added to your project’s directory.

Backing up to Local Git Repository: Once you have a git directory set-up it is easy to back-up your project, and restore it when needed. Here are the basic overview of the process and commands that you will need to use.

First you need to add your files to the staging area using the “git add” command. You can add a single file to the staging area using “git add filename”, or you can add the entire project to the staging area using “git add .”

Once you have added files to the staging area you will need to use the “git commit” command to add the files to your local repository. This command will move all files on the staging area to the repository. When typing this command you can use the -m modifier to add a comment about the updates that have been made to the project. Here is an example:

git commit -m “this area can feature information about updates to the code”

Online Repositories and Advanced Functionality: With this basic knowledge you can create local repositories for version control. This is all I am going to cover today. However, to take advantage of the full benefits provided by git you will need to learn how to restore your code to a previous version and how get set-up to use an online repository. Here are some helpful links for you take these next steps:


Unix on Mac: Command Line Basics

Saturday, April 23rd, 2011

I started using Unix on my Mac about a year ago. I am still a novice at using the command line but I have come to realize how powerful and useful this interface can be. To learn how to use the command line I watched two videos from the PeepCode screencast website – videos number 34, command line basics, and 37, advanced command line. Below is just a short overview of the most important concepts and commands.

Unix
Unix is multitasking and multiuser operating system that is based on a hierarchical data structure. Now a days, most computers can handle a large number of tasks and users; however, when Unix was originally developed this was not the case. One interesting thing about the design of Unix is that the system handles everything as though it were a file. This means that folders and executable files can be copied, read, moved, deleted and processed like a text file. Mac’s version of Unix is called Darwin (many different versions of Unix exist).

The Terminal Utility
To access Unix on OS X there is an application called Terminal that comes standard on all Macs. This command line app provides access to Unix via a text based interface. The benefit of using Terminal is that you have access to all of the power of Unix; the downside is that the interactions are all text-based and there is little feedback provided when commands are executed.

So now let’s dive into the terminal interface and go over many common commands. Here is a screenshot of my Terminal window. The first thing worth noticing is that the command prompt contains three important pieces of information: (1) the system name followed by a colon; the (2) the current directory followed by a space; last, (3) the current user name followed by a dollar sign. Here is an example from the screenshot bellow: “Julio-Terras-MacBook-Pro:Farm-Bridge julioterra$”. As you can imagine, the information contained in these command prompts is quite useful.

Unix Commands
It is useful to think of Unix commands as scripts or applications. The structure of most unix commands is as follows: [command] [modifier] [source] [destination]. The first two parts of this structure hold true for all commands. Modifiers are always preceded by a dash (-). The third and fourth elements are only used for relevant commands. Here is a list of the most common commands along with relevant modifiers – all of these commands are case sensitive (Here is a link to a useful wikipedia list of Unix commands).

One important characteristic of Unix systems is that when a command is successfully executed then the system does not return any information (they usually only return error messages unless the user requests a ‘verbose’ output, more on this later).

Now here is a list of common Unix commands:

  • “help” – the help command returns a list of the most common commands available.
  • “pwd” – returns the full path of the current directory
  • “cd” [path] – changes the current directory to the specified path. There are some special characters that can be used to navigate directories: “~” always refers to the root directory; “.” refers to the current directory; “..” refers to the parent directory.
  • “ls” [modifier] [path] – returns a list of the files in a given directory. The path argument is optional, if no path is provided then the command returns the files from the current directory. Common modifiers include: “l” returns more detailed information about each file; “a” returns all files in a directory, including the hidden ones; “h” when combined with “l” returns the same info as “l” by itself but it also provides more details regarding file sizes.
  • “chmod” [modifier] [source] – changes the access privileges associated to a file or directory. To understand the modifiers for this command you need to understand how access privileges are managed in Unix. There are three separate sets of access privileges that are available for any given file or directory: read (“r”), write (“w”), and execute (“e”). These privileges can be set for the user (“u”), group (“g”), others (“o”) or all (“a”). The character “+” is used to add privileges, while “-” is used to remove privileges.
  • “cat” [source] – known as the concatenate command it reads a file and outputs the content to the terminal window.
  • “cp” [modifier] [source] [destination] – copies the file or directory identified as the source to a location and name identified as the destination. It is important to note that if another file exists with the same name at the destination then that file will be overwritten. List of useful modifiers: “i” to prompt user before system overwrites another file at destination; “r” means recursive and is used to copy a directory along with all of its contents.
  • “mv” [modifier] [source] [destination] – command to move a file or a directory from the source to the destination. This command is also used to change the name of a file. Useful modifiers include: “i” to prompt user before system overwrites another file at destination; “v”, which stands for verbose, to inform user of the activities that system is doing in carrying out this task; “n” to ensure that the system does not overwrite any files in the process.
  • “rm” [modifiers] [source] – command removes files from the source location. Useful modifiers include: “i” to prompt user before system removes any files specified; “r” to instruct the system to remove all files within a directory (otherwise, the “rm” command is only able to delete empty directories).
  • “mkdir” and “rmdir” [path] – these commands can be used to create and delete a directory respectively.

To get help with a specific command you can often use one of the following modifiers: “–help”, “-help”, or “-h”. Unfortunately, the help feature is implemented in an inconsistent manner across commands so you may need to try all three options, and sometimes none of them will work.

The last important item that I want to cover is the concept of “pipe”. Pipe is a functionality in Unix that enables a user to pass the output of one command to be processed by another command. The “|” character is used to identify a pipe linkage. One command that is often used with a pipe is the “more” command. This command makes it so that a the system only outputs on screen’s worth of content at a time (the user needs to press return or the space bar to request that the system display more content). Here is how a pipe could work: “cat filename.txt | more”

That’s all for today.


Learning to Make a PCB

Wednesday, April 20th, 2011

Over the past few weeks I have been working on creating my first PCB (printed circuit board) for a project called Emote. The process has been extremely rewarding, though at times also frustrating. The potential offered by using PCB is pretty amazing. It makes electronics much smaller and opens up numerous design possibilities.

There are many reasons why I wanted to design my own PCB: there are good free PCB design tools available, numerous high-quality tutorials for these tools exist online, and the cost of fabricating a PCB is pretty reasonable.

Here is a high-level tutorial with an overview of the entire process with links to the various resources so that you can learn how to make your own PCB.

Getting Set Up
The first step is getting set-up by downloading and installing a PCB design application along with the appropriate libraries and extensions. Here is a list of the applications I used, along with associated libraries and extensions.

Eagle CAD [link to site]. This is the design software where you can create schematics and boards. I found this application felt counter-intuitive at first since I am accustomed to Adobe creative suite type tools. After about 10/15 hours of use I got used to it and start to enjoy the work. What I am trying to say is that there is a learning curve but don’t get discouraged.

Sparkfun Eagle Library [link to download].  this library is extremely useful, especially if you buy stuff from Sparkfun. It also contains a large number of components that they use frequently on their own boards. If you plan to use any of the tutorials I list below then this is a must. Here is Sparkfun’s own description and instructions: “This is the collection of all the components SparkFun designs with and therefore components and footprints that have been tested. Unzip and place the SparkFun.lbr file into the Eagle\lbr directory. If the above link does not work, google ‘sparkfun eagle library’ to get the latest collection.”

Sparkfun Eagle CAM File [link to download]. This file should be used along with the Sparkfun library. Therefore, if you download the library file make sure to get this one as well. Here is their own description and instructions: “This file is responsible for creating the gerber files for submission to a PCB fab house. Place this file in the Eagle\cam directory.”

Sparkfun Eagle Shorcuts [link to download]. The shorcuts in this file are used in the tutorials that I reference below. I did not use them but you should make up your own mind on whether or not to download the file. “Place this file in the Eagle\scr directory.”

Though I only used the Sparkfun library in my project, there are several other libraries out there that you should know about. Here are the other two most popular libraries:
Lady Ada’s Eagle Library [link to webpage]
Microbuilder’s Eagle Library [link to webpage]

Designing a PCB
Once you have installed the software and placed the library and extension files in their proper locations, you are ready to start up Eagle. As I next step I recommend that you go through the Sparkfun tutorials, which are easy to follow and comprehensive.

Eagle, an Overview. Before you jump into the Sparkfun tutorials here is a quick overview of how Eagle is set up. This high-level overview will provide some context for the tutorial links featured below.

Eagle handles the design of components and boards separately. Components are always created within libraries. In order to create a new component you need to create a new library, or add the component to an existing library. Boards are created within projects. It is important to note that the term board is used to refer to one of the standard views within Eagle.

Components and projects all contain two standard views: schematic view and the board view. The schematic view provides abstracted information about a component or board. Component schematics are comprised of pins, outlines and labels; board schematics are composed of components, electrical links between components, outlines and labels.

The board view provides an accurate model of the physical features of component or board. For a component the board view includes the physical location of the pads for each pin, the overall dimension, and any other important markers. For a board this view features the physical location of each component along with wire connections, drill holes, plates, and all other relevant specifications for fabrication.

When designing a component or project in Eagle you always create the schematic first. The schematic feature is actually a great planning tool for any DIY electronics project. Schematics are created first because they enable you to plan your circuit conceptually before working on the physical design.

Sparkfun Tutorials. Now that you’ve got a rough understanding of how Eagle works here are some tutorial from Sparkfun that will walk you step by step through the process of creating a schematic, design a PCB layout, and making a custom part for your project. I’ve also included a link to a tutorial where they share common issues they’ve encountered in during their many years of experience.

PCB Fabrication
Once you have gone through the tutorials above and finished designing your first board you will be in an excited hurry to get your board printed. You are almost there but be patient. Before I even get into the next steps I recommend that you do the following checks on your board:

  • Check all electrical connections to make sure there are no incorrect overlaps. It will cost you money and time if you don’t catch it before you fabricate.
  • Print out your board design on a piece of paper and check to make sure that the size of all components are correct, especially if you are using untested component designs.

Geber Files. To fabricate a board you need to generate Gerber files. The process for generating these files is covered in the Sparkfun tutorial about designing a PCB. These files are the industry standard for PCB fabrication. For a 2-layer board Eagle will generate 7 files (assuming you are using the Sparkfun CAM file). All files need to be submitted to the fabrication house.

Here is the extension for each Gerber file along with a brief description of its function:

  • GTL: top copper layer, holds location of electrical connections (i.e. ‘wire’)
  • GTS: top soldermask layer, holds edges of solder mask that protects from bleed overs
  • GTO: top silkscreen layer, holds text and lines that will be printed onto board
  • GBL: bottom copper layer, same as top layer but for bottom of board
  • GBS: bottom soldermask layer, same as top layer but for bottom
  • GBO: bottom silkscreen layer, same as top layer but for bottom
  • TXT: drill file, holds the location of all drill holes on the board

It is important to review your Gerber files before you send them out for production. Unfortunately, I have not found any good free Gerber file readers for Macs. There is a an online Gerber viewer available at http://circuitpeople.com/, unfortunately, it does not let you view multiple Gerber files layered on top of one another. If you know of a good Mac Gerber file reader please leave a link in the comments section.

There is a great online service at FreeDFM.com [http://freedfm.com] that processes Gerber files and provides feedback regarding issues, and even fixes some of the problems automatically. This service is provided by the guys at Advanced Circuits.

Fabrication Options. There are many different PCB fabrication houses around the country (and beyond our borders). Below I’ve included the two that have been recommended to me. Another option is to create your own PCB at home. Here is a link to a tutorial that shows you how to do just that. A few friends of mine have used this approach successfully.

First and foremost, Advanced Circuits [http://www.4pcb.com/]. This is where I will be sending my first PCB for production later this week. This place was recommended to me by Paul Rothman, one of the residents at ITP. They provide great deals for students ($33 full featured 2-layer prototypes), and they also offer really fast turnarounds on their bare bones boards.

Next up is BatchPCB. I have not used them either. I have listed them here because they seem to have an interesting business model and I have seem a lot of stuff about them on Sparkfun (I will admit much of it was their advertising).


Emote [Thesis]

Wednesday, April 13th, 2011

Its taken me a really long time to write this, my first post about my thesis. I decided on my current direction in late February. During the last month and a half I have been focusing my efforts on data collection and setting up the database back-end for this project. Without further delay here is an overview of the project. I plan on providing some updates over the next couple of days, stay tunned.

My Thesis in One Sentence: Emote is a platform for tracking my emotions and creating high-resolution visualizations that explore sources of meaning and fulfillment in my life.

Slightly More Informative Description: Emotions are important. They strongly affect how we experience reality by influencing our perception, choices and actions. Emotions are also messy and hard to measure. They are highly subjective short-lived phenomena created by interactions between physiological and cognitive processes in response to our psychological, social and physical context.

Emote explores methodologies for collecting and integrating high-resolution data about the physiological states, cognitive processes, and contextual factors associated with my emotions. To uncover insights from this data, Emote uses visualization approaches to highlight correlations between my emotions and activities, people, and places in my life.


Brains, Drugs & The Law

Friday, April 1st, 2011

This piece brings up interesting ethical questions about the use of cognitive-enhancing drugs to treat people who are healthy and ill. One of the most important consideration is of course: what are the side effects associated to the short- and long-term use of these drugs.

When examining the side effects of these drugs by healthy people we need to look beyond there effect on the individual’s health. We also need to consider the impact that use of these drugs will have on communities. Taking sports doping as an example, I don’t have any moral objections to the use of these substances as long as they are used safely.

That said, I also see the possibility that if doping becomes legalized then it may evolve into a requirement for athletes to be able to compete. Do we want that to be the case, for the use of cognitive-enhancing drugs to become a de facto requirement for success? The answer to this question will probably vary by on a case by case basis.

On a more recreational level, I believe that as long as a drug can be used safely then it should be legal. Of course, we should have similar social conventions to govern how these types of drugs can be used, such as is the case with alcohol and smoking.

This piece by William Saletan offers a really interesting perspective regarding the use of enhancement technologies in the world of sports. For the most part, when we talk about enhancement technologies and athletes we are usually referring to steroids. The case against steroids tends to be that it’s illegal, it’s harmful, it’s cheating.

This argument, which is often taken at face value, is rather dubious as Selaten points out. First off, the fact that steroids are illegal does not in and of itself mean that it merits this status. Second, most steroids when used by professional athletes are safe because they take them under close medical supervision. Lastly, if we are to consider this type of enhancement cheating, we need to take a close look at other types of enhancements that can be provided via surgery. As he points out in the article: “In the age of biotechnology, you are the device.”

On a personal level, this article opened my eyes (sorry for the pun) to the enhancement possibilities associated to LASIK surgery. In my family both my mother and sister have undergone this type of surgery. At the time I decided to pass on this opportunity since I only suffer from mild vision impairment. I did not know that LASIK could be used to enhance one’s vision beyond 20/20, and this fact actually makes me interested in finding out more about this possibility.

Lastly, my personal view regarding enhancement technologies in sports is that they are neither good or bad, and that the grand standing done in congress is of little value. That said, each sports league should have clear guidelines on what types of enhancements are allowed – especially, as the enhancements being used become surgical rather than ingestible.

This fascinating article from Jeffrey Rosen investigates the influence that neuroscience is beginning to exhibit on the American legal system. Over the past couple of decades new technologies have emerged for examining and altering brain functions (such as PET, MRI and TMS). Many of these technologies have already been used in legal cases. As the power of these technologies increase so does their potential for doing good and causing harm.

Rosen’s article points to the need for our society to have open discussions about the appropriate uses of these types of technologies. Many scientists and researchers who work in this field have wide-reaching visions about the potential use for these types of technology. However, it is crucial that the larger society engage in the conversation to determine what are appropriate uses and limitations for these kinds of technologies.

Though I do not object to neurology being used in legal proceedings outright, I currently do not feel comfortable with many of the proposed uses of this technology as illustrated in many of the scenarios from the neurologists interviewed by Rosen. Here are a few scenarios that concern me:

  • Having courts create a definition of a normal brain that works properly as a means to determine whether people are responsible for their behavior.
  • Enabling courts to use technology that is able to read and decode a person’s thoughts and memories.
  • Using technologies that alters a person’s neurological pathways in order to induce them to tell the “truth”.
  • Leveraging neurology to denitrify people with a proclivity for certain types of violent or illegal behavior.

These scenarios are frightening to me because I do not believe that our thoughts, memories, motivations and behaviors can be reduced to an analysis of our brain structure and/or activity. I would go so far as to state that we don’t even know whether our thoughts and memories reside in our brain or are only accessed by it. Another concerns is that by classifying how a normal brain functions and criminalizing (or marginalizing) brains that function differently, we will likely end up reducing diversity of human thought and eliminating possibilities for our society to evolve. Lastly, I categorically object to the idea that we should consider holding people responsible for what they might do, rather than only for actions they have actually done.

Reading 1: Professor’s Little Helper, Barbara Sahakian & Sharon Morein-Zamir, Link to Article
Reading 2: The Beam in Your Eyes, William Saletan, Link to Article
Reading 3: The Brain on the Stand, Jeffrey Rosen, Link to Article