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.

Fun puzzle – Christmas Conundrum

Saw this puzzle on Chris Shiflett’s blog and was able to figure it out. Don’t read further if you want to try yourself…

 

 

 

 

First, I wrote down the numbers, and immediately noticed the first numbers “1024” and “512” were suspiciously binary… though, that seems somewhat coincidental now. However, I plotted all the numbers into a spreadsheet, then did a conversion to binary.  I began thinking that maybe the 1s and 0s were like the beat of a Christmas song, so I tapped them out, and it didn’t seem to be anything.  Though bits seemed to be like “Jingle Bells” or “God Rest Ye Merry Gentlemen”, they never played out for the entire song. I got a bit sidetracked, thinking this was a designer, that maybe the numbers should be converted to HEX values, and use those colors for something.  Again, it didn’t pan out.  Here’s where I was at that point:

Then, as I looked at the column of binary numbers, I noticed there was a pattern… not in the numbers, but in the shape of the groups of numbers. I converted the column to monospace type and started connecting the 1s. It really didn’t make sense at first… but I saw the last group of numbers made a Greek Sigma “Σ” and an “X”. So I thought “Sigma Chi”, a fraternity.  The numbers above it made a “W” and a Sigma, and I thought maybe the “W” was supposed to be a Psi, but I couldn’t find anything relevant for “Psi Sigma”. At that point, I hadn’t connected all the 1s correctly, so I went back and connected all the 1s, even diagonally. The patterns became a lot clearer… but it still didn’t make sense.  At that point, I had my table turned just a bit to the side, and noticed the Sigma could actually be a sideways “M” and the “W” a sideways “E”… so I had “E M M X”.  With that, I saw I already had the “A” and a “Y”. Once I made one more missed connection of 1s, I had the two “R”s and figured the extra bit in the first group was an “!”.  From there, it was a simple matter of re-ordering the letters to make: MERRY XMAS!

Thanks to Chris Shiflett for the fun diversion. Though, it looks like I missed submitting the correct answer by only a few minutes (congrats Cogocogo) … it was still an enjoyable brain exercise.

Found an Old Song I Co-wrote

I used to have a site full of my old bands’ music, but that site went down and all those songs got trashed. I have them all backed-up on disc somewhere, but haven’t had a chance to go through all the stuff we have in boxes.  Anyway, I found this mp3 in one of my archives and I’m posting it here for the time-being. Wow, it’s almost 10 years old:

Smooth Like Roy’s You Know I Would