Increase productivity with Todoist

If you’re like me, you’d want to keep your ever busy life a bit organized. Being a techie, you’d first find a tool that will facilitate you in doing so. Most of us are fan of a number of such tools: RememberTheMilk, BackPack, Ta-Da List, 30boxes, Microsoft OneNote, Stickies etc. I’ve also tried all of them and a few others, stuck with them for a few days, but later lost the interest. This happened until one of colleagues, Anis, suggested me to have a look on Todoist.

At first sight, I thought it as “okay…another web 2.0 brainchild”. It seemed too simple to handle my complicated needs and I did not have high ambition with it. But as days passed, I was discovering new new features of it and gradually it became a part of my life. I’m a big fan of Getting Things Done (GTD) approach and Todoist became my dropbox for all the tasks in my mind.

If you ask me what’s so special about Todoist, I’d mention the following few features:

Simplicity

Todoist is damn simple and hosts one of the most powerful yet sleek web 2.0 interface on the web. It allows you to have an unlimited nested category/project list and under each of them, unlimited nested task list. This is something that most other tools miss. For me, it’s a super MUST feature.

(more…)

Extended Model for CodeIgniter

Feb 2009: An updated version of the code for CodeIgniter 1.7.x can be found here.

I developed this extension of CodeIgniter’s Model last year, but never had the chance to publish it. The main purpose of this extension is to make a dev’s life easy. This extension has been used by several of my devs at RBS and has been proved to increase productivity and reduce the number of painful small queries to write. Their enthusiasm has driven me to post this for the CI fans out there.

Without much babble, let’s get into point. I’ve explained the process of installing it and then showed some example uses. For starter, click here to download it. Now follow these steps to get started:

1. Replace the system/libraries/Model.php file with the attached Model.php (CodeIgniter version 1.6.3)

2. For each of your tables, you will need to create a model file in system/application/models.

3. Lets say we have a “products” table whose schema is as follows:

1CREATE TABLE `products` (
2 `id` int(11) NOT NULL auto_increment,
3 `title` varchar(50) NOT NULL,
4 `description` text NOT NULL,
5 `color` varchar(20) NOT NULL,
6 `price` float NOT NULL,
7 `category_id` int(11) NOT NULL,
8 `featured` char(1) NOT NULL,
9 `enabled` char(1) NOT NULL,
10 `visits` int(1) NOT NULL,
11 `created` int(11) NOT NULL,
12 `modified` int(11) NOT NULL,
13 PRIMARY KEY (`id`)
14) ENGINE=MyISAM;

4. Now we need to create system/application/models/product.php:

1<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2
3class Product extends Model
4{
5 function Product()
6 {
7 // Call the Model constructor
8 parent::Model();
9
10 // Load the associated table
11 $this->loadTable('products');
12 }
13}

5. From any controller, you can load the Model as instructed in the CI manual. Here are some sample usage of the model functions:

1function products()
2{
3 // Load the model in the default way
4 $this->load->model('Product');
5
6 // Total # of products
7 echo $this->Product->findCount();
8
9 // Total # of featured products
10 echo $this->Product->findCount("featured = 'Y'");
11
12 // Retrieve ALL the products
13 $allProducts = $this->Product->findAll();
14
15 // Retrive id, title and price of top 10 products (based on popularity) that are enabled
16 $topProducts = $this->Product->findAll("enabled = 'Y'", 'id, title, price', 'visits DESC', '0', '10');
17
18 // Retrive id, title and price of the 1st most popular product that is enabled
19 $topProducts = $this->Product->find("enabled = 'Y'", 'id, title, price', 'visits DESC', '0', '10');
20
21 // Retrieve the product with id = 1
22 $oneProduct = $this->Product->read(1);
23
24 // Retrive the price of the product whose id = 1
25 $productPrice = $this->Product->field('price', 'id = 1');
26
27 // Single array with the titles of all the enabled products
28 $productArr = $this->Product->generateSingleArray("enabled = 'Y'", 'title');
29
30 // Insert a new product in the db
31 $newProductId = $this->Product->insert(array('title' => 'New Product', 'price' => '10.99'));
32
33 // Update the price of the newly added product
34 $updProduct = $this->Product->save(array('price' => '20.00'), $newProductId);
35
36 // Delete the product
37 $this->Product->remove($new_product_id);
38}

7. There are a number of other helpful functions in this file. If you have a careful look, you’ll discover that some of them are really handy.

UPDATE: I forgot to give due credit to the wonderful developers of CakePHP – I’ve taken inspiration from their Model implementation while building this one for CodeIgniter.

Download

MORE UPDATE: Download the version for CodeIgniter 1.7.x here.

jQuery Essentials – Round 3

I still receive a good number of hits to my first (10 jQuery Essentials) and second (jQuery Essentials – Round 2) collection of jQuery plugins. So, I have been thinking about making the next post in the series for quite some time. Time has always been the killer of ideas, along with the fact that not too many plugins found way to my list of favorites.

Now that I have some fresh essentials, this post was inevitable.

[poll id=”2″]

18. jQuery UI

ui

This is the official big boss with a number of core interactions (drag, dropping, sorting, selecting, resizing) and few great widgets (accordions, date pickers, dialogs, sliders, tabs) built on top of those. Although its a great collection, I somehow haven’t been able to use it in any real projects yet. It seems small plugins always get a favor than big collections 🙂

19. Facebox

facebox

This is a cute, little plugin that shows Facebook style dialog boxes using jQuery. It supports nearly all the possible contents you might want to show in a dialog box: image, div, remote pages. It has both automatic behavior and manual invoking. Simple and fun to me.

(more…)

Cross-Domain AJAX calls using PHP

AJAX has become the core component of many web applications around us. And its fairly easy to handle AJAX now a days, with the help of various javascript libraries (ex: jQuery, Prototype, Mootools, YUI, etc). But there is one security issue that web browsers impose in doing AJAX calls – they don’t let you do AJAX calls in web servers different than yours. That means, if your script is in www.mydomain.com and you’re trying to do AJAX call to www.anotherdomain.com/get.php, then the browser will through error like: “Error: uncaught exception: Permission denied to call method XMLHttpRequest.open”.

Now, there are a number of solutions to this problem. Instead of explaining them all to you, lemme provide you the simplest one: using a PHP transport file. If you already know the thing and just need the script, download from here.

Others, let’s see an example implementation first.

Example use

   1: xmlHttp.onreadystatechange=function()
   2: {
   3:     if(xmlHttp.readyState==4)
   4:     {
   5:         alert(xmlHttp.responseText);
   6:     }
   7: }
   8:  
   9: xmlHttp.open("GET", 'http://myserver.com/transport.php?action=' + 
  10:                     urlencode('different-server.com/return_call.php') +
  11:                     '&method=get&data1=101&data2=pass', true );
  12:  
  13: xmlHttp.send(null);

Now, lets see how it works:

  1. The script makes an AJAX call to the myserver.com/transport.php with a few parameters:
    • action = the target URL you need to fetch, from a different domain
    • method = the HTTP method (post/get)
    • data1, data2 = sample parameters for using as either query-string or POST fields
  2. When the request is received by transport.php, it uses cURL to make a call to the page mentioned in action.
  3. Based on the method, it either makes a GET request or a POST request. In both cases, it sends the extra parameters that are sent.
  4. After the response is received, transport.php echoes it. So, you have what you need!

Download

transport.php
Cross-Domain AJAX call transporter.
Downloaded: [downloadcounter(transport)] times

Comments and suggestions are most welcomed 🙂

HTTP Class for PHP (supports both cURL and fsockopen)

Feb 2009: A couple bugs have been fixed and library updated.

This is a wrapper HTTP class that uses either cURL or fsockopen to harvest resources from the web. It supports a handy subset of functionalists of HTTP that are mostly needed in day to day coding. Scripts who need to communicate with other servers will find it useful. If you’re looking to invoke any RESTful API and don’t want to bother adding a bunch of libraries for that simple thing, just put this class and you’re set.

Download

Detailed documentation can be found here. And you can download the source from here.

Update

Class added in Orchid – “PHP framwork for the rest of us”

Features

  • Can use both cURL and fsockopen.
  • Degrades to fsockopen if cURL not enabled.
  • Supports HTTP Basic authentication.
  • Supports defining custom request headers.
  • Supports defining connection timeout values.
  • Supports defining user agent and referral values.
  • Supports both user-defined and persistent cookies.
  • Supports secure connections (HTTPS) with and without cURL.
  • Supports adding requests parameters for both GET and POST.
  • Supports automatic redirection (maximum redirect can be defined).
  • Returns HTTP response headers and response body data separately.

Example 1 – Simple Get (Facebook Application List)

1<?php
2
3include_once('class.http.php');
4
5$http = new Http();
6
7$http->execute('http://www.facebook.com/apps/index.php?sort=6');
8echo ($http->error) ? $http->error : $http->result;

Example 2 – Invoking Yahoo Term Extraction API

1<?php
2
3include_once('class.http.php');
4
5$http = new Http();
6
7$http->addParam('appid' , 'a_really_random_yahoo_app_id');
8$http->addParam('context' , 'I am happy because I bought a new car');
9$http->addParam('output' , 'xml');
10
11$http->execute('http://search.yahooapis.com/ContentAnalysisService/V1/termExtraction');
12echo ($http->error) ? $http->error : $http->result;

Example 3 – Logging into Basecamp (without using cURL!)

1<?php
2
3include_once('class.http.php');
4
5$http = new Http();
6
7$http->useCurl(false);
8$http->setMethod('POST');
9
10$http->addParam('user_name', 'emran');
11$http->addParam('password', 'hasan');
12
13$http->setReferrer('https://someproject.projectpath.com/login');
14$http->execute('https://someproject.projectpath.com/login/authenticate');
15
16echo ($http->error) ? $http->error : $http->result;

Example 4 – Getting a protected feed

1<?php
2
3include_once('class.http.php');
4
5$http = new Http();
6$http->setAuth('emran', 'hasan');
7
8$http->execute('http://www.someblog.com/protected/feed.xml');
9echo ($http->error) ? $http->error : $http->result;