A Different Type of Resume (Résumé)

The one thing that’s difficult to tell from a programmer’s résumé is “Can they actually code?”  Sure, they may have had some coding jobs in the past, or have some schooling in programming, but that doesn’t tell you much about their actual skill.  Or maybe they DON’T have the schooling or work experience, but have done tons of personal projects or worked in open source projects… a résumé might miss that talented coder.  One of the things that I see a lot of tech people looking for recently is a Github account, and examples of coding or helping with open source projects, which is great.

As I thought about putting together a résumé, I wondered how can I demonstrate understanding of modern PHP concepts, without the hiring person needing to jump through a lot of hoops, or visit a bunch of sites.  So I created a résumé in code, and got some useful tips from the Forrst community as well.

The goal was to make a resume that could be readable to a non-programmer.  And I think if you look at it, you should be able to follow along:

$myResume->myName = “Terry Matula”;
$myResume->myEmail = “terrymatula-at-gmail-dot-com”;
$myResume->myPhone = “281-656-1474”;
// Places I’ve worked
$workExperience = array();
etc…
Even if you knew nothing about coding, that should make sense. And the great thing is, if you copy the file to a server and run it, it actually makes a somewhat nice looking résumé page.

Things I’ve Learned Using Codeigniter – PHP

1) You don’t need an ORM

I had experimented with Datamapper, and it was great. But there was complex join statement I needed that DM didn’t support… so I had to just write out the SQL like normal.  I then realized it’s just as easy to use CI’s Active Record or regular query command and create your own methods.  Plus, it keeps things pretty speedy.

2) You DO need a base Model

I’ve only just recently started using Jamie Rumbelow’s MY_Model and it’s changed everything. Previously, when I wanting to get a single record from a table, I was writing $this->db->from('table')->where('id',$id)->limit(1)->get()->row(); for every single table. Now, that’s already included for every Model I make.

3) It’s helpful to look at the core code

For example, I was curious how the Active Record was implemented, so I opened up DB_active_rec.php. I know some people prefer to use “->get()” by adding in the table name and limit as parameters, and I wondering if there was difference in how it’s handled.  Interestingly, it runs the exact same “from()” method, just as if you had “->from()” in the query.

And while this is a micro-optimization, if you want to return a single result and you’re sure it’s the first result… use “->limit(1)”.  The “row()” method will work with multiple rows returned, so there’s logic built in to just return the first row.  Adding “->limit(1)” will help skip all that.

4) The url helper really needs to be auto-loaded by default

In my autoload file, I always load the database and sessions libraries and the url helper. I can’t remember a project where those didn’t get used.  I’ll occasionally autoload the form helper as well, but that’s a project-by-project call.

But the url helper… I honestly can’t see how anyone would ever NOT use that in every project.  “site_url()” and “redirect()” just seem like no-brainers.

5) Object-Oriented programming and MVC

Prior to learning Codeigniter, I was experience in Drupal and WordPress, and a bit of Joomla, but working with them isn’t strict OO.  The custom stuff I programmed was really procedural or functional, based on the fact that I learned programming using PHP 4 and classic ASP/ vbscript.  While I read about and tried using Classes and methods, I just didn’t get it. With CI, I had the ‘flipped switch’ moment, where Objects and Classes made total sense.

Now, I’m onto learning as much as I can about OO in PHP 5.3, including namespaces and inheritance… which aren’t yet built into CI

5 Rules for Your Email List Unsubscribe Link

I put my email address into a lot of forms, especially because I like to check out new sites and services, and I’m always hoping for the “beta” invite. Inevitably, this means I also get added (without my knowing) to a lot of email lists. At the bottom of most emails is usually (if they’re following the law) a link to “unsubscribe”.  I’ve noticed some companies do unsubscribes right, and others… not so much.  So here are my rules that you should always follow for YOUR email list:

1) The best unsubscribe link takes you to a page that says “You’ve been removed from our list”… and that’s it.  Simple, effective, and I won’t hate you or your company afterwards.

2) The second best way (if you really think your email recipients are so stupid they may click it unintentionally) is to have a page with two buttons. One saying “Unsubscribe” and another saying  “Oops! I made a mistake! I don’t know how links works! Derp” or something.

3) NEVER ask for my email address to unsubscribe. You sent me the freaking email, you should KNOW my address. Also, I often use the “plus trick” for my gmail, and asking me to track down exactly what email address I used for your stupid, spammy site will just fill me rage and hatred for you and your babies.

4) NEVER send an “Unsubscribe Confirmation” email. Seriously? Are you that stupid? I just said “Don’t send me any more emails” and you’re going to do the exact opposite? How are you able to feed and clothe yourself?

5) Do NOT ask me to sign in and “change my notification preferences”. More than likely, I already forgot the password for your lame company that TechCrunch will never cover, and I’ll just have to do a “forgot password” thingy… meaning I must both find what email address I used AND get another email from you. Fail. Fail. Hatred. Fail.

CSS3 Gradients

I love CSS3 gradients… but I just can’t remember the syntax for both WebKit and Mozilla. That means, any new project I start where I want to use gradients, I run a Google search. One of the top results for CSS3 gradients is css-tricks.com. It’s a great article, but the Mozilla gradient example is over-complicated. Also, the two colors are in different orders between moz and webkit.  Personally, I think the top color should be on the left… for BOTH examples. So, more for my own personal reference, here’s a simplified CSS3 gradient code.

background:#ccc;

background: -webkit-gradient(linear, 0 0, 0 100%, from(#ccc), to(#eee));

background: -moz-linear-gradient(top, #ccc, #eee);

IE gets no gradient…. because, come on.

Simple Facebook / Codeigniter Authorization

On a Codeigniter project I’m working on, I wanted to have Twitter and Facebook logins available. Luckily, right around the time I was starting the project, Elliot Haughin released libraries for both Twitter and Facebook. The Twitter library worked almost instantly and is quite brilliant. However, the Facebook library was causing me some problem.

Looking through the Facebook Developer pages, it seemed like a fairly straight-forward process to get a User’s Facebook auth tokens… and with CI2 having querystring support now, I thought I could do everything in a simple Facebook controller.  Here’s what I got:

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Name:  Simple Facebook Codeigniter Login
 *
 * Author: Terry Matula
 *         terrymatula@gmail.com
 *         @terrymatula

 * Created:  03.31.2011
 *
 * Description:  An easy way to use Facebook to login
 *
 * Requirements: PHP5 or above
 *
 */
class Facebook extends CI_Controller {

    public $appid;
    public $apisecret;

    public function __construct()
    {
        parent::__construct();
        // replace these with Application ID and Application Secret.
        $this->appid = '12345';
        $this->apisecret = '123abc123';
    }

    /**
     * if you have a Facebook login button on your site, link it here
     */
    public function index()
    {
        // set the page you want Facebook to send the user back to
        $callback = site_url('facebook/confirm');
        // create the FB auth url to redirect the user to. 'scope' is
        // a comma sep list of the permissions you want. then direct them to it
        $url = "https://graph.facebook.com/oauth/authorize?client_id={$this->appid}&redirect_uri={$callback}&scope=email,publish_stream";
        redirect($url);
    }

    /**
     * Get tokens from FB then exchanges them for the User login tokens
     */
    public function confirm()
    {
        // get the code from the querystring
        $redirect = site_url('facebook/confirm');
        $code = $this->input->get('code');
        if ($code)
        {
            // now to get the auth token. '__getpage' is just a CURL method
            $gettoken = "https://graph.facebook.com/oauth/access_token?client_id={$this->appid}&redirect_uri={$redirect}&client_secret={$this->apisecret}&code={$code}";
            $return = $this->__getpage($gettoken);
            // if CURL didn't return a valid 200 http code, die
            if (!$return)
                die('Error getting token');
            // put the token into the $access_token variable
            parse_str($return);
            // now you can save the token to a database, and use it to access the user's graph
            // for example, this will return all their basic info.  check the FB Dev docs for more.
            $infourl = "https://graph.facebook.com/me?access_token=$access_token";
            $return = $this->__getpage($infourl);
            if (!$return)
                die('Error getting info');
            $info = json_decode($return);
            print_r($info);
        }
    }

    /**
     * CURL method to interface with FB API
     * @param string $url
     * @return json
     */
    private function __getpage($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $return = curl_exec($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        // check if it returns 200, or else return false
        if ($http_code === 200)
        {
            curl_close($ch);
            return $return;
        }
        else
        {
            // store the error. I may want to return this instead of FALSE later
            $error = curl_error($ch);
            curl_close($ch);
            return FALSE;
        }
    }

}


That’s about it. You could put it all in “index()”, but I wanted to separate it a little.

update: Looking at the bit.ly api, it’s actually very similar. i’ll eventually try to make it more generic.

Terry’s Happy Place songs

There are songs that just seem to always make you feel better when you hear them.  I’ve kept my own list in my head, and now I want to collect them into one post.  The list is fluid, but most of these have been set for years.  In no particular order, songs that put a smile on my face:

1) Morningwood – Nth Degree

2) Frankie Valli – December, 1963 (Oh, What a Night)

3) Glass Tiger – Don’t Forget Me When I’m Gone

4) Dolly Parton – Here You Come Again

5) Duran Duran – Hold Back The Rain

6) Duran Duran – The Reflex (yes, 2 Duran Duran songs)

7) The Beatles – Good Morning Good Morning (pretty much any Beatles, though)

8) Public Image Ltd – Disappointed

9) Radiohead – Bones

CodeIgniter and Datamapper ORM base installation

More and more at work, I’m using CodeIgniter (actually version 2) coupled with Datamapper ORM for quick projects. I even completed a fairly substantial project (the Careers page for PetRelocation.com) with probably 90% of the work being done in an 8 hour period… solo. The most difficult aspect of the whole thing was having multiple file uploads required for the page.  For these projects, I created base framework with CodeIgniter 2 and Datamapper ORM already integrated… plus some of the config files already set, like the autoloads.

So in the effort of being a good community member, I’m offering the CodeIgniter/Datamapper base that I use.

Weekend project – Auto Missing Child Alerts

Last week I saw some posts in my Twitter stream that were retweets of a missing child alert in the UK. It made me wonder if there was something that would do this automatically, so that a tweet would get sent from a user as soon as an alert was issued.  Kind of like the Emergency Broadcast System but for social networks.  I searched over a few days and couldn’t find anything, so I thought I’d build my own.

The guts of the program literally took a few hours yesterday, since I’m already aware of how to access Twitter and Facebook’s API.  I think the big hurdle is convincing people to essentially hand over their accounts to a service… with the knowledge that an alert post could come up at any time.  Also, trusting that the service won’t use the information for “evil”.  If it all works, however, it could be a huge boost to the Amber Alert system.

Imagine, the instant an alert is issued, it’s posted to multiple accounts and in front of millions (10s of millions?) of people.  One argument might be, if you follow 50 people who signed up for the service, you’d get 50 of the exact same message in your stream… but really, it only happens infrequently, and it’s to help find a missing and endangered child. People should be able to overlook that.

Right now, I think I have it working well… but I’ve only been able to test it with my accounts. I’m not sure how it will scale, but it seems to be okay. Here are some details of how I have it setup…

First, if you login using Twitter, I’m saving your “twitter name”, “oauth token”, and “oauth secret token”.  With Facebook, I’m saving your “name”,”oauth token”, and “facebook id”, and asking for offline posting privileges.  Then I have a table that sets whether you have the service active or not, keyed off your unique id. After you activate the service, you’re done.

After that, I have a script that checks for new Amber Alerts… though I’m hoping to add in international alerts.  If it finds a new one, it sends out a post with a link to the Amber Alert page. I also built a sort-of “panic button” script, in case something goes horribly wrong… or the site is compromised… I can run it and the whole system is wiped. Contingency plans, you know.

So it’s all at AutoAlert.Me. I’m probably not going to publicize it anymore than this post and tweet, and just having it running for my own accounts… but it’s there if others want to use it too.