From the category archives:

Technology

RESTful design and the HTTP request

April 20, 2008

No Gravatar

One of the biggest changes in Rails 2.0 is the way the framework pimps RESTful design.

??!@#$%^&*??

My thoughts exactly. Understanding what REST was/did/accomplsiehd was a bit of a struggle for me, hopefully, I can do a good job of breaking the concept down into tasty, digestible portions.

Disclaimer:
If you’re a robotic code monkey like myself, my over-simplified terminology may anger you. By all means, if I am incorrect, which I often am…correct me…but please…think of the kids! Don’t nitpick, it’s just not cool.

The HTTP Request

Before I can explain what REST is, you need to have a basic understand of how your web browser communicates with web servers. Let’s start with something you are familiar with. When you visited my blog, this is what happened:

  1. You typed in www.jonathansng.com

  2. Your browser sent a request to the server

  3. My server responded with HTML

  4. Your browser rendered that HTML

Well…beneath all this seemingly simple transaction, a few more, albeit important things are occurring. Using the same example as above, this is what is really happening:

  1. You typed in www.jonathansng.com

  2. Your browser sent a request to the server (called an HTTP request)

  3. My server responded to that HTTP request

  4. Your browser rendered the HTML that was returned

A HTTP request is like a little sticky note that is passed on to the web server. When the web server gets this note, it can read over the note and determine what action it needs to take place. There are eight different kinds of HTTP requests.

There are two kinds of requests that you should be most comfortable with. The “GET” request and the “POST” request. The “GET” request does exactly what it states, it gets the content of some resource from the server, identified by the URL Working with HTML, it should come as no surprise that the “POST” request is used to send (or POST) data to a URL, eventually creating a new resource.

Resources

I hate to use technical jargon, but some things can’t be side-stepped. Okay, take a deep breath and clear your mind. Stop thinking of the internet as “web pages”, from now on when you’re in Rails land, you need to think of the internet as a “resource.”

You might be a little bit confused, because as I’m writing this, I’m trying to think of a good example. Okay.

Let’s say you click through my site…the about résumé, my portfolio, and about me page. Web pages right? Wrong. These are resources! Take my résumé for example; if I printed it out on paper and handed it to you, it’d still contain everything you’d see if you would have accessed it on the web…but now it’s on paper! What if I took a screen capture and saved it as a JPG; or how about an Adobe PDF? Do you see where I’m going with this?

The “web page” you accessed was just one way to format the resource, in this case, my résumé.

The OTHER HTTP requests

Stick with me for a little while longer. Earlier, I mentioned there were eight types of HTTP requests, well here are all of the HTTP requests:

  1. HEAD
  2. GET
  3. POST
  4. PUT
  5. DELETE
  6. TRACE
  7. OPTIONS
  8. CONNECT

All I want is for you to be aware of these request types, I’m sure you already guess what a few of these do, but don’t freak out if you have no idea.

Let’s tie it all together

Let’s use our Bookstore application as an example. Now, what if I were to tell you this URL could do two different things:

  • http://localhost:3000/books/1

Say what? Do you remember what I said about HTTP requests?

Okay…imagine this…say you want to view book #1, when you click the above URL you are sending a HTTP “GET” request to the server; once the server gets your HTTP request it responds with the information you requested, in this case the title and description for book #1.

Well, after reading over the description I’ve decided book #1 sucks. I want to delete it. If you mouse over the “Destroy” URL for the bookstore app, you’ll notice the URL is as follows:

  • http://localhost:3000/books/1

Hey wait…that’s the same URL as the “Show” link! You are 100% correct. So how can one URL serve multiple purposes? You guessed it, the HTTP request!

When you click the “Destroy” link, you’re sending a HTTP “DELETE” request to the web server. When the web server gets your request it sees you want to DELETE book #1.

Crazy.

Take some time to let this all soak in, it’s actually quite important. You’ll see just how important this RESTful design is when we start digging into our Bookstore application.

You may have noticed I haven’t explained what REST actually stands for, honestly, I have no idea, does it really matter….probably not, but if you’re particularly curious, Wikipedia has the no-nonsense low down on everything we’ve discussed and then some.

I think this is a good point to take a break, not to mention it’s 11PM and I want to play Call of Duty 4. Recently, I added my blog to feedburner, if you want an instant update when I add a new post, subscribe! As usual, leave me a comment for better or worse…if you’re feeling like a badass you can even Digg this or donate to my beer fund!

Until next time folks….

The next tutorial has been published: Rails’ Relationships

{ Comments }

Alexa Updates Website Ranking Methodology

April 18, 2008

Alexa recently released news that they have “better rankings,” and “improved methodology” and have moved past using their Alexa Toolbar as one of the main sources for its rankings. I have always called Alexa the CEO’s site meter tool as the toolbar itself wasn’t even available for MACs. I think every CEO or marketing manager has installed the toolbar at one point in time to check their ranking and it has been used widely by marketing professionals as a research tool for competitive intelligence.

Alexa Ratings

I haven’t used the site or toolbar in over a year and for comparative site reporting I usually frequent sites like Compete.com and Quantcast.com which the industry and website owners have implemented and are using in great numbers to report on their own demographics and to share information to their vertical or category for ranking. These two services have free features and provide pretty detailed information for general comparison reporting or trending. If you have the cash to pay for yearly access to Hitwise, comScore or Nielsen’s net ratings then let me know so you can run a few reports for me too. Those subscriptions are costly and I haven’t seen much value in them unless you are in an interesting vertical and are looking for websites to advertise on that you might not have realized were in your demographic.

I wish sites like 100Hot.com still existed and MediaMetrix still published their top 100 website report online for free. I think I’ll give Alexa another try and see if they are delivering something worthwhile now.

{ Comments }

PHP vs Rails

April 4, 2008

No Gravatar

I was milling over some old PHP code today, funny, because my friend Norm linked me to David Hansson’s blog post…it looks like PHP is a Friday thing!

After looking at my old code, I thought to myself, hmm, what better time to showcase the beauty of Rails. I made a post on a message board I frequent, and there was quite a bit of discussion. Anyways, take a look at this!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
header("Content-type: text/html; charset=utf-8");
include_once('inc.functions.php');
require('inc.drawrating.php');
 
$uid = $_GET['uid'];
 
$conn= mysql_connect("localhost","db","dbpassword") or die (mysql_error());
mysql_select_db(ave_development) or die(mysql_error());
 
 
$q = "SELECT views FROM stores WHERE uid=$uid";
$result = mysql_query($q,$conn);
$tmp = mysql_fetch_object($result);
$views = $tmp->views;
$views++;
 
$lview = date("Y-m-d H:i:s");
$q = "UPDATE stores SET views=$views, last_view='$lview' WHERE uid=$uid";
mysql_query($q, $conn);
 
$q = "select * from stores where uid = $uid";
$result = mysql_query($q,$conn);
$row = mysql_fetch_object($result);
 
$name = $row->name;
$phone = $row->phone;
 
if ($phone == 0) { $phone = ""; } else { $phone = " - " . format_phone($phone); }
 
$description = $row->description;
$description_lb = str_replace("\n", "<br>", $row->description);
 
$address = $row->address1;

This is the code I would use if I were to do the same thing in Rails.

1
2
3
4
5
# the controller
class StoresController < ApplicationController
 @store = Store.find_by_id(params[:id])
 @store.increment!("views")
end
1
2
3
# I'd place this in my 'show' view
<%= number_to_phone(@store.phone) if @store.phone.exists? -%>
<%= simple_format(@store.description) -%>

{ Comments }

Free online dating that’s truly free!

April 3, 2008

No Gravatar

April 2nd was the cumulation of four months of work, yesterday we launched Meeta.com our free dating website. Using a rapid development framework, known to all of you guys as Ruby on Rails, we’ve been able to move from conceptual models to a production stable product in a very short amount of time!

Along the way, I’ve seen first had the power of Rails, the benefit of RESTful design, and the necessity of comprehensive test coverage. Drop in, sign up, check it out! Now that we’ve hit our beta launch
date, I’ll be back with even more Rails tidbits that I’ve learned
during these four months :)

71-37-25-72:trunk jon$ rake stats
(in /Users/jon/Sites/meeta.com/trunk)
+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers          |  2071 |  1683 |      37 |     214 |   5 |     5 |
| Helpers              |   342 |   293 |       0 |      32 |   0 |     7 |
| Models               |  1766 |  1364 |      38 |     165 |   4 |     6 |
| Libraries            |   458 |   340 |       5 |      48 |   9 |     5 |
| Integration tests    |     0 |     0 |       0 |       0 |   0 |     0 |
| Functional tests     |  2106 |  1730 |      36 |     249 |   6 |     4 |
| Unit tests           |  1176 |   935 |      38 |     145 |   3 |     4 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                |  7919 |  6345 |     154 |     853 |   5 |     5 |
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: 3680     Test LOC: 2665     Code to Test Ratio: 1:0.7

{ Comments }

Google Adwords Updates Display URL Policy

March 26, 2008

Google recently announced a major update to their display URL policy in AdSense ads in an effort to further incorporate landing page quality to their bid and CTR algorithm which determines what position your ad appears and how relevant the keyword that you are buying is to your landing page.

What do I need to know about the updated display URL policy?

Based on feedback from both our advertisers and users, and consistent with our efforts to present relevant results, we’ll no longer allow certain exceptions to our display URL policy. These include, but aren’t limited to, redirects and vanity URLs. In line with our existing policy, we’ll continue to require that your ad’s display URL matches its destination URL (the URL of your landing page). This policy will be strictly enforced for new ads, regardless of previous exceptions. For more details about the current display URL policy, please visit https://adwords.google.com/support/bin/answer.py?answer=47173

.

Here are some other important aspects of the policy you may want to keep in mind:

Tracking URLs - Your ads will be approved if the URL of your landing page domain matches that of your display URL domain.

For example, the following would be acceptable:
• Display URL: www.google.com/adwords
• Destination URL: www.trackingurl.com/google123
• Landing page URL: www.google.com

However, this example would be unacceptable:
• Display URL: www.google.com/adwords
• Destination URL: www.trackingurl.com/google123
• Landing page URL: www.trackingurl.com

Sub-Domains

The use of sub-domains and additional text within the display will continue to be acceptable, provided the top-level domain matches the URL of your landing page.
For example, the display URLs below would be acceptable for the landing page URL of http://sub.google.com/miscellaneous, as the top-level domains match:
• sub.google.com
• google.com/extratext
• www.google.com/extratext

Quality Score

Note that changing your display URL may affect your ad’s Quality Score and ad position.

Keyword URLs

Keyword URLs are considered your destination URL (the URL of your landing page); your ad’s display URL must match its destination URL.

Next Steps

While no immediate action will be taken on existing ads, we encourage you to make the necessary changes to all ads within your account. This will ensure that your ads run without being disrupted by future disapprovals related to this policy enforcement. Visit https://adwords.google.com/support/bin/answer.py?answer=6272 for step-by-step instructions for editing your display URL.

Share This

{ Comments }

I am a certified AdWords Professional

March 10, 2008

No Gravatar

 

I qualified last week and am now an AdWords Professional and our company, Add Three, is now an AdWords Qualified Company!

Those of you who are managing AdWords media campaigns should seriously look into the AdWords qualification. The training program offers a plethora of information, some of it will even be information that is new to you! The training program is 9 sections long, encompassing everything from initial signup all the way to the developer API. To become certified, you must meet some prerequisites:

  • pass the test with 75% or greater within the 1h 30min test window
  • have an account in good standing for t least 90 days 
  • for an individual, manage a 90 day ad spend of $1,000 or $100,000 in the US (this varies by country) 

As an AdWords Professional Google will offer you access to the My Client Center, API access, the Qualified Individual/Company designation, and some other miscellaneous perks.

Learn more about the program at the Google AdWords Professional page.

{ Comments }

View SQLite data with columns

March 5, 2008

No Gravatar

SQLite allows us to quickly and effortlessly get our Rails applications off the ground. Having used MySQL, I was used to formatted data queries . The first time I used a SQLite database, I was in for a little shock.

add3-imac:trunk jon$ sqlite3 db/development.sqlite3
SQLite version 3.4.0
Enter ".help" for instructions
sqlite> SELECT * FROM users;
1|straight|man|Seattle|1@msn.com|1928-03-03|t|2008-02-21 11:40:05|2008-02-21 11:40:05
2|straight|man|Portland|2@msn.com|1928-03-03|t|2008-02-21 11:40:09|2008-02-21 11:40:09
3|straight|woman|Oregon|3@msn.com|1928-03-03|t|2008-02-21 11:40:12|2008-02-21 11:40:12
sqlite>

That is a little tricky to decipher…let’s try something a little different!

sqlite> .headers on
sqlite> .mode column
sqlite> SELECT * FROM users;
id     orientation gender   city    email    birthday  subscribed created_at      updated_at
---------- ----------- ---------- ---------- ----------- ---------- ---------- ------------------- -------------------
1      straight   man     Seattle   1@msn.com  1928-03-03 t      2008-02-21 11:40:05 2008-02-21 11:40:05
2      straight   man     Portland  2@msn.com  1928-03-03 t      2008-02-21 11:40:09 2008-02-21 11:40:09
3      straight   woman    Oregon   3msn.com   1928-03-03 t      2008-02-21 11:40:12 2008-02-21 11:40:12
sqlite>

That’s more like it!

{ Comments }

Import a MySQL dumpfile into your database

March 4, 2008

No Gravatar

After you have used MySQL to dump your database, FTP that dump file to an accessible directory on your server.

Once you have uploaded the dump file to your account here, make your way back to command line and get ready to import the file!

Now to import the dump file into MySQL, use the following command at your shell prompt:

# USER is your MySQL username
# DBSERVER is your database servername, not always required
# dbname is your database name<br># dbname.sql is the dump file you are importing
# -p will prompt for your password
 
mysql -u USER -p -h DBSERVER dbname < dbname.sql

If your preferences are properly set, the same thing can be accomplished with:

mysql < dbname.sql

Enjoy!

{ Comments }

Use MySQL to dump databases

March 3, 2008

No Gravatar

Often times you will need to dump your MySQL database from one machine to another. Sometimes you can use utilities like PHPMyAdmin, but it’s always useful to know how to dump your database’s contents manually.

add3-imac:~ jon$ mysqldump -u username -p databasename >/tmp/databasename.sql

{ Comments }

Calculating eCPM

March 3, 2008

I got an email from one of my buddies in the industy asking how to calculate how much they can afford to pay on a CPM for ads outside PPC using the performance data from advertising on PPC content. Here are some fictious numbers he sent over for the example:

PPC Content Stats:
488,000 Impressions
350 Clicks
18 Conversions
$95.00 Ad Cost
5.6% Click Thru Rate

Ad Cost / Impressions = 1.946
1.946 * 1000 = 0.19 CPM

Does this mean we pay roughly $0.19 CPM?

The only missing piece to this equation is the CPA that they are willing to pay for each conversion. Using these numbers they are currently getting a $5.20 CPA on content ads. If they were able to pay $20 CPA then they should effectively be able to buy CPM traffic on a network like AdBrite for around 0.80 - $1.00 depending on the quality of the placement. I would just use this as a gauge and not be afraid to test out networks like DrivePM, MSN DR, Yahoo Class 2 and Advertising.com. Sometimes you’d be surprised running wider reach categories that your ad might perform in areas that you would of never thought of like Maps, Web Mail and IM messenger placements.

If you want to effectively test display banners you should have a budget of about $10k and should A/B test several ad sizes like 728×90 leaderboards, 300×250 square box ads and 160×600 skyscraper units. I have seen different sizes perform better for different types of businesses. You’ll want to get at least 1M impressions on each banner to get good enough conversion and CTR performance results.

Oh yeah, BTW “eCPM” = effective CPM for you acronym junkies.

Share This

{ Comments }