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 June, 2007

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 ()