October 2011

setInterval() and clearInterval() Example

var t;
function show_uploaded_logo() {
   if($('div.form-item div.image-widget div.image-preview img').is('*'))
      // use console.log to test that the function has stopped running
            //code here
t = setInterval(show_uploaded_logo,1000);

Use jQuery to hide a DIV when the user clicks outside of it

     mouse_is_inside = true;
     if(! mouse_is_inside)  $('div#personalize-window').fadeOut('slow');

PHP Get Current URL

Sometimes it is not as straightforward as one may think to get the current url to use it inside your application. Here is a snippet that I use to fetch the current URL and use it in a script. The current url (whether http or https) is now a local variable that you can do with as you please.

$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] :

You should groom this value before using in anything sensitive, like a sql query.

Mobile Version of Website

To implement our changes, we first set the viewport to the device's width. Do this by inserting the following line of code into the head of your XHTML template:

chown and chgrp in one command

chown user:group filename.ext

Of Course, to change all of the files in a folder:

chown user:group folder/*

And then, once you know that, you can do multiple files/folders at once:

chown user:group folder folder/* filename.ext filename2.ext

Mobile Device Detection in PHP

function mobile_device_detect($iphone=true,$ipad=true,$android=true,$opera=true,$blackberry=true,
  $mobile_browser   = false; 
// set mobile browser as false till we can prove otherwise
  $user_agent       = $_SERVER['HTTP_USER_AGENT']; 
// get the user agent value - this should be cleaned to ensure no nefarious input gets executed
  $accept           = $_SERVER['HTTP_ACCEPT']; 
// get the content accept value - this should be cleaned to ensure no nefarious input gets executed