LAMP On Focus

Icon

PHP, MySQL, Linux practical usage.

YUI CSS Compressor IE problem

I am using the YUI JavaScript / CSS compressor from yahoo to compress our JS & CSS.
While using it I encountered a rather strange problem, the compressed CSS was working fine in Firefox but not in IE. Upon investigating it came down to a peculiar problem.
One of our CSS has a CSS rule like.,

{ height: expression( this.scrollHeight > 96? "96px" : "auto" );}

After running thru the YUI compressor it becomes.,

{height:expression(this.scrollHeight>96? "96px":"auto");}

The above CSS works fine in FF but not in IE (tested in IE8 & IE7)
when I change the above CSS as given below it works fine. Notice the space before and after the > symbol

{height:expression(this.scrollHeight > 96? "96px":"auto");}

For some strange reason after giving those spaces every thing was fine with IE.,

Any Idea whats going on here ? Bug in IE, YUI or the CSS ?

anyway, I just ran a `sed` replace command on the CSS folder to fix it now. Any other elegant fix are welcome.

find . -name "*.css" -print | xargs sed -i 's/>/ > /g'

I am back

Whew.., been really long, sorry for not replying to the questions on the tools. Was totally on short for time trying to get my 9 month old to settle in, Since I brought him back to Bangalore from my native.

Will try and post more often.

jSuggest Enhanced 1.1 – Auto-complete Using jQuery

Change Log
- Fixed: Handling multiple spaces in keywords.
- Fixed: On empty results drop down border visible.
- Added: Keyword highlighting can now be either as string/words

Highlight Mode

The hlMode Option defaults to “string” mode, other supported format is “word”

On the drop down when keyword high lighting is on, till now the highlighting was done only as a string, Now it can be done as both string or word, like.,
when search is as “apple fruit” and the search result is “apple is a fruit” if the hlMode is set to word then both apple and fruit in the drop down will be highlighted.

highlight: true,
hlMode: "string"

Download :
jquery.jSuggest.1.1

Subverion : Check out files affected during a specific commit revision

I am using SVN for my code management, and recently I needed to get only the files that where commited on a particular version. Looking around there was no straight way of doing this. But, this can be achived by the following steps.,
Get the list of files commited on a particular revision number.
svn log </local/svn/checkout/path/> -qv -r<revision_number> | awk '/\//{print $2}'

 svn log /home/raja/coderepo/ -qv -r12423 | awk '/\//{print $2}' 

Export the files one by one by specifying the filename & revision number explicitly.
svn export -r<revision_number> <repository_url> <target_directory>/<file_name>

 svn export -r12423 http://svn.rajavarma.com/trunk/ /home/raja/svndump/r12423/myfile.php 

Have wrapped the process in a simple PHP script which you can download svn.export.revision.files.php here.

jSuggest Enhanced – Auto-complete Using jQuery

jSuggest Enhanced updated to 1.1

I was looking for a lightweight simple auto-complete using jQuery, found a perfect one that fits my requirement, enter jSuggest an excellent lightweight auto-complete control based on the beautiful jQuery.

However I needed some extra’s like,

  • Trigger callback function on a ‘Click’ / Selection from the drop down.
  • Highlight the search keywords in the drop down list.
  • Support for JSON data

and do I hooked up these minor enhancements to the core.

You can download the patched version from the link at the bottom of this post.

Data Format

The dataFormat Option defaults to “json” format, other supported format is “html”

dataFormat: "json"

Highlight Keywords

The highlight Option defaults to “true” for highlighting search keywords on the dropdown.

highlight: true

The actual display differentiation has to be done on the CSS level for the high light to show.

#jSuggestContainer ul li var{background:#FFCC65; font-weight:bold;}

On Select Callback

The onSelect Option defaults to “” (empty), When a callback function name is given, the given function is called with the selected text.

onSelect: "callback_function_name"

Hope this helps some one.

Original Contol at : Keansphere (jSuggest)
Patched file : Enhanced jSuggest

Facebox Extended.

I was looking for a lightbox like control which is easy to customize.
Landed on a excellent control “facebox“. As we needed some additional functionality in addition to the ones available I have made some enhancements to it.

Create Modal Window

Clicking on the overlay layer or the Esc key will not close the window, forcing the user to respond to the popup window.

jQuery(document).ready(function($) {
$('a[rel*=facebox]').facebox({modal:true})
});

Switch off footer

Does not display the footer div on the popup.

jQuery(document).ready(function($) {
$('a[rel*=facebox]').facebox({footer:''})
});

Replace the content of the window.

This addition allows you to replace the content of the loaded Facebox window with a new content. Quite handy if you want to display response of a form submit from within the modal window.

$.facebox.content(<new_content>);

//Example.,

$.get('http://www.domainname.com/form/submit/url.php', 'params', function(data){$.facebox.content(data)})

Hope these changes will be helpfull for some one.
Download the modified version : Facebox Extended

Daemons in PHP

A ‘daemon’ in Linux is program that runs continuously in the background without user intervention processing data.
For instance if we need to parse a log file, or process uploaded videos.

So we write a script and `fork` it separately as an individual process, this can be done in PHP using the Process Control Extensions. Getting a good grip on it, will take some studying. Though the time spent on it would be a valuable if you are in for a lot a heavy duty processing. The pcntl extensions are not available in PHP by default, you have to compile the CGI or CLI version of PHP with –enable-pcntl configuration option when compiling PHP to enable Process Control support.

An another way to run a script in background when pcntl functions are not available to you, would be by writing the script in a unconditional while loop. But make sure you have the logic to stop the process on failure within the loop.

while (1) {
//The complete process

  if (condition_to_stop === true) {
    break;
  }

Then execute this from a control script. Start this a separate process redirecting all the out put to the void.

$processId = shell_exec("nohup /usr/bin/php process.php 1>/dev/null 2>&1 &");

Make sure you do not depend on any output printed in the screen by process.php, as in the above command we send all the output including the error’s into the /dev/null black hole.

Run ifconfig as a non-root user

Recently I needed to extract the ip number of the box on which my script was running, and had to decide the behaviour of tool.
Upon digging around, worked out a command snippet that worked, as given below.

ifconfig eth0|sed -n "/inet addr:.*/{s/.*inet addr://; s/ .*//; p}"

But the problem was ifconfig only works as a `root` user if you try it as a normal user you would get a command not found.

$ ifconfig
-bash: ifconfig: command not found

The problem is the `sbin` folder under which the `ifconfig` command resides is not added to the`PATH` environment variable by default.

all you have to do is the following.

$ export PATH=$PATH:/sbin
$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/raja/bin:/sbin

Now as we have added the `sbin` folder to the `PATH` variable, try the command again it will work.

You don’t want to set the path each time you login. You can add it to your `.bashrc` file in your home folder to update the path
automatically each time you login.

Here is how you do it.,

$ vi ~/.bashrc

add the following line at the end of the file.

export PATH=$PATH:/sbin

Save and close the file. From the next time you log-in the `sbin` folder will be available to your `PATH` variable.

In case you need to reload the .bashrc file immediately issue the following command

$ source ~/.bashrc

NOTE : It works only on a readonly mode. Trying to set the interface parameters as a non root user will generate error.

$  ifconfig eth0 192.168.0.1
SIOCSIFADDR: Permission denied
SIOCSIFFLAGS: Permission denied

Pixel Tracker

A Web bug is an invisible 1×1 clear gif that is embedded in a web page or e-mail. These can be used in your emailers to track the actual views of your marketing mailers, capture user data on navigation patterns and high visit areas on your site.

Leave it to your imagination as to what to do with it.

We need the following list of operations in our tracker, for it to be of any use.

We need a appropriate p3p policy.

header("P3P: CP="NOI DSP COR NID ADMa OPTa OUR NOR"");

We need a transparent 1×1 pixel gif image.

//Image header
header("Content-Type: image/gif");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache");
header("Cache-Control: post-check=0, pre-check=0");
header("Pragma: no-cache");

//Image Data
$gifData = base64_decode("R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==") ;

echo $gifData;

When we have cleared this 2 points, we log the data we need.

On this script, we have a day wise table rotator, a new table will be created for every day.
The script is pretty much self descriptive.

So, go ahead and give it a try.

Download the Tracker Script here.

Message From India

“Forgiving a Terrorist is left to GOD:

But fixing their appointment with GOD is our Responsibility”

~~INDIAN ARMY

Calendar

March 2010
M T W T F S S
« Feb    
1234567
891011121314
15161718192021
22232425262728
293031  

Bookmarks

  • No bookmarks avaliable.

Friend Connect