Unraveling it all

It used to be in the good old days when programming for the web that you could just include a JS file and call it a day. The included file probably had all of the instructions you needed to understand what was going on.Probably.

It wasn't great, but it was easy to unravel what was going on. If you had a bug somewhere you could track it down fairly easily. Just look at where the error was coming from and track down the offending line of code that wasn't allowing snow to fall all across your page (or whatever other horrible script you were forcing on your users)

The web has evolved in a lot of great ways, but it's getting harder to debug. Here are some hoops I recently jumped through to debug a simple NodeJS undefined error:

  • Get this lovely error:

TypeError: Cannot read property 'name' of undefined at C:\Users\ddefreitas\Documents\web\nodejs\express.js:23:31 at Layer.handle [as handle_request] (C:\Users\ddefreitas\node_modules\express\lib\router\layer.js:95:5) at next (C:\Users\ddefreitas\node_modules\express\lib\router\route.js:131:13) at Route.dispatch (C:\Users\ddefreitas\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (C:\Users\ddefreitas\node_modules\express\lib\router\layer.js:95:5) at C:\Users\ddefreitas\node_modules\express\lib\router\index.js:277:22 at Function.process_params (C:\Users\ddefreitas\node_modules\express\lib\router\index.js:330:12) at next (C:\Users\ddefreitas\node_modules\express\lib\router\index.js:271:10) at Immediate.<anonymous(C:\Users\ddefreitas\node_modules\multer\lib\make-middleware.js:52:37) at Immediate.immediate._onImmediate (timers.js:590:18)

  • Ignore the 6 files that the error chained through (due to NPM magic I've never seen these files in my life)
  • Realize the error starts on line 23 on the file I was working on.
  • Get curious about offending line: console.log(req.files.file.name);
  • Print out the base object, realize there is no file property.
  • Go to documentation for NodeJS. Realize it I'm looking at the wrong documentation after searching and swearing for 20 minutes. My fault.
  • Look up the properties for the express api. Realize that none of the properties listed are named files.
  • Ctrl + f type in files
  • Find a note stating that I need to use the multer middleware (that thing I included and decided I would figure it out later)
  • Look up the description for it, find out it's written on top of busyboy (something else I will have to understand at some future point)
  • Eventually find the properties I was looking for so I can get by with getting a small proof of concept working.

I love the modern tools we have available, and the speed at which they allow us to build, but I can't help the feeling that I have too many black boxes built on top of each other just waiting to collapse.

Apr 28 2016

HTML: ID vs Classes

Recently I've been helping teach intro HTML and programming classes through the Philly GDI chapter. One of the big things that seems to stump beginners for a while is the difference between whether to use a ID tag or a class. When learning they seem to both do the same thing, however there are some key difference between them.

To start off a HTML class or ID can both be thought of as hooks that allow you to select an HTML element and do something with it. Formally these hooks are called selectors.You can use selectors in CSS to style a certain tag or to add some dynamic behavior to your site in JavaScript. In addition to tags and IDs you can use tag names as hooks to select an object. Which one do you choose?

The main thing to keep in mind is that IDs are meant to be unique and will only exist on one tag in your code. Common IDs are 'header', 'footer' and 'navigation'.Your site should only have one header, footer and navigation menu and because of that they are unique. Classes on the other hand are meant to be shared and re-used between different tags.

Here is a basic HTML layout of a bit of text in a poem:

Now I want this snippet of poetry to stand out some more so I want only the first line to be in bold.

One way of doing this is to apply an ID to the first tag:

<p id = "firstLine">I think continually of those who were truly great.</p>

In the CSS I can use a selector to apply the bold font face to just that paragraph with an ID of "firstLine":

#firstLine { font-weight : bold; }

You specify something is an ID by using the # symbol. Someone decided this a long time ago and that's just the way it is now.

There are 3 lines I think are really cool so this is a great opportunity to use a class since I plan to highlight more than one section.

First I'll put a span around all of the parts I want to highlight:

<span class = "highlight">from the womb, remembered the soul’s history</span>

<span class = "highlight">where the hours are suns,</span>

<span class = "highlight">Was that their lips, still touched with fire,</span>

Next I just need to add in my class selector in CSS and let it know what color I would like my highlight to be in:

.highlight { background-color : yellow; }

Unlike IDs, classes are selected using a period (.). Once again this is simply the symbol that was chosen to represent them.

One big difference to keep in mind between classes and IDs is that you can only apply one ID to a tag, however you can have as many classes as you want! If I created an underline class to apply an red underline to the text within it, I can simply add that class on:

<span class = "highlight underline">from the womb, remembered the soul’s history</span> .underline{ text-decoration : underline; }

A tag can also have an ID and one or more classes associated with it as can be seen used in the final output:

If you look carefully in the example above you'll see that I also selected all headers and paragraph tags and changed their font using the element name as a selector.

A few bonus bits about IDs:

  • IDs can be used to jump a page directly to where that ID is. Ever been to a page where you can jump to the bottom of the page? Normally you just give an element an ID of "footer" and then link to it using something like this:

    <a href="#footer">Go to footer</a>

  • Javascript automatically creates a reference variable to the element of any page with an ID on it. That means that the this div element: <div id="foo"></div> can be accessed in JavaScript simply by using the variable foo.

Nov 03 2015

Advanced JS

I've been working on getting a better understanding of JavaScript for the last year or so. For a while now I've been doing mostly front end development to provide a nice user experience. This isn't to say I've been doing UX stuff, but connecting a series of JQuery statements to make something work.

Thinking I'd hit bottom on how much I could learn about JS on the job I was happy to find John Resig's Secrets of the JavaScript Ninja.

This is exactly the book I need for a series of technologies. Not the introductory book on the topic with a few advanced topics towards the end chapters. Secrets of the JS Ninja assumes you know how objects, variables, Ajax and control structures are used in JS and puts you to work with some of the deeper features of the language.

One example is the user of the functions call and apply to set the context of this to be whatever you pass via call/apply. Two days later I found myself happy for having read that chapter as I had to debug a 3rd party piece of code which used those functions. A series of calls and apply's would have left me scratching my head about how the data got set if I hadn't just read up on it.

If you need an advanced JS book try out Secrets of the JS Ninja.

Jun 02 2015

Interviewing with limited experience

Internships and co-ops are great ways to learn and to help you pad your resume a little bit before you start looking for jobs after graduation. When I was a in college I wanted to do an internship desperately so that I would be in a better position once I hit the job market. It worked out pretty well for me as my internship lead to a part time job which lead to a full time job the day after I graduated.

Now I'm on the other side of the table and I've gone through a couple of cycles of co-op candidates at work and look across at a series of young hopefuls who also seek to pad their own resume's.

I go through dozens of resumes each cycle for students who are seeking employment in the development field for the first time and have found a few things happen repeatedly that make me either put your name into the "NO" pile instantly or very politely cut our interview short.

Hopefully potential first time interns / co-ops with limited experience will benefit from this.

I don't care about the alphabet soup, just show me what you did

I don't care how many abbreviations you can cram onto your resume as it all ends up meaning nothing. Sometime ago I found someone who had every exciting language and technology possible on their resume. I got excited, I wanted to interview and talk to this kid. He was also the owner of his own company. I thought: "Wow! This kid is going to shine and would be a great addition to our team! He'll hop aboard and just start getting stuff done at once."

Then I looked closer at his resume. He listed all of these technologies but then had no details about anything he did with any of them. I looked at the website for his "company" and every line made me cringe. It was like reading the greatest hits of every cringe worthy start-up. The site had page after page of nothing. At the end I had no idea what the company was about, no idea what was being worked on, no idea that it was anything more than a generic template that was just filled with words.

Add a few key technologies that you worked with, but then tell me exactly what you did. Give me a quick overview of some cool, interesting or fun things you have accomplished using technology. Even if the tech stack you've worked with doesn't match what I'm looking for exactly I'll consider your resume more than the person that just lists every technology available.

Don't mention jobs that aren't relevant to the software development field

Student careers centers are partly to blame for this. I went to one once and they asked me to list every place I ever worked for. They then proceeded to make me put this on a resume that I hoped to use to apply for a development position. Don't do this.

Please don't list that you worked at Hollister and advised customers on what clothes looked good to them or that you were a cashier and handled up to $200 cash. I will feel like I wasted my time reading that as it tells me nothing about your ability to write an if statement.

Even if you don't have much experience, just mention a small project you worked on in class, mention some of the highlights of what you did with it. In the interview we'll go over those class projects in detail to see what you understood from it.

Extracurricular activities are cool and fun, but don't go overboard with them

I get that most students looking for their first job don't have much experience but I really don't care that you planted 300 trees one summer, or that you attempted to get a bill to pass to ban plastic bottles or that you went to bible school.

Extracurricular activities are a nice extra to get to know a little bit about a student, but please keep it brief and don't go overboard with listing every club you were part of since high school.

Don't list tools that you use to code

Visual Studio, Notepad++, Sublime, vim, XCode. What do all of these items have in common?

They have no place on your resume.

They are tools that you use to write code and tell me nothing about you and your skill. It is space wasted that you could have used to go into detail about something that you worked on to give me a better insight into your skill set. I personally don't care what you use to write code in. I might raise an eyebrow if you use Notepad to write your code, but apart from that I don't really care what you write code in. If you want to use MS Word with a series of plugins to make it highlight JavaScript then be my guest. As long as your code works and is clean I won't mind.

Don't even get me started on listing Word, Excel, Chrome/ Firefox as skills. Please just stop.

Be honest

I know it can be rough trying to get your start. You find your self in the catch-22 where you have no experience because you don't have a job, and you don't have a job because you have no experience. This is understandable but don't lie on your resume. It will become quickly apparent in the interview if you're not as skilled as you claim or if you don't know how to use a technology. You will be quickly and politely shown to the door in minutes after you arrive.

Aug 28 2014


Guide of things common basic debugging traps that I've fallen into over the years and I've seen others fall into. On any given day these questions run through my mind as I encounter strange behavior or when something isn't working right. They may seem obvious but I wanted to get them down and onto paper so I can have something to reference when it's 4AM and the deadline is at 8AM. Also this should hopefully be helpful to newcomers

An updated copy of this is kept on github


  • Don't panic!
  • What do you expect to happen?
  • What is actually happening?
  • Look at the output, what does it tell you? Read it carefully and slowly.
  • Which source file does the issue occur in?
    • Which function?
    • Which line?
    • What specific statement?
    • Start answering the first question and go deeper.
  • What values do you think your variables have? Print these values to screen to verify what they are.
  • Be very liberal with your debug print statements. Put them before and after where you suspect the problem is happening.
  • Are you loading the right file?
  • Are you sure you're loading the right file?
  • Is there some caching going on anywhere on the OS/Server/Compiler/Browser/Proxy level?
    • Always logout and then login after clearing your cache
  • Are all of your variables correctly spelled?
  • Are your variable and function names spelled correctly?
  • Do you have semi-colons in the right place?
  • Did you check for semi-colons at the end of if, for and while structures or anywhere else where they are not supposed to be?
  • Do you have whitespace in the right place?
  • Do you fully understand how a function / feature is supposed to work? Either speak up and ask or spend some time with the documentation.
  • If you are working on anything non-trivial put it under source control. That way you can compare previous known working versions of the code to the current failing version.
  • If something works on one computer but not another verify that all libraries and dependancies are the same.
    • Also ensure that everything else is the same:OS runtime library, dependencies etc. A small version number difference can break things.

C/ C++

  • Is your compiler setup properly?
  • Do you have all of the required header files?
  • Segfault? Ctrl + z.
    • If you have a segfault it means you probably did something funky with a pointer, so start your search with pointers. Wikipedia has a decent write up on segfaults
      • Learn to use pointers properly. It will save your life


  • Are your files set to the right permissions?
  • Is there a break in network connectivity? (CDN down, remote server unavailable etc).
  • Do a cache clear and force reload.
  • Make sure the error log is turned on
  • Check the error log for an extra clues that may not have been displayed on screen (usually in the Apache error log)
  • Are your ini file settings in order?
  • Did you get the needle haystack order right? Double check on PHP.net, or your IDE's code hinting.


  • Are you sure the feature you are trying to use is available on the browser you are testing on? See what happens on other browsers.
  • If you get an error TypeError: Cannot call method 'yourMethodName' of null or something similar to it, chances are that you are attempting to access a DOM element before it is loaded. Place your code in side a $(document).ready(function(){/*Code Here*/}); call. No JQuery? Use document.addEventListener("DOMContentLoaded", function() {/*Code Here*/}, false); instead.


  • Are you running the script in a $(document).ready(function(){/*Code here*/ });?
  • Are you sure you have the format $(document).ready(function(){/*Code here*/ }); and not $(document).ready(){/*Code here*/ }?
  • Are you creating race conditions with the network? Think about async and if you may need to wait.

JUN 05 2014


All the cool new features for PHP are in the latest releases. You can't get to those easily from package managers. It takes package managers a while to update to the latest versions. If you want to get the latest version faster you'll need to build your own copy to get the latest and greatest and to help the open source community debug.

Here are some notes on how to get this done. (The instructions below assume basic linux terminal competency)

Installing Apache from source


Make : apt-get install make

APR: apt-get install libapr1-dev libaprutil1-dev. Apr is needed for the error checking for APR... no configure: error: APR not found. Please read the documentation.


  1. Download the source files: wget http://www.bizdirusa.com/mirrors/apache//httpd/httpd-2.4.9.tar.gz
  2. Extract source files : tar -zxvf httpd-2.4.9.tar.gz
  3. Configure the install: ./configure --prefix=/usr/local/apache --enable-so --enable-cgi --enable-info --enable-rewrite --enable-spelling --enable-usertrack --enable-deflate --enable-ssl --enable-mime-magic
  4. Make make
  5. Make install make install
  6. Start Apache. Navigate to /usr/local/apache/bin and run ./apachectl start

You should now have a functioning Apache server

Key commands from configuration script

--prefix=/usr/local/apache: This is where apache will be installed

--enable-so: This tells Apache to build so modules modules.


You can alias the apachectl command so you can start it from anywhere.

  1. Navigate to your home directory : cd ~ . Edit the .bash_aliases file: vi .bash_aliases
  2. Make the alias alias apache="/usr/local/apache/bin/apachectl"
  3. Depending on your environment you may need to alias the sudo command as well so it works with your newly created alias for Apache. Add this line before step 3: alias su5. do="sudo "
  4. Logout of your terminal and log back in, you can now access apache via apache <start> <restart> <stop> <status>

Installing PHP from source


libxml : apt-get install libxml2-dev


  1. Download the source files: wget http://downloads.php.net/tyrael/php-5.6.0beta3.tar.gz
  2. Extract source files : tar -zxvf php-5.6.0beta3.tar.gz
  3. Configure the install: ./configure --with-pear=/usr/share/php --with-bz2 --with-curl --with-gd --enable-calendar --enable-mbstring --enable-bcmath --enable-sockets --with-regex=php --with-zlib --with-regex=php --with-zlib --with-mysql --with-mysqli --with-apxs2=/usr/local/apache/bin/apxs
  4. Make make
  5. Make install make install

Key commands

--with-apxs2=/usr/local/apache/bin/apxs: This enables PHP to create libphp5.so. This mod is required so that Apache can rung PHP files.

Congfiguration with Apache

Next PHP needs to be configured with Apache.

  1. Navigate to /usr/local/apache/conf (or wherever your local Apache install is)
  2. Open httpd.conf with your preferred editor. For example vi httpd.conf or gedit httpd.conf
  3. Set the Directory Index to index.php index.html This makes index.php the default file loaded, then if index.php is missing index.html is loaded
  4. Add AddType application/x-httpd-php .php
  5. Ensure the libphp5.so module is loaded: LoadModule php5_module modules/libphp5.so
  6. Set the Handler for PHP files:

    <FilesMatch \.php$> SetHandler application/x-httpd-php

  7. Restart Apache

MAY 18 2014


Most applications use a database of some form. For PHP MySQL is a popular choice of database for a variety of reasons:

  • It's free
  • It usually comes bundled with a PHP installation (shared hosting, WAMP, LAMP etc.)
  • There are a variety of tutorials for it on the web and it's easy to learn

The final point has much to do with why many people who programme in PHP get bogged down with security issues. The first 5 tutorials that I found all showed users how to perform MySQL queries using the myql_* library.

Notice how on the documentation for this library the first thing it says is that it's deprecated as of PHP 5.5.0? It's been deprecated as of PHP 5.5.0. That was in 2013, I can remember the PHP.net and community at large recommending no longer using mysql_* functions as far back as 2009. In the tech world that might as well have been in the age of the dinosaurs.

The main reason for it being deprecated is that it is simply not a secure way to write MySQL statements. It treats a MySQL statement as a string rather than an immutable object.

With mysql_* functions you create a statement as a string and pass that string to your database to be executed. The problem begins when you want to pass user generated information such as a username into your database. Users can directly insert new MySQL commands from your webpage into your database. This is called an SQL Injection attacks. It's one of the most basic attacks against any website that uses a database.

Here is a typical MySQL command:

$query = "SELECT * FROM mySuperImportantTable WHERE user = '" + $userInput +''";

Assume $userInput will come from any user visiting the site and is entered through a user name textfield.

In the example above this line is ripe for SQL injection. If $query were to be run with a the command mysql_query($query) a user could pass in 'dirty' input. For example a user could enter as input

a'; drop mySuperImportantTable WHERE 1=1

Noticed the a'; at the start of the query. It makes the above query:

$query = "SELECT * FROM mySuperImportantTable WHERE user = 'a'; DROP mySuperImportantTable WHERE 1=1 '";

See where the trouble begins? No? Here is the query by itself:

SELECT * FROM mySuperImportantTable WHERE user = 'a';

DROP mySuperImportantTable WHERE 1=1 '";

See how what was mean to be a simple select query has now turned into a select query and a drop query? That is an injection attack. The above example is mostly harmless if you had backups, but your attacker can now run any MySQL command on your server. They can dump your full table structure, give themselves full administrative privileges, delete your account, get other users email address, password and anything else they see fit to do.

Many new to PHP will attempt to go through great hoops of fire to prevent this with clever functions to look out for 'dirty' user input to stop injection attacks. This inevitably always fails. When I first started I used to write functions to scrub the strings for any MySQL keywords and escape harmful characters.

This is a losers game. There are more vectors to exploit this than you can reasonable fix while maintaining the rest of your life.

The solution is to use parametrized queries. With a parametrized query the resulting query that comes from your user input isn't treated as a MySQL command, rather it's treated as dumb text that is simply to be inserted into your database. So going back to the example from earlier your query simply looks for a user named 'a'; DROP mySuperImportantTable WHERE 1=1 ' instead of executing an extra statement.

Writing better MySQL statements

So how do we write parametrized queries?

The first step is to choose a either the mysqli or PDO_MySQL library. I'll show how to use mysqli since it's similar to the mysql library.

The dangerous way

Your typical mysql connection looks like this:

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); //Database connection mysql_select_db('foo', $link); //Select database $query = "SELECT * FROM mySuperImportantTable WHERE user = '" + $userInput +''"; //query setup $result = mysql_query($query); //query execution while($row = mysql_fecth_assoc($result) { //Do stuff with $row variable }

That is the general form that most tutorial sites teach how to use MySQL with PHP. Look at it well and repeat to yourself :"I will never write MySQL code like that every again."

A safer way

Here is a good template for parametrized MySQL statements:

$mysqliConnection = new mysqli("localhost","user","password","database");// Connect to database and choose database $query = "SELECT * FROM mySuperImportantTable WHERE user = ?"; // Query saved into a string. Note the '?' $stmt = $mysqli->prepare($query); //Query prepared for execution $stmt->bind_param('s',$userInput); // Bind user data to the query. $stmt->execute(); // Execure the query $result = $stmt->get_result(); //Only needed if we are expecting to get data back from the db while($row = $result->fetch_assoc()) { //Do stuff with $row variable }

Above we in the $query string instead of inserting the $userInput variable, we substitute it with a '?'. Note: the '?' is not surrounded by single quotes in the string. This is because if we surrounded it with single quotes we would simply be doing a search for a '?'.

The '?' is a special symbol which the bind_param() function replaces with the contents of $userInput.

If we had more than one variable user input to add to our query we would edit the bind_param method to accept them: $stmt->bind_param('ssi',$userInput,$otherTextInput,$integer)

Note the first parameter of bind_param() dictates how many variables we are passing in. For each variable passed we denote it by an 's' or an 'i'. 's' for String data types and 'i' for integers. There also exist the options 'd' and 'b' for the types Double and Blob respectively.

That's it! You're now safe from basic injection attacks. This is not to say that you can now relax. There are always nefarious people out there looking for new ways to break into your database, but at least with this approach you won't be a sitting duck with a target on its back.

JAN 16 2014


I've been feeling guilty lately about my Raspberry-pi sitting on my desk collecting dust, every time I use my PC I can feel it staring silently at me, judging me.

To fix this I decided to get a 32GB SD card so I could have more space to play around on it (2GB is not enough) and got a HDMI to VGA converter so I could give it a monitor of it's own. No need to give up one of my screens to use it, or have to crane my neck at an awkward angle to use it on my TV while still sitting at my desk.

After hunting around for a power cable for the old 15" Dell monitor I had laying around I remembered that I would need to flash an OS onto the SD card. Then I remembered: I own no SD card readers. For a split second I had a strange feeling of panic and sadness, then it hit me: I could just use my camera like I did last time!I dug around in my drawers and found it, my old Casio Exilim EX-S10RD

It looked a little battle worn with some scratches and scuffs from being dropped a few times over and the red finish was starting to chip away at the edges. Just as I was taking it out I happened to notice my cellphone(Samsung Galaxy S2), iPAD retina and DSLR sitting pretty close to each other and realized how downgraded my once prized piece of technology into a glorified SD card reader.

The Casio was once my crown jewel, the piece of technology that I never left the house with. With a whopping 10.1 MP(don't forget that extra 0.1 Mega Pixel) it was the best camera I'd ever owned in my life back in 2009 when I first got it. My cell phone at the time had a 3 MP camera, and all of the pictures it took came out blurry and washed out. But not this 10.1MP red beauty. Picture came out crystal clear, it had a great continuous shooting mode and let's not forget about the 720P video it could take.

This camera by it's image count tag had taken at least 4203 pictures from 2009 until I stopped using it probably around 2011. That's over 20GB of pictures! I've since lost a good portion of those pictures due to various hard drive crashes (should be a warning to backup more). The camera was with me when I went to my first nerdy convention Otakon in the summer of 2009. It traveled up and down the east coast with me as I went around seeing new places in the US. It was also there when I watch a police chase end right outside my dorm room during my sophomore year of college when the police ended a chase with road tacks causing the car to stop on the side walk. I was recording the chase when the man in the car decided to end his life with a gun right outside my window. I also remember almost dropping it into the reflecting pool in DC and leaving it behind and more than one party.

When I bought it he camera cost $211.99, which wasn't easy on a college student budget making minimum wage ($7.19 at the time). I got it right after getting my first job on my college campus the summer after my freshman semester.It now sells used for $53.99 and Amazon offers to buy mine for $24.10.I remember spending weeks researching the digital camera market, going over features and deciding which ones mattered to me, reading reviews good and bad, whipping out a ruler to get an idea of the size since I wanted a really portable camera, battery life, warranty, LCD size, feel of the buttons, quality of the images and then I finally bought it. I think I still have the box it came in stowed away somewhere. I even made sure to write a review on it on Amazon giving it 4 out of 5 stars lamenting in my review:

Where the Exilim logo is right under is a big sticker with "YouTube Capture Mode" it looks like a high quality adhesive sticker, and I'm a bit worried to take it off thinking that it might leave an ugly square spot on the camera. So I'm stuck advertising for YouTube every time I whip out my camera....oh well I'll get over it eventually.

I think the reason I knocked one start off of it was because it wasn't as slick of an interface of some of the Sony ones I'd used before. Oh and the YouTube logo rubbed off of the sticker eventually after a few years. I just noticed that someone else commented that the sticker came off easily for them. If only I had known back then...

And now for the past two years or so I've used it to read and write to SD cards. The once mighty inseparable companion now collects dust in my drawer not seeing the light of day for months at a time.

So here is to the memory of an old friend. I might try to hang out with him more like we used to. The pictures it take still look great five years later. I don't need the iPhone's new autobalancingretouchandairbrushingdualled or whatever the new feature is nowadays. Here are the last few forgotten pictures I found on the internal memory probably from a mini golf course I went to a few years ago. Probably taken after the memory card got full and we still wanted more pictures:

WinAmp! Artsy I don't remember whose fingers those are So many pearly white teeth!

SEP 11 2013


I've recently started using Xcode again and was attempting to use git via the command line since I'm more at home there. After some Googling I found out that it was tied into Xcode .app folder. I looked for a way to make it easy to get at the already built in git. I hated the idea of installing another version and bloating my system with multiple versions when there is a perfectly suitable version already installed. Here is the easiest way I found to work around this:

  • Open the terminal
  • Type in sudo vi .profile
  • Edit the file to include the following line:
alias git="xcrun git"

Restart the terminal and you will now have access to just run git everytime.

JUN 25 2013


I've written software imperatively for almost a decade now. In fact I was barely aware that there were other ways to write it until I was introduced to Scheme in my junior year of college, I even wrote an interpreter for it.

Scheme was certainly an oddity to me when I was first introduced to it. With most imperative languages I could look up a few syntax idioms and be on my way to writing basic scripts. With Scheme it felt like I had to learn to program all over again. It made me feel dense as everything I did I had to do slowly before I thought it was right, and then I had to wade through what seemed like a never ending stream of error messages at compile time.

But I powered through it, participated in class, got my assignments done, passed the tests, wrote an interpreter and moved on. At the end of it all I thought I would say goodbye to functional programming forever.

Fast forward 3 years and here I am learning Haskell. I have no reason or explanation for what made me pick it up other than a mixture of curiosity and boredom on a slow afternoon. Someone had linked to Learn You A Haskell for Great Good and I decided to take another look at functional programming. After an hour in what once felt slow, awkward and painful now made me feel empowered.

So far I'm about 3 Chapters into the book but here is what I've found so far: Haskell makes thinking of problems easier. Let's take a look at a FizzBuzz solution and a few slight variants in Haskell that I decided to code up after an hour of reading to gauge my understanding:

fizzBuzz y = [ if x `mod` 15 ==0 then "FizzBuzz" else if x `mod ` 5 ==0 then "Buzz" else if x `mod` 3 == 0 then "Fizz" else show x | x<-[1..y] ]

This will generate a fizzbuzz solution for y numbers when called:

*Main> fizzBuzz 15

On the first line I declare my function fizzBuzz and pass it my parameter y. The body of the function exists between the square braces.

Before we move on let's talk about Comprehension Sets.

Here is a Comprehension Set:

Don't panic. It's just a little math.

What it says is that we want a list of values S which will be generated by the output function 2*x.

x, our variable, must be part of our input set (N) and our predicate says x^2 must be greater than 3.

Comprehension sets are a very concise way of representing data and Haskell utilizes this.

The if else if else block is our function part of the Comprehension set. The x<-[1..y] serves as our input and for this example we don't have a predicate. The input bears a little more explanation.

[1..y] gives us a list of numbers from 1 to y.

x<- will take each value from the list in turn. This is a built in feature of Haskell.

If we did want a predicate,we would just add it in after the input. For example if we only wanted even numbers

fizzBuzz y = [ if x `mod` 15 ==0 then "FizzBuzz" else if x `mod ` 5 ==0 then "Buzz" else if x `mod` 3 == 0 then "Fizz" else show x | x<-[1..y], even x ]


*Main> fizzBuzz 15

We can have as many predicates as we would like. Let's say we wanted only numbers which were greater than 42:

fizzBuzz y = [ if x `mod` 15 ==0 then "FizzBuzz" else if x `mod ` 5 ==0 then "Buzz" else if x `mod` 3 == 0 then "Fizz" else show x | x<-[1..y], even x, x > 42 ]

Results: *Main> fizzBuzz 75 ["44","46","Fizz","Buzz","52","Fizz","56","58","FizzBuzz","62","64","Fizz","68","Buzz","Fizz","74"]

What if we wanted to control our input range to only check for multiples of 10? Haskell has a few built in functions to make this easy with lists. Haskell can check for patterns when we're making a list if we seed the first few values:

fizzBuzz y = [ if x `mod` 15 ==0 then "FizzBuzz" else if x `mod ` 5 ==0 then "Buzz" else if x `mod` 3 == 0 then "Fizz" else show x | x<-[10,20..y] ]


*Main> fizzBuzz 100

These are just a few of the things that I've found very neat in Haskell from 1 hour of playing with it. Coding these solutions would have been close to trivial in C or Java, but Haskell makes for very concise code in a few lines.

The benefits of functoinal programming are plentiful I'm told. The issue of correctness especially interests me for web development as it could possibly lead to inherent security benefits and fewer headaches.

MAR 06 2013


We've all Googled something in our lifetime (except for that one guy I heard ask "What's a Google?") and having worked in front end user IT support for years I can tell you that most of the time the God like skills users have commended me for were just a mixture of dropping the error message or description of the problem into Google and learning how to filter out the vast and ever increasing amounts of noise on the internet.

I can remember how I found just about every other search engine out there: Yahoo, Lycos, Ask Jeeves and AOL were all by advertising on TV in the late 90's, MSN Search (as it was called back then) was probably the first thing I ever saw when I connected to the internet for the very first time. Google though I can't remember the details of. At best I have a memory of some guy on a forum linking to it claiming it had better results. After finding Google I haven't used another search engine apart from a brief stint of using Duck Duck Go and Bing to see if I could function without Google; turns out I couldn't.

Google was my gateway to knowledge through the late 1990's and early 2000's. Long before Oxford decided to add Google as a verb to their dictionary myself and some friends were using it as such. I found that no problem was too hard for Google to find, no weird error that occurred under very specific conditions was too obscure for Google to help me find someone else across the world with the same problem that found a fix for it. No matter the query Google had the answer.

This is where the problem beings. There is a fine line between an empowering tool and a crutch. Google is the mightiest, sharpest sword out there on the internet, but it makes it so much more dangerous if you fall on it.

I started programming seriously on the web after learning my ABCs in qBasic and making static web pages just didn't cut it anymore. I wanted to know how all those cool effects on all of those geocities sites were done, how a page could store my information and welcome me back later, how new forum posts could be shown by users typing into a text box.

I found my way to PHP and JavaScript to answer those questions. I learnt a lot during that time, but I also fell into the trap of copy paste coding. Hmm I want to move an image across the page, let me just Google "How to move image across the page JavaScript" and boom my problem was solved. Twiddle with a few numbers and HTML in the script and look at that it's done.

I fell especially hard into this trap with JavaScript.Not sure why but for a long time I always though JavaScript wasn't worth learning, it never struck me as exciting or interesting, just some funky thing web browsers use on the client side. For years if I needed anything done in JavaScript I would Google for the solution, no thought or effort on my part. It wasn't until last year I resolved to really learn JavaScript from the ground up and treat it with the respect it deserved. I stopped using Google to give me neatly wrapped solutions and started using it to point me in the right direction.

A quick Google for "How to move image across the page JavaScript" brings me to some familiar forums and some new faces of websites which aim to provide neatly wrapped solutions to these types of searches. Just looking at the results brings back old memories of being frustrated when the code was over my head and the lazy desire to find something that just did what I wanted. I can sense that same feeling in some of the posters who being to get impatient when they can't just have their question answered with exactly what they're looking for.

Vu Tran posts that The best programmers are the quickest to Google. It's hard to disagree with this as I remember on particular Comp Sci assignment which my class had to do in C++. At that time no one had used C++ extensively for at least a year and a half. Most of us that were on the ball were silently Googling away getting the answers and refreshing their memory quickly on long forgotten nuances of C++. Other's were openly asking how to do X or why they were getting a certain error. This went on for a few minutes until someone yelled out "God dammit no one here knows either, we're all just Googling to and that's why we're making progress and you're not". Interestingly enough on another project the same people asking the C++ questions instead of Googling would find themselves asking "Why doesn't this work?" after quickly Googling and copy pasting code they didn't fully understand.

You see the key here is not only to quickly run to Google, but to also know how to filter out the results which are a technical match to you search, but not to your over all goal. Not knowing how to effectively wield the power you end up falling into a deeper and deeper trap of ignorance.

Bonus chatter: I once said the word Google out loud to some kids that weren't in the "tech" crowd in high school and someone yelled at me for having dared to share the ultimate secret of technology with the plebeians.

FEB 26 2013


I have ADD when it comes to my hobbies.

There are endless choices out there when it comes to personal projects with each being more interesting that the last one. The tech industry is moving faster than I've ever seen it move with a constant stream of innovation from the big players in the market and indie devs just putting out great tools and products. Right now I'd love to just pour hours into Programmable Drones, Arduino and other electronic devices, Android Development, Windows 8 app development, Diving deeper into what I already know, doing neat things in HTML5 or giving back to the community.

I've poked around with each for a few hours, but never long enough to get any concrete results. Time to change that.

I've been looking over a few things I'd like to get into; checking out the tools, documentation, community etc and hopefully in a few days I'll find the right project to commit to for months to come. I think the only way I even have a chance to survive this though is to stay of Hacker News and /r/Programming so that the latest release: rubied python on rails for full scalability on the cloud running in memory on a cherry pi with with built in easy to use CSS templates for mobile devices and desktops, doesn't distract me.

That and pictures of cats.

Feb07 2013


Server issues now resolved. Back up and running but lost all data. In light of this I'm thinking of moving to Amazon web services, I've been looking for an excuse to play around with their services for a while now and this gives me a chance.

Jan 31 2013