Clinton Paquin

Code

I don't always make code public, but you can find other samples at GitHub

Here are some basic code samples, they aren't always production ready, but it gives you an entry talking point if you want to see my style.

PHP
MySQL
Javascript
  •                                         <body id="<?php echo $subsection; ?>" class="<?php echo $section; ?>">
        <div class="row">
            <div class="twelve columns">
                <?php echo $nav; ?>
                <section>
                    <?php echo $header; ?>
    
                    <?php if(! empty($copydeck->content) ) { ?>
                        <?php echo $copydeck->content; ?>
                    <?php } ?>
    
                    <?php echo $quicklinks; ?>
                </section>
                <?php echo $footer; ?>
            </div>
        </div>
    </body>
    </html>
    
                                        
                                            class About extends MY_Controller {
    
    	public function __construct() {
    		parent::__construct();
        }
    
    	public function index() {
    		// set up view
    		$this->load->view('layouts/main', $this->page_data);
    	}
    
        public function social() {
            /**
             * tumblr.com
             */
            $this->load->library('tumblr');
            $tumblr_posts = $this->tumblr->read_posts();
    
            /**
             * meetup.com
             */
            $this->load->model('meetup');
            $meetup['groups'] = $this->meetup->getGroups();	// get all groups
            $rsvps = $this->meetup->getRsvps();				// get everything you RSVP'd for
    
            foreach($rsvps->items->item as $checkin) {		// get details on all events you RSVD'd for
                $meetup['checkins'][] = $this->meetup->getEvent($checkin->event_id);
            }
    
            $checkins = $this->meetup->getCheckins();		// get everything you actually checked in at (much shorter list)
    
    
            /**
             * linkedin.com
             */
    
            /**
             * forrst.com
             */
            $this->load->library('forrst');
            $forrst_user = $this->forrst->user_info( $this->config->item('forrst') );
            $forrst_posts = $this->forrst->user_posts( $this->config->item('forrst') );
    
            /**
             * stackoverflow
             **
    
            /**
             * github
             */
    
            /**
             * google+
             */
    
            /**
             * twitter.com
             */
            $this->load->model('twitter');
            $twitter_posts = $this->twitter->getTweets( $this->config->item('twitter') );
    
            // set up view
            $this->load->view('about/social', $this->page_data);
        }
    }
    
                                        
                                            /**
     * Model to handle copy for all pages
     * @author clintonpaquin
     */
    class Copydeck extends CI_Model {
    
    	protected $copydeck 	= '';
    	protected $promos 		= '';
    	protected $navigation 	= '';
    
    	/**
    	 * Initialize copydeck file and make sure it exists
    	 */
        public function __construct()
        {
            parent::__construct();
    
        	$this->load->helper('file');
    
        	$this->navigation = $this->__loadNavigation();
        	$this->copydeck = $this->__loadCopydeck();
        	$this->promos = $this->__loadPromos();
        }
    
        private function __loadCopydeck()
        {
        	$data = '';
    
        	//set path to copydeck file that should be used
        	$path  = $this->config->item('copydeck').$this->router->class.".xml";
    
        	// check to see if copydeck file can be found …
        	try {
        		$fileInfo = get_file_info($path);
    
        		if($fileInfo) {
        			if($fileInfo['size'] > 0) {
        				$this->copydeck = $fileInfo['server_path'];
    
        				$xml = simplexml_load_file($_SERVER['DOCUMENT_ROOT'].'/'.$this->copydeck, null, LIBXML_NOCDATA);
    
        				//make sure the xml file has content
        				try {
        					foreach($xml->pages->page as $page) {
        						if($page->attributes()->id == $this->router->method) {
        							$data = $page;
        							break;
        						}
        					}
    
        					if(empty($data)) {
        						//throw new Exception('Unable to load empty copydeck');
        					}
        				} catch (Exception $e) {
        					show_error($e->getMessage());
        				}
        			} else {
        				// throw new Exception('Unable to load empty copydeck');
        			}
        		} else {
        			// throw new Exception('Unable to locate copydeck');
        		}
        	} catch (Exception $e) {
        		show_error($e->getMessage());
        	}
    
        	return $data;
        }
    }
                                        
  •                                         /*
     * This is actually an MSSQL example (yeah, we have to use those other languages sometimes too …)
     * Select the ID, FirstName, LastName, and Number of subscriptions a user has (with promo code > 19)
     * Three tables
     *  - Promotion
     *  - Member
     *  - MemberPromotion (bridge table)
     */
    Select m.ID, m.FirstName, m.LastName, count(*) as Count
    From [FXNetworks].[dbo].[MemberPromotion] mp, [FXNetworks].[dbo].[Member] m, [FXNetworks].[dbo].[Promotion] p
    Where mp.PromotionID=p.ID and mp.MemberID=m.ID and mp.Subscribed='1' and p.ID >= '19'
    Group By m.ID, m.FirstName, m.LastName
    Order By Count ASC
                                        
                                            /*
     * This is actually an MSSQL example (yeah, we have to use those other languages sometimes too …)
     * Select a Promotion Description and Count of users subscribed to that Promotion (with promo code > 19)
     * Three tables
     *  - Promotion
     *  - Member
     *  - MemberPromotion (bridge table)
     */
    Select distinct Description, count(*) as Count
    From (Select m.ID, p.Description
    From [FXNetworks].[dbo].[MemberPromotion] mp, [FXNetworks].[dbo].[Member] m, [FXNetworks].[dbo].[Promotion] p
    Where mp.PromotionID=p.ID and mp.MemberID=m.ID and mp.Subscribed='1' and p.ID >= '19') as Foo
    Group by Description
                                        
                                            /*
     * This is actually an MSSQL example (yeah, we have to use those other languages sometimes too …)
     * Select the ID, FirstName, LastName, and LastLogin of users subscribed to newsletter (with promo = 19)
     * Three tables
     *  - Promotion
     *  - Member
     *  - MemberPromotion (bridge table)
     */
    Select Member.ID, Member.FirstName, Member.LastName, Member.LastLogin FROM Member, Promotion, MemberPromotion 
    WHERE Member.ID = MemberPromotion.MemberID and MemberPromotion.PromotionID='9' AND
    DATEADD(year, 1, Member.LastLogin) < getdate() 
    Group By Member.ID, Member.FirstName, Member.LastName, Member.LastLogin
    order by LastLogin DESC
                                        
  •                                         /**
     * Twitter API Sample
     * This is a quick code sample I whipped up and tested in about 30 minutes for a fellow dev over at forrst.com
     * It does a query to twitter.com looking for references to the term "TGIF" and returns the response in json
     * The response is parsed and output every 10 seconds, the old results slide down and new are placed at the top
     * of the stack.  Good fun for the whole family right?!
     **/
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <body>
    <style type="text/css">
    /** please for the love of John Elway put your css in a seperate file (it's inline here for demo reasons) **/
    #twitter ul{height:auto; padding:15px 0 0 15px; margin:0}
            #twitter li{float:left; margin:3px; color: #ccc; list-style-type:none; background: #666; display: block; 
                        width: 300px; height: 100px; padding: 7px; border: solid 2px #6fb2cd; display:none;}
                    #twitter li:hover {border: solid 2px #ccc;
                            -moz-box-shadow: 6px 6px 3px #888;
                            -webkit-box-shadow: 6px 6px 3px #888;
                            box-shadow: 6px 6px 3px #888;}
                    #twitter li a {color: #6fb2cd; text-decoration: none;}
                            #twitter li a:hover {text-decoration: underline;}
    
                    #twitter img {float: left; padding: 3px;}
    </style>
    <script type="text/javascript">
    $(function () {
        function getTweets() {
            var url = 'http://search.twitter.com/search.json?callback=?&q=%23TGIF&rpp=16';
            $.getJSON(url, function (json) {
                var output = [];
                for (var i = 0, len = json.results.length; i < len; i++) {
                    output.push('<li><img src="' + json.results[i].profile_image_url + '" width="48" height="48" />' + json.results[i].text + '</li>');
                }
                $("#twitter").html(output.join('');
                $("#twitter li").slideDown('slow');
            });
        }
        var timer = setInterval(getTweets, 10000);
        getTweets();
    });
    </script>
    <ul id="twitter"></ul>
    </body>
    </html>
                                        
                                            /*
     * This is a simple method to use the jQuery AJAX caller and post to an update on a user's profile
     * As is best practice, make sure you set a timeout, error handling method, and while your script is working
     * be sure to let your user know that something is going on by showing some type of a visual "loading" indicator
     *
     * @param array - data about the user
     */
    function updateUser(data) {
    
    	// disable submit button and hide it
    	$('#submit').attr('disabled', 'disabled').hide();
    
    	// show processing indicator
    	$('#processing').css('visibility', 'visible').show();
    
    	$.ajax({
    			url: 'users/update',
    			datatype: 'json',
    			type: 'POST',
    			data: {first_name : data.first_name, last_name: data.last_name, email: data.email, promo_code: data.promo_code}
    			timeout: 3000,
    			success: function(response) {
    
    				// hide processing indicator
    				$('#processing').css('visibility', 'visible').hide();
    
    				if(response.error == true) {
    					$('.error').html(response.message).css('color','red');
    					$('.error').css('visibility', 'visible').fadeIn();
    
    					// re-enable submit button and show
    					$('#submit').attr('disabled', '').show();
    				} else {
    					// everything is good, hide the form and display thankyou
    					$('#my_form').hide();
    					$('.thankyou').html(response.thankyou);
    				}
    			},
    			error: function( objAJAXRequest, strError ){
    				// hide processing indicator
    				$('#processing').css('visibility', 'visible').hide();
    
    				if(strError == 'timeout') {
    					var error_message = "Timeout: There was an error processing your request.";
    				} else {
    					var error_message = "There was an error processing your request."
    				}
    
    				// load and display error message
    				$('.error').html(error_message).css('color','red');
    				$('.error').css('visibility', 'visible').fadeIn();
    
    				// re-enable submit button and show
    				$('#submit').attr('disabled', '').show();
    			}
    
    		});
    }