How to check if a Javascript variable is an array

Looking for the simplest way to check if a Javascript variable / object is an array? Here’s a simple way on how to check for an Array variable in javascript:

function isArray(variable) {
if (variable.constructor == Array)
return true;
else
return false;
}

or better yet, just do this:

function isArray(variable) {
return (variable.constructor == Array);
}

Bash script to empty a mysql database

I wrote a bash shell script that deletes all the tables in a mysql database and I thought I’d just post it here in case anyone might find it useful. It accepts one required argument which is the database name and one optional argument which is the username with DROP/CREATE DATABASE privileges to dbname .

#!/bin/bash
if [[ ${1} == '' ]]
then
echo “”
echo ” `basename ${0}` {dbname} [{user}]”
echo “”
echo ” {dbname} - is the name of the mysql database to zap”
echo ” {user} - optional, user ‘root’ is used as default”
echo “”
exit 1;
else
read -p “Are you sure you want to empty ${1} [Y/N]? ” ans
if [[ ${ans} == "y" || ${ans} == "Y" ]]
then
user=${2:-”root”}
echo -n “Using mysql user ‘${user}’, ”
mysql -u ${user} -p -e “drop database ${1};create database ${1};” && echo “${1} emptied.”
exit 0;
else
echo “Aborted.”
exit 1;
fi
fi

Note: Oh and be careful in using the script ‘coz it will erase all the data in your database so make sure you have backups. ;-)

How to empty a mysql database

This morning I was doing some tests and I found myself having to use a web-based mysql tool called phpmyadmin to delete all the tables in a mysql database.

Since I was to do it several times, I decided to use the command line interface program mysql. I was kinda surprise that I didn’t find any single command to drop all the tables, anyway deleting all the tables can be done by issuing the following command:

sh$ mysql -u username -p -e “drop database dbname; create database dbname;”

You will need to specify a username with drop/create privileges for the dbname database. It will then prompt for the user’s password when you hit enter on the command line.

Using mailto links in web pages

Yesterday, I found myself in a situation, wherein I wanted to provide a mailto link that will not only include a subject but also an initial body when a web site visitor clicks on the link.

I was quite sure that it was possible but couldn’t remember how to do it so after some googling, I found a “MailTo Syntax” page that describes how it’s done.

In the message body you can actually include html links that a person can email to friends. You’ll just have to url encode the text so that it will be properly included in the email message body when the user clicks on the link. If you need a url encoder, you can use this online form.

Project Gazell source code released to public

In an effort to improve private torrent trackers the Project Gazelle team has created a reliable, lightweight and secure codebase. It was designed from the ground up to be secure against SQL and XSS injection attacks and at the same time be able to handle thousands of users.

The source code, which is currently undergoing beta, is available via the Project Gazelle SVN. The source code comes with a C++ based tracker, PHP frontend and complete administration panel.

You can find more info at the Project Gazelle web site.

The .NET Source Code soon to be released

Looks like Microsoft will be releasing the source code for the .NET framework for the soon to be released version 3.5 of the framework. ScottGu has made the announcement on his blog.

This is welcome news for .NET developers because it will help a lot in creating and debugging .NET software. The .NET source code release offers integrated debugging in Visual Studio 2008 allowing developers to step thru the framework’s source code.