What is a programming framework?

by Yang Yang on May 2, 2009

Programmers write programs for users so certain processes in the workflow can be automated for efficiency and correctness.

As such, to improve the programming efficiency of similar projects for addressing a common set of related problems, such as the need for content management system in web authoring, some programmers write programming frameworks to integrate the bare bone workflow of a system that acts like a prototype. It is then on the prototype that more details are added and project-specific needs are satisfied.

While you can create a php website from scratch, spinning out code line by line, you may also consider using one of the frameworks such as cakephp and zend framework to accelerate your development if you are familiar with one of them.

However, it’s not all goodness coming out of enjoying such an established foundation. First of all, you have to learn them and some modern frameworks such as Zend Framework are well established that it’s just not easy to master it. While you may spend time learning other people’s framework, you can easily create your own, especially if you have done enough coding and prototyping and have always wanted to be faster in production by reducing repeating stuff, which is the essence of programming frameworks.

Every seasoned programmer has his own library of frameworks, one way or another. If you speak PHP, you may want to read this php framework comparison article by chad.

{ 1 comment }

VeriSign, the central registry for COM domains, recently released a new tool called Data Analyzer. Data Analyzer allows you to check the amount of traffic a domain name gets, even if the domain does not exist.

So just the kind of traffic analysis tool that examines the type-in traffic of unregistered domains (.COM). Well, not just type-in. Imagine a domain that has some history but recently got abandoned, wouldn’t it be great to know that? To sum up, you can use this tool to:

  1. Grab valuable unregistered .com domains with decent type-in traffic.
  2. Know mistyped versions of your current domains, those your visitors tried but failed to get to your site.
  3. Hunt for abandoned or dropped domains that have a history and traffic.

The tool has just now been released to domain registrar Dynadot at this address. If you are not already a Dynadot customer, sign up for an account.

Where does the data come from?

Verisign, being the central registry for COM domains, also runs the root name server for COM domains. Each time you type in a domain name in your browser, Verisign’s root name server will receive a query for that domain name. Verisign stores all queries, including those for domains that do not exist, in their massive Data Analyzer database.

How do I use the Data Analyzer?

You can find the Data Analyzer by logging into your Dynadot account and clicking on the “Search” tab and then “Data Analyzer Tool” sub menu.

On this page you can submit a list of domain names that you want to check the traffic for. They will send your domains to Verisign, and the next day you can sign back into your account and check the results. Each domain name will receive a score between 0 and 10. 0 means no traffic, and 10 means lots of traffic.

How can the Data Analyzer help me?

Say for example you own the domain name “acmewidgets.com“. You want to check to see if your customers are mistyping your domain name, and thus not getting to your website. You can submit a list of domains to the Data Analyzer such as:

axmewidgets.com
acmwidgets.com
acmewigets.com

If any of these domains return a high score, then you can register the domain name, and forward the traffic to your correct domain name.

How many domains can I upload?

You can upload as many domains as you want. In fact some customers have already uploaded millions of domains to be analyzed by the Data Analyzer. However, if you upload lots of domains, it may take many days to finish analyzing your domains. Verisign limits the number of domains Dynadot can submit to them each day.

{ 1 comment }

Katrina Costedio Steals (KatrinaCostedio.com)

by Yang Yang on April 29, 2009

Katrina Costedio currently lives in Sarasota, Florida and has a small design firm (katrinacostedio.com) that attends to small business needs doing all kinds of design work: print design, card design, logo design and web design. She’s planning to go to San Francisco, California, though.

I worked for her on 2 projects, namely maahs acupuncture clinic site, including PSD to CSS/HTML service and a php contact form; and obrienorganics.com including ALL stuff that’s basically from PSD design to everything – PSD to CSS/HTML, php CMS and shopping cart. Other than these, I have helped her with other sites as well:

  1. some wordpress work for burkethejerk.com
  2. fixing a few css and javascript errors for searchlight-partners.com
  3. there’s some more I can’t remember now…

Katrina Costedio would have been a good lady, if she has kept her words and not stolen my work without paying me a penny.

Below is an email message I planned to send her but understandably as  she might have blacklisted me, I’ll just post it here for all to see:

So obrienorganics.com launches with my code? You know you haven’t paid me a penny for it, so technically it’s all my property and you are stealing. We never had any contract that says if all goes this way, you unconditionally own everything I did.I thought you said you would be losing thousands dollars more to finish what I started. I beg your pardon. It’s you who shut me off from the servers and projects by suddenly changing all the login passwords. I feel stupid and betrayed the next morning when I found out I couldn’t log in any more. Not to mention you never started from scratch again. Instead, you stole my work shamelessly for your own clients. Because I have spent a month on your project and it’s almost done!

Katrina Costedio is stealing.

You crapped my code as unsecure and stolen yet you use it with no shame. What kind of b*tch are you? (I still have all her original words in my mail box.)

Also we haven’t finished up with my “copyright” issues yet, which file did you say I stole from other people and didn’t even bother to remove the copyright information? Ohhh, if it happends to be jquery.js or csshover3.htc, they are licensed under LGPL for crying out loud and almost all sites use them! I can’t believe you were trying to come up with this kind of shit to demonize me? So that you can take my hard work free? At least get a programming class before doing that, katie.

{ 2 comments }

I dismiss SEO

by Yang Yang on April 28, 2009

Other than a descriptive title and a few describing words about what the current page is about, there’s no more needed to be done SEO-wise. No more. Period.

Why, when I can create art, fulfill dreams, amuse and please my users and make them feel they have never been treated so well on other sites, should I spend majority of the time doing SEO chores and hunting for a few pathetic back links?

{ 3 comments }

It’s hard to describe this scenario precisely with limited title length. Basically, this is when you want to dedicate a field in ‘category’ table to store the number of articles or posts in ‘post’ table that fall into this category.

Previously, you had both ‘category’ table to store post categories and ‘post’ table to store posts. Each post must fall under a category for the sake of categorization referenced by a field named ‘category’ in table ‘post’ that bears the ID of the category in table ‘category’ that this post belongs to.

I hope I have made myself clear on this.

Problem

Now the problem is that you want to display the count of posts under each category and there are apparently a large number of them so preferably you don’t want to count through them all each time a web page is loaded so as to reduce mysql server load.

Solution

The solution is obvious. You’d make an additional column for table ‘category’ arbitrarily named ‘count’ for example. And update it once there’s an addition to the posts or a deletion from the existing. Now how do we do that.

Assume that there are only 2 columns in the current ‘category’ table, one is ID and the other is TITLE. To create another category table from the existing one with an additional ‘count’ field:

CREATE TABLE category2 SELECT category.id AS id, category.title AS title, COUNT( post.category ) AS count
FROM category, post
WHERE post.category = category.id
GROUP BY post.category 

This would create a new table called ‘category2’ that’s no different from the original ‘category’ table except for the additional column we just added: ‘count’.

Executing this single SQL query, not only is the new column created but they are also filled with the count of the posts that are assigned to each of the category.

The last task of this job will be to drop the original ‘category’ table and rename ‘category2’ to ‘category’.

Another Solution

By the help of an extra temporary table, you can also add a number / count column by combining the following 2 tips:

  1. Create a temporary table of rows with id and count: counting records number.
  2. Transfer the statistics from the temporary table to the newly created column of the original table: update more than one rows with a single update query.

{ 1 comment }

Different number notations for different numerical bases:

0144  // base 8
 100  // base 10
0x64  // base 16

To convert between number bases, use PHP base_convert() function:

$hex = 'a1'; // hexadecimal number (base 16)
$decimal = base_convert($hex, 16, 10); // $hex converted from base 16 to base 10 and $decimal is now 161
$bin = '101'; // binary number (base 2)
$decimal = base_convert($bin, 2, 10); // $bin converted from base 2 to base 10 and $decimal is now 5

base_convert() function changes a number string from the original base to the target base number string. Other than this, there are also other specialized base conversion functions in PHP that’s basically created around decimal (base 10):

// convert to base 10
print bindec(11011); // 27
print octdec(33);    // 27
print hexdec('1b');  // 27

// convert from base 10
print decbin(27);    // 11011
print decoct(27);    // 33
print dechex(27);    // 1b

{ 0 comments }

Degrees and radians are different metric means to gauge an angle. They are mutually convertible in PHP. Simply use the PHP degrees to radians function deg2rad() and PHP radians to degrees function rad2deg().

$degrees = 180;
$radians = deg2rad($degrees); // 3.1416
$degrees = rad2deg($radians); // 180

Because trigonometric calculations are usually done in radians, you have to convert the degrees into radians:

$cosine = cos(deg2rad($degrees));

{ 0 comments }

To display numbers to end users, especially large numbers, you may need to format them to be more user friendly. For example, with a large integer 43386000.75, it is usually preferred to comma-separate every 3 digits to this:

43,386,000.75

To format numbers this way in PHP, you need number_format() function:

print number_format(43386000.75); // prints '43,386,000.75'

This is English notation of numbers with thousands separator. For French number notation:

print number_format(43386000, 2, ',', ' '); // prints '43 386 000,75'

Deducing from the parameters used in the above example, we have the number_format() function synopsis:

string number_format ( float $number , int $decimals , string $dec_point , string $thousands_sep )

With number_format(), you can format any integer number of floating point number by thousands separator (which in most cases is a comma), decimal point (which usually is a period point), number of decimal digits after the decimal point.

{ 4 comments }

PHP: Send HTML Email (mail)

by Yang Yang on April 23, 2009

As we all know the simplest approach to create an email message and send it out is to use the php mail() function. A typical usage example would be:

mail('recipient@email.com', 'Subject Title', 'Message body goes here.');

However, as the mail() function sends emails in text/plain mime type by default, if you include HTML code in the message body, it would not be interpreted as HTML at all. Instead, all the tags and attributes are displayed as they are.

To work around this and send HTML email with PHP mail() function, you will have to modify the message mime type to text/html. In practice, use the mail() function with an additional argument to set arbitrary headers for the email message:

$to = 'recipient@email.com';
$subject = 'Purchase Successful!';
$message = '
<html>
<head>
	<title>Purchase Successful!</title>
</head>
<body>
	<p>Here are the order details:</p>
	<p> ... </p>
	<p><a href="http://www.example.com">back to store</a></p>
</body>
</html>
';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

mail($to, $subject, $message, $headers);

Now the email dispatched to the recipient will have all the HTML in it working as expected.

{ 13 comments }

Some strings of texts may lack necessary wraps and don’t have natural line breaks in them so that the lines are too long to read comfortably. Therefore, you want a way to insert line breaks in to the string every dozens of characters.

The php function you need is wordwrap():

$s = ' ... '; // very long single line string text
$s_wrapped = wordwrap($s, 60); // $s is wrapped by every 60 characters and evaluated to $s_wrapped

Line breaks are inserted into the original text every 60 characters.

{ 2 comments }