iPhone/iPod JavaScript Redirect

JavaScript redirect For iPhones/iPods Specifically

<script language="javascript">
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
    {
        location.replace("http://url-to-send-them/iphone.html");
    }
</script>

Forgotten TO-DO’s

I’m not sure about all the rest of the Developers out there but my biggest problem is coming back to finish TO-DO’s.

I have always marked temporary code hacks, or code that needed improvement with a // ::TO-DO:: {description of issue}.

I finally got sick of going through old code and seeing multiple ::TO-DO:: blocks.

I wrote this tiny shell script and run it nightly from cron.

#!/bin/sh
echo "Starting ::TO-DO:: Search for (project)"
echo ""
grep -r -n "::TO-DO::"  (/PATH/TO/PROJECT/FILES/) (/PATH/TO/PROJECT/FILES1) (/PATH/TO/PROJECT/FILES2) -B1 -A3

Just ensure there is an email address for the cron output or you will have to pipe greps output to mail, mailx, mutt, or something similar.

The -r flag tells grep to search recursively for each path.
The -n flag adds line numbers on the offending line.
The -B1 and -B3 adds the prior line and three following lines to the output.


CSS Columns: Fixed width and fluid “remainder”

I encountered a little issue with a simple 2 column layout for a small project I am working on. The left column was to be fixed at 220px and the right needed to be what was left of the screen width.

After several attempts, it ended up being quite easy.

<style>
    .main .left-col{width: 220px;float:right}
    .main .main-content{overflow: hidden}
</style>
<div class="main">
    <div class=".left-col">
        <!-- Content -->
    </div>
    <div class=".main-content">
        <!-- Content -->
    </div>
</div>

Public key authentication over SSH

Generate key on local machine

ssh-keygen -t rsa

Ensure that the remote server has a .ssh directory

Make sure the server your connecting to has a .ssh directory in the home directory of the user you are doing this for. If it doesn’t exist you can run the ssh-keygen command above, and it will create one with the correct permissions.

Copy your local public key to the remote server

If your remote server doesn’t have a file called ~/.ssh/authorized_keys then create it. If that file already exists, you need to append the contents of ~/.ssh/id_rsa.pub to it.

cat ~/.ssh/id_dsa.pub | ssh user@remote.server "cat - >> ~/.ssh/authorized_keys"

Now ssh to the remote server

Your should be able to ssh to the remote server without being asked for a password.

Security

All someone would need to login to the remote server, is one file on your local machine ~/.ssh/id_rsa, so keep it secure.

Getting asked for a password

If you are getting asked for a password, check the permissions.

server$ chmod 700 ~/.ssh
server$ chmod 600 ~/.ssh/authorized_keys

All The Cheat Sheets That A Web Developer Needs

Posted by Bogdan over at topdesignmag.com

No matter how good programmer you are, you can`t memorize everything. It often happens to spend more time searching for a particular library, tag or declaration, than implementing it on our code. To ease your work I have gathered here some of the most important cheat sheets that you will ever need. Do you have any suggestions?

It’s good shit – go check out the full post: http://www.topdesignmag.com/all-the-cheat-sheets-that-a-web-developer-needs/


Removing “X-Authentication-Warning” headers

After moving some scripts to a different server I noticed a small change in email deliverability. Possibly unrelated but I did notice “X-Authentication-Warning” headers were being added to outgoing mail sent by php.

The problem

“X-Authentication-Warning” headers like the following were being added:

X-Authentication-Warning: xxx.domain.com: www-data set sender to user@example.com using -r

The solution

In order to prevent this you need to have the “trusted users” feature enabled in Sendmail (I believe it is by default in Red Hat Enterprise Linux):

Locate your submit.mc (should be in /etc/mail/submit.mc) and add:

FEATURE(use_ct_file)dnl

Open “/etc/mail/trusted-users” and add “www-data”:

root@smtp [~]# echo "www-data" > /etc/mail/trusted-users

Restart Sendmail:

root@smtp [~]# /etc/init.d/sendmail restart

**NOTE**

You have just set your web server as a trusted sender. You do not want to do this on a shared hosting server.


Converting Lighty (Lighttpd) Rewrites to Nginx

It was actually quite easy, once I checked the error logs and realized that I never created the rewrites :P

Lighttpd:

url.rewrite-once = (
    #open rate
    "^/images/email/([0-9]+)/([a-zA-z0-9]+)/([0-9]+)/email-logo-([a-zA-z0-9]+).gif"  => "/open.php?email_id=$1&type=$2&cid=$3&ab=$4",
    #opt out
    "^/outfast/(.*)" => "/optout.php?action=optout&a=fast &click=single&hash=$1",
    #click
    "^/go/([0-9]+)/([0-9]+)/([0-9]+)/(.*)"  => "/click.php?cid=$1&email_id=$2&link_id=$3&extra=$4"
)

Nginx:

#opt out link
    location /outfast/ {
        rewrite ^/outfast/(.*) /optout.php?action=optout&a=fast&click=single&hash=$1 last;
    }

#click through rate
    location /go/ {
        rewrite ^/go/([0-9]+)/([0-9]+)/([0-9]+)/(.*) /click.php?cid=$1&email_id=$2&link_id=$3&extra=$4 last;
    }

#open rate
    location /images/email/ {
        rewrite ^/images/email/([0-9]+)/([a-zA-z0-9]+)/([0-9]+)/email-logo-([a-zA-z0-9]+).gif /open.php?email_id=$1&type=$2&cid=$3&ab=$4 last;
    }

The biggest thing to notice is the lack of quotes and the “last” keyword at the end of each rewrite (in these cases at least)


Twitter Delicious Facebook Digg Stumbleupon Favorites More