1 0 Archive | tutorials RSS feed for this section
post icon

Javascript function to uncheck all checkboxes

Yesterday I searched and searched for a good hour for some unobtrusive javascript to set all check boxes within a div to unchecked when a user would click “None” for a none of the above type form, when I realized that, duh I know how to write javascript. So I wrote this function.

Javascript:

function $(id) {
 return document.getElementById(id);
}
window.onload = initPage;
function initPage() {
 var productDiv = $("products");
 var productList = productDiv.getElementsByTagName("input");
 var productReset = $("product-none");
 productReset.onmouseup = function() {
  for (i = 0; i < productList.length-1; i++) {
   productList[i].checked = false;
  }
 }
}

HTML:

input value="1" name="product[]" id="Carpeting" type="checkbox" Carpeting
input value="2" name="product[]" id="Hardwood Flooring" type="checkbox" Hardwood Flooring
input value="3" name="product[]" id="Ceramic Tile" type="checkbox" Ceramic Tile
input value="4" name="product[]" id="Ceramic Tile" type="checkbox" Ceramic Tile
input value="5" name="product[]" id="Kitchen/Bathroom Cabinets" type="checkbox" Kitchen/Bathroom Cabinets
input value="6" name="product[]" id="Counter Tops" type="checkbox" Counter Tops
input value="7" name="product[]" id="Major Appliances" type="checkbox" Major Appliances
input value="32" name="product[]" id="product-none" type="checkbox" None

I’ve taken out the html tags cause it was causing this page to format wrong so you’ll have to just understand how the tags would look. Someone tell me how to get around this?

So basically this javascript creates an window onload then finds the div with id => “products”. Then finds all the input elements and puts them into an array. Then finds the input with the id => products-none. Then creates a function to run a for loop across the array and sets all check boxes value “checked” to false when a user releases a mouse click on the products-none input.

I’ve only tested this in Firefox 2.0 Mac OS X
Feel free to use it modify or what ever you like!

Leave a Comment
post icon

Create TextMate todo list to keep track of your work

How to…do… a TODO, FIXME and CHANGED in TextMate comment for other developers in your office, network, whatever… So you’ve got an html, php, erb, python, ruby etc file. Just add the appropriate comment for your language followed by TODO, FIXME or CHANGED like this:

The within your project you can either hit; (Mac) shift+ctrl+t or go to; Bundles -> TODO -> Show TODO List

Which will bring up a window with all the TODO, FIXME or CHANGED items within your project. This makes it easy to find areas than need work or tell the other developers in your team wtf is up.

Leave a Comment
post icon

Grab color values from anything on your mac os screen

Digital Color Meter is a cool application located in Applications/Utilities/DigitalColor Meter.app. You can color pick anything on your screen and grab the color value in different formats to use in your projects.

Update: You can also use shift + command + c to copy the color as a hex value and paste it into your favorite editor.

Leave a Comment
post icon

Automate your mysql backups

Here’s a way for you to backup your mysql databases automatically. You can configure it to do it when ever you like. Code was found on dreamhosts wiki written by Matttail

First log on to your home directory with an ftp client or ssh. Create a backups dir and a backups/archives dir.

ssh yourdomain.com

If you have a problem logging in it’s probably because you don’t have shell access, which you should be able to set up with your host from their panel)

Run these commands from the command line in your home dir:

mkdir backups
mkdir backups/archives

Then open your favorite text editor and create a file with this code. Replace the User, pass mysqlA.domain.com db_nameA with your info. If you want more then just copy paste the mysqldump lines and fill them in accordingly. Save this file as mysql.sh and then upload it to the backups dir.

#!/bin/bash
cd /home/username/backups/
mkdir mysql
suffix=$(date +%y%m%d)
mysqldump --opt -uUser -ppass -h mysqlA.domain.com db_nameA > mysql/db_nameA.$suffix.sql
mysqldump --opt -uUser -ppass -h mysqlB.domain.com db_nameB > mysql/db_nameB.$suffix.sql
tar -cf archives/mysql_backup.$suffix.tar mysql/*
rm -r mysql/

Then you will need to set up a cronjob so from the command line:

crontab -e

Place the following in this file:

MAILTO="you@yourdomain.com"
27 23 * * 3 /home/username/backups/mysql.sh

You can takeout the MAILTO if you don’t want it to email you errors if there are any when the script is ran. The 27 23 * * 3 is the date the script is ran, which is 11:27pm on the 3 day of the week. Edit these if you like. Mine is set to 0 2 * * 1, which is 2:00am Monday. Type CTRL O to save the file and CTRL X to exit the crontab.

That’s it! Your done! If you want to test the script run this command under the backups dir:

./mysql.sh
Leave a Comment
post icon

Methods to hide email addresses from page source

Just stumbled upon a good site called csarven, that has a bunch of interesting ways to keep bots away from email addresses on web pages.

Leave a Comment