Contact Cameron Cox

x Cancel
posted 2 years ago

How do you stay productive?

I know a few people around these parts read hacker news, and may have seen Jerry Seinfeld's Productivity Secret

I've really never found a system that really fits my workflow, and wondered how everyone kept track of their days.

posted 2 years ago

MySQL Bound Parameters

                $pdo = new Pdo('mysql:host=127.0.0.1;dbname=app', 'root');

$query = $pdo->prepare('SELECT * FROM accounts WHERE id = ?');
$result = $query->execute(array(2));

if (false !== $result) {
    foreach ($query->fetchAll(PDO::FETCH_OBJ) as $row) {
        echo $row->name, "\n";
    }                                          
}                
Raw

I've been re-writing a lot of queries in the day job lately, and noticed that older queries didn't make use of prepared statements. They either accepted straight user input, or used some custom method that tried to duplicate what mysql_real_escape_string or prepared statements does.

So perhaps there's a lack of education in this, or perhaps developers are lazy (cough).

But either way, here's a basic example of using a prepared statement to find an account.

posted 2 years ago

A more ruby-like way

                  def self.terms(terms)
    return if terms.blank?
    composed_scope = scoped
    terms.split(' ').map { |term| "%#{term}%" }.each do |term|
      composed_scope = composed_scope.where('first_name ILIKE :term OR last_name ILIKE :term OR email ILIKE :term', { :term => term })
    end

    composed_scope
  end                
Raw

A slightly more ruby way, scopes are obsolete

posted 2 years ago

Untitled

https://github.com/cameroncox/bogart

A nifty little micro framework, in PHP.

Feedback, forks, pull requests welcome

posted 3 years ago

Quick little MaxMind API wrapper

                require 'httparty'
module MaxMind
  class API
    class << self; attr_accessor :key; end
  end

  class Request
    include HTTParty
    base_uri 'http://geoip3.maxmind.com/'

    def self.find_by_ip(ip)
      get '/f', :query => { :i => ip, :l => API.key }
    end
  end
end                
Raw

Just a simple little API wrapper for a proof-of-concept application.

posted 3 years ago

nvie's gitflow at develop - GitHub

http://github.com/nvie/gitflow

Neat git extension for managing your git workflow.