Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog. You can find information on programming, linux, documentation, tips for code and database optimization, my thoughts and rants, and whatever else I feel like sharing. Feel free to contribute to the blog by posting comments and asking questions.

Archive for 2007

alter css values dynamically with javascript

Posted by chris on July 26th, 2007 Comments(0)

You can use javascripts document.getElementById().style method to alter CSS values. Here’s an example:

Create your div tag:

Now create your javascript function:

function changeCss()
{
     document.getElementById("myDiv").style.border = '2px dotted #CCC';
}

Now you can call this javascript function on any given event to alter your CSS tags border. Things like height, width, and a bunch others work as well. For instance create an html button, and onclick call the changeCss() function.

In JavaScript and Ajax ()

ajax and the xmlhttprequest object

Posted by chris on July 16th, 2007 Comments(0)

I’m teaching myself “ajax” here is how to create the basic xmlhttprequest object, interact with a server-side scripting language such as php, and display the returned xml to the page (in this case a series of html form text boxes).

Read the rest of this entry »

In JavaScript and Ajax, Programming ()

easy mysql backup

Posted by chris on July 6th, 2007 Comments(0)

Here’s an example of quick script I wrote in PHP and added as a cronjob to backup some mysql databases:

// dump database tables to sql text files //
exec('mysqldump -uroot -pPasswordHere music > /tmp/music.sql');
exec('mysqldump -uroot -pPasswordHere taskfreak > /tmp/taskfreak.sql');
// pack into tarballs //
exec("tar -cf /tmp/music.sql.tar /tmp/music.sql");
exec("tar -cf /tmp/taskfreak.sql.tar /tmp/taskfreak.sql");
// gzip tarballs //
exec("gzip /tmp/music.sql.tar");
exec("gzip /tmp/taskfreak.sql.tar");

In Linux, Programming, SQL ()

linux debian apache2 installing mod-write

Posted by chris on June 23rd, 2007 Comments(0)

To install mod-rewrite in debian type a2enmod rewrite from the shell. You will the be asked to restart apache.

A simple mod-write script that blocks anyone from hotlinking to your images would look like this:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]

You would either place this in an .htaccess file or if you have root access to the server in /etc/apache2/sites-available and then within the directory you want to protect from hotlinking.

In Linux ()

php switch/case statements

Posted by chris on June 18th, 2007 Comments(0)
switch ($i)
{
case 0:
    echo "i equals 0";
    break;
case 1:
    echo "i equals 1";
    break;
case 2:
    echo "i equals 2";
    break;
}

Update: I have a few developers at my work that have a java background and they didn’t know that you can actually include a conditional in your case, cause I guess java doesn’t let you. So for case 1 (in this instance) you could actually have it test against a variable outside the switch so it would read:

$var = 2;
switch ($i)
{
case 0:
    echo "i equals 0";
    break;
case $i == $var:
    echo "i equals 1";
    break;
case $i== $var:
    echo "i equals 2";
    break;
}

I forget where I used this code recently, but it is useful, as it makes your switch more dynamic.

In Programming ()

linux random tar stuff

Posted by chris on June 15th, 2007 Comments(0)

This will probably grow as I need tar to do more stuff.

Excluding a directory from your tarball:
tar -cf backup.tar /home –exclude “/home/cpanel”

In Linux ()

Linux Search From Shell Using Grep Find Xargs

Posted by chris on June 4th, 2007 Comments (2)

The find command is used to find files in a Unix/Linux system. The grep command is used to find text within files and output. The xargs utility is used to combine commands together. This is a demonstration of using all three to search for specific text within files recursively through the directory tree.

find . | xargs grep my string -risl

r tells the system to perform the search recursively.
i tells it to ignore cases.
s tells it to suppress error messages.
l lets it know we only want matching filenames.

You can also send the output to a file since sometimes the lists can be very long. Once in the file it can easily be browsed using VIM or you can even grep it again.

find . | xargs grep my string -risl > /mylist.grep
In Linux (, , )

Resize Images From Linux Shell using imagemagick

Posted by chris on June 3rd, 2007 Comments(0)

After installing imagemagick you can resize images:

convert -size 125x125 /path/to/image.jpg -resize 125x125 /path/to/image.jpg

Ofcourse you can do this in php by executing the shell command using the exec() function.

In Linux, Programming (, , )

a backup system – for the poor and lazy

Posted by chris on June 2nd, 2007 Comments(0)

Well I’ve put enough time and effort into my server configuration, mysql databases, and my web dev files that it was finally time to start backing up. Now I’m not completely crazy, the server does have a 3ware card in it for mirroring, but in the end its still a server in the closet (its not gay) and something bad could happen. So I spent about 2 hours writing a few backup scripts because I’m too poor for rsync and too lazy for amanda.

All you need is a cheap web host like the one I use (about $5 a month) and some time. Here’s what I did:

Read the rest of this entry »

In Linux, Programming ()

upgraded debian sarge to etch + 2.6 kernel

Posted by chris on May 22nd, 2007 Comments(0)

Well I’ve been running debian sarge with the 2.4 kernel for a long time and things came to ahead when I was unable to install some pecl and pear packages for some neat stuff I’m doing in PHP. I have a tendency to make drastic decisions. In geekdom upgrading your server to not only a new linux version about the kernel as well in one night is considered drastic…I think. I have lots of important stuff on there too, client files, mysql databases, lots of web content in /var/www and not to mention the countless hours, weeks worth of hours I’ve spent fine tuning it.

Read the rest of this entry »

In Linux ()