Learning AJAX with Coffeescript, jQuery, PHP, and SQLite Part 2

Today we are going to talk database. For small learning projects like this, I love sqlite. I like it because I don’t have to worry about installing and getting a separate database running, it doesn’t take up system resources when I’m done using it, and I can store the database with the code in subversion. This is handy if, like me, you find yourself developing on several different workstations.

Project Setup

In the document root of your PHP server, create a folder called quotes. Within the quotes folder, create another folder called data. Our folder structure now looks like this quotes\data.

Since sqlite is so easy, we could create a new file in our data folder, rename it quotes.db, call it good and do the heavy lifting with PHP. But, since the only compelling reason to develop on Windows is the plethora of gui tools, we are going to make it even easier.

  • Download SQLite Adminstrator from here.
  • Create a new database (call it quotes.db if you like) and save it in the data folder.
  • Run this query:
    CREATE TABLE quotes (id INTEGER PRIMARY KEY AUTOINCREMENT, q_text TEXT, q_author TEXT, q_source TEXT)

That pretty much covers it from the database side. Not a lot of code in here yet, but, at least its something. Till next time.

Learning AJAX with Coffeescript, jQuery, PHP, and SQLite Part 1

We recently went through a huge migration at work (Lotus Notes to Exchange) and I needed a way to decompress, so I thought I would learn something new. I have some previous experience in web development, so I thought a little project like this would be fun.

The Tools

Let me dwell a second and give some of the reasoning behind the tools I’m using here.

SQLite: I like SQLite for learning applications because it is quick, easy, and, since it is a file based database, I can replicate the changes through SVN. This way, no matter which work station I sit at, I can have the exact environment I left…even the database.

PHP: I programmed with PHP at my last job and despite the fact that I enjoy the syntax of python better, PHP is still a great tool.

jQuery: its hard to do anything involving JavaScript without mentioning jQuery. It’s shortcuts are priceless.

Coffeescript: Obviously the least known tool in the stack, one may wonder why you need anything more than jQuery in order to write good JavaScript. And, you’re right. You don’t “need” Coffeescript. You don’t even need jQuery. I stumbled upon Coffeescript a while back and really related to the syntax. JavaScript, especially the proper scoping of variables, remains somewhat of an enigma to me. Coffeescript helps me translate it into something I understand a bit better.

The Setup

This walk through doesn’t require much, but, I always find the best place to start is the beginning. Before we can write some code, we need to setup our environment.

PHP

Any LAMP, WAMP, MAMP, or BAMP setup will work just dandy for anything I will be doing in the next couple entries (although we won’t be using the M part of any of those setups since we’ll be using SQLite instead of MySql.) Usually, on Windows, I prefer the Zend Community Server. The only stipulation is that the version of PHP needs to be able to do PDO. Correct me if I’m wrong, but, I think your pretty safe with any PHP version that starts with a 5.

Coffeescript

The trickiest part of the development environment is getting Coffeescript setup. If your setup has any *nix in it, you’ll have to take a detour through here to get that figured out. Once you have Node.js working, its as easy as:

npm install -g coffee-script

For those of you following along on your Windows box, I have a different solution. Following the instructions here:

  1. Download the Node.js executable for windows from http://nodejs.org/#download and run the installer.
  2. Download Coffeescript from http://github.com/jashkenas/coffee-script/tarball/master, extract (use 7-zip if you need to), and place in your Program Files directory.
  3. Create a new text file on your desktop and rename it to coffee.cmd. Edit the file so that it contains the following text:
    @echo off
    "%PROGRAMFILES%/nodejs/node.exe" "%PROGRAMFILES%/CoffeeScript/bin/coffee" %*

    Note:If you are running 64-bit Windows, you can either replace "%PROGRAMFILES%/Node/node.exe" with "C:\Program Files (x86)\nodejs\node.exe" or move your nodejs folder from C:\Program Files (x86) to C:\Program Files. Its your call.

  4. Move coffee.cmd to your C:\Windows\System32 folder

If all is well in Coffeescript land, you should be able to open a command line, type coffee and enter an interactive session. Use ctrl-c to exit.

With that, we should be all setup. Tune in next time and we will actually write some code.

The pot calls the kettle black. Facebook v Google

I read an article this morning about the smear campaign Facebook hired a PR firm to run against Google. You can read the full article here.

The explosion of irony happens when Facebook states its reasons for the campaign:

  1. Facebook believes Google is violating users privacy (which Google may be doing–I am not familiar with the particular Google service the article mentions).
  2. Facebook believes that Google “may be improperly using data they have scraped about Facebook users.”

This would be equivalent to Facebook taking your personal information, publishing it on a billboard, and then crying foul at Google for looking at the billboard.

All I can say is /facepalm.