Archive for category development
Triggering the Source Code view of the current page using JavaScript
Posted by admin in development, javascript on March 29, 2008
I was recently writing a demo to showcase the new Google Language API, and in my demo I did the usual thing of instructing users to View > Page Source in order to view the source code and comments. I know this is less than ideal, because it forces users to have to process the instructions, and then execute them. Somewhere in there you lose them and they never execute the desired action.
It got me thinking: is there a way to have the source code in front of them in one click? A few Google searches later, and the answer was yes!
Using JavaScript you can open a new window to display the source code view of the current window:
-
window.open('view-source:' + window.location.href, 'mysource');
Voila! How easy was that? Now it's your turn.
Recommended Mozilla Firefox add-ons (aka extensions, aka plugins)
Posted by vinoaj in DOM, HTTP, development, firefox, html, javascript on July 30, 2007
This is a list of my "must-have" Mozilla Firefox add-ons. If you can recommend anything similar or better, be sure to drop me a comment.
Page Analysis & SEO
Minimise Nuisance
Bookmark Management
Download Management
Productivity
Web Development & Design
Security
Functional Extensions
Tab Management
Add-Ons Management
Page Analysis & SEO
About This Site Bookmarks - right-click on a page, select "About This Site Bookmarks" and you will see a list of handy links pointing off to informational sites such as Alexa, Compete, Netcraft, del.icio.us, etc.
Minimising Nuisance
Bookmark Management
Download Management
Download Statusbar - manage your downloads via the Firefox status bar.
DownThemAll - conveniently download all link targets on a page.
FlashGot - allows for single and multiple downloads utilising an external download manager of your choice (I prefer FlashGet).
Productivity
Auto Copy - highlight a piece of text and the selection is automatically copied to your clipboard.
FoxClocks - displays local times around the world in the statusbar or toolbar. Great for if you are dealing with friends and colleagues across multiple timezones.
FoxyTunes - operate your currently running media player from your Firefox statusbar.
Google Notebook - conveniently clip text and links to your Google Notebook.
Linkification - Converts text links (including e-mail addresses) into clickable links.
Web Development & Design
ColorZilla - eye-dropper tool that allows you to pick the HEX & RGB values of colours of elements on the page.
Firebug - the quintessential Javascript debugger. It also allows for excellent DOM and CSS debugging and manipulation.
IE View - open the current page in an IE window.
Live HTTP Headers - view HTTP request and response headers in realtime.
User Agent Switcher - allows you to spoof the User-Agent string and have Firefox masquerade as the Googlebot, etc, to see how your site reacts to different user-agents.
View Source Chart - renders page source HTML in an easy-to-read manner.
Web Developer - a must for the serious web developer.
YSlow - an addon to the Firebug debugger. It allows you to profile a page and identify bottlenecks. Provided by Yahoo. Also see Yahoo's articles on improving page load performance.
Security
McAfee SiteAdvisor - lets you know if the currently viewed site is considered "safe" or not.
Functionality Extensions
CustomizeGoogle - customize your Google search and application experiences.
ErrorZilla - extends the standard page not found error screen with convenient links such as access to the page's Google cached copy.
Tab Management
Faviconize Tab - minimize a tab's width to the width of the favicon.
Add-Ons Management
FEBE - a convenient extensions & settings backup tool. Allows you to also run scheduled backups. The backups can be used to transport your extensions and their settings to another machine or Firefox profile.
MR Tech Local Install - install power tools for add-ons
Selecting a random row using MySQL
Posted by vinoaj in development, howto, mysql on July 25, 2007
There are many examples where you would need to retrieve a random record or more from a set of tables. For example your page template may be cycling through QOTDs, testimonials, offers, specials, and so forth.
To retrieve a random row in MySQL, use the ORDER BY RAND() statement to randomly order the rows of a table. Then use LIMIT x to retrieve the first x rows from the randomised representation of the table.
For example:
-
/* Retrieve 5 random special offers to display in your e-commerce store's sidebar */
-
SELECT offer_id
-
FROM special_offers
-
ORDER BY RAND()
-
LIMIT 5
Of course, we can make our query as complex as needed, and then randomly order the resultset.
-
SELECT so.offer_id, i.title
-
FROM special_offers so
-
LEFT JOIN items i ON (so.item_id = i.item_id)
-
LEFT JOIN item_categories ic ON (i.item_id = ic.item_id)
-
WHERE ic.category_id = 2344
-
ORDER BY RAND()
-
LIMIT 5
PHP code snippet – Reorder items in a table
Posted by vinoaj in db, development, howto, php on July 9, 2007
This snippet of code reorders items in a table based on the number of steps you want to move an item from its current position. It moves the item of interest to its new position and shifts all other items to their new shifted positions.
-
function moveItem ($n_steps) {
-
if ($n_steps == 0) {
-
return;
-
}
-
-
$cur_pos = $this->pos;
-
$new_pos = $cur_pos + $n_steps;
-
-
if ($n_steps <0) {
-
$min_pos = $cur_pos + $n_steps;
-
$max_pos = $cur_pos - 1;
-
$shift_sign = '+';
-
} elseif ($n_steps> 0) {
-
$min_pos = $cur_pos + 1;
-
$max_pos = $cur_pos + $n_steps;
-
$shift_sign = '-';
-
} else {
-
return;
-
}
-
-
$id = $this->id;
-
-
//Reorder existing items that will be existed by moving this item
-
$sql = "UPDATE positions
-
SET order_num = order_num $shift_sign 1
-
WHERE id = $id
-
AND position>= $min_pos
-
AND position <= $max_pos";
-
-
$this->db->query($sql);
-
-
//Now set new position for this item
-
$sql = "UPDATE postions SET position = $new_pos WHERE id = $id";
-
$this->db->query($sql);
-
}
svn – Ignore/exclude files from version control
Posted by vinoaj in development, howto, svn on July 5, 2007
In most projects there are going to be files that you wish to ignore in version control. These could be temporary files, log or debug files, and so forth. These are files that you can safely ignore when executing commands such as svn commit and svn st. The following shows how to configure your svn client to ignore particular files in your working copy.
svn propedit svn:ignore /path/with/files/to/ignore/
svn opens up your text editor of choice
Use file patterns to indicate which files to ignore from version control. Each pattern goes on a new line. e.g.
log_12*.log *.tmp
Save your file and exit
Now whenever you perform commands like svn st or svn commit, svn will ignore files with the patterns you specified in the directories that you specified.