Tuesday, September 30, 2008

Javascript catching mouse click event and know what DOM element is being clicked

Asking some great encoders in irc.freenode at #javascript channel, people are having an extensive help to me.
I got this code working, but here I use the mootools JS Library but still the same as native javascript syntax.

$(document).addEvent('click', function(e){
console.info(e.target.get('id'));
});


// This works in IE
$(document).attachEvent('onclick', function(e){
alert(e.srcElement.id) // gives the id of the element being clicked
});

Through it, it does prints or gives me the id of the element being clicked. It's really cool knowing this technique.


Monday, September 15, 2008

Counting the tables in MySQL Database

Finding ou how cool MySQL is, I gathered this statement that might be useful when doing a CLI tasks.

select count(*) as number_of_tables from information_schema.tables WHERE table_schema='schema_name';

OR

select count(*) as number_of_tables from information_schema.tables WHERE table_schema='schema_name' and table_type = 'BASE TABLE';


The latter one does only selects those base tables, BASE TABLE is actually a MySQL valid value of a table_type. This link can give some information about schema -> http://dev.mysql.com/doc/refman/5.0/en/information-schema.html

Saturday, September 6, 2008

Inline-download problem with IE browsers

IE's problem again faces some criticism to my part. I came up of this snippet
that does an inline download of a file.

Adding of
header("Cache-Control: maxage=1"); //In seconds
header("Pragma: public");
heals the problem when a file is in buffer at the client's browser. Problem occurs here is when a
user attempts to open a file, it does tells that the file sort of not found or whatever Microsoft tells.

"

filename = unique_string(8);


$fp = fopen("/tmp/{$filename}", 'w');
fwrite($fp, $contents);
fclose($fp);

header("Cache-Control: maxage=1"); //In seconds
header("Pragma: public");
header( 'Content-Type: ' . 'application/pdf' );
header( 'Content-Disposition: inline; filename="' . basename("/tmp/{$filename}") . '.pdf' . '"');
// Add the rest of the headers
header( 'Cache-Control: public' );
header( 'Content-Transfer-Encoding: binary' );
header("Content-Length: " . filesize("/tmp/{$filename}"));

readfile("/tmp/{$filename}");
unlink("/tmp/{$filename}");

"

Viewing the file through an inline-download is over HTTPS so this is a SSL problem with IE.

Detecting plugins for pdf


I just found this site that can detect acrobat reader in browser plugins.
Here's the link: http://gemal.dk/browserspy/acrobat.html

Viewing the source code of that page, i found these lines in the script which does the detection of pdf plugin.

<object id="ocx_pdf" classid="clsid:{CA8A9780-280D-11CF-A24D-444553540000}" style="display:none"></object>
<script type="text/javascript"><!--
var i_acrobatreader;

var v_acrobatreader;

var a_acrobatreader;

if (obj(navigator.plugins)) {

for (var i=0; i < navigator.plugins.length; i++) {

if (navigator.plugins[i].name.toLowerCase().indexOf("adobe acrobat") >= 0) {

i_acrobatreader = true;

v_acrobatreader = navigator.plugins[i].description.substring(navigator.plugins[i].description.toLowerCase().lastIndexOf("version ") + 8, navigator.plugins[i].description.toLowerCase().lastIndexOf(" for"));

break;

}

}

}

// --></script>

<script type="text/vbscript"><!--

on error resume next

num = 0

myarray = array("PDF.PdfCtrl.1", "PDF.PdfCtrl.2", "PDF.PdfCtrl.3", "PDF.PdfCtrl.4", "PDF.PdfCtrl.5", "PDF.PdfCtrl.6", "PDF.PdfCtrl.7")

do until num = 6

set tmp = CreateObject(myarray(num))

if IsObject(tmp) then

i_acrobatreader = true

v_acrobatreader = num

end if

num = num + 1

loop

if IsObject(ocx_pdf) and i_acrobatreader then

a_acrobatreader = ocx_pdf.GetVersions

end if

// --></script>

....

<script type="text/javascript"><!--

if (i_acrobatreader) {

document.writeln("Yes");

if (v_acrobatreader) {

document.writeln(" - version " + v_acrobatreader);

}

} else {

document.writeln("No or unable to detect...");

}

// --></script>



....



<script type="text/javascript"><!--

if (i_acrobatreader) {

if (a_acrobatreader) {

var comps = a_acrobatreader.split(",");

for (var i = 0; i < comps.length; i++) {

var detail = comps[i].split("=");

if (detail[0])

document.writeln(detail[0] + " version " + detail[1]+"<br />");

}

} else {

document.writeln("Unable to detect...");

}

} else {

document.writeln("Acrobat Reader not installed.");

}

// --></script>


In my previous applications, by garnering some concepts from other snippets, I came up to this:

<script language="javascript" type="text/javascript">
<!--
    /*<![CDATA[*/
    var hasAcrobat = navigator.mimeTypes && navigator.mimeTypes["application/pdf"];
    /*]]>*/
//-->
</script>  <script type="text/vbscript">
<!--

on error resume next
num = 0
myarray = array("PDF.PdfCtrl.1", "PDF.PdfCtrl.2", "PDF.PdfCtrl.3", "PDF.PdfCtrl.4", "PDF.PdfCtrl.5", "PDF.PdfCtrl.6", "PDF.PdfCtrl.7")
do until num = 6
    set tmp = CreateObject(myarray(num))
    if IsObject(tmp) then
        hasAcrobat = true
        v_acrobatreader = num
    end if
    num = num + 1
loop

// -->
</script>  <script language="javascript" type="text/javascript">
<!--
    /*<![CDATA[*/

   
    if (! hasAcrobat) {
        window.location = '<?=$_SERVER['REQUEST_URI']?>&forceDL';
    } else {
        window.location = 'some_php_script.php?filesrc=<?=base64_encode($sourceDoc)?>';
    }
    /*]]>*/
//-->
</script>

Tuesday, September 2, 2008

CSS Hide Background

I just found this css snippet to somewhat like disabling the elements behind if a dialog box appears.

/* Enables to disable elements behind */
.somethingDialogUnderlayWrapper {
position: absolute;
left: 0px;
top: 0px;
z-index: 998;
display: none;
background: transparent;
}

/* colors to a disabled-color */
.somethingDialogUnderlay {
background: #eeeeee;
opacity: 0.5;
}

Monday, May 19, 2008

WebFaction.com details on their tools and customer service

This morning, I was spending my time looking for web hosting and I got this WebFaction.com.
Previously, it was recommended also to me by Wilson Miner (one of Django Framework's developer).

Well definitely, as a programmer, you would be glad to know others suggestions or recommendations
whom you might have to think as a guru or expert in some other fields that you would like to be.

I did send a message to WebFaction.com, and I say wow to their fast reply. They have a good customer
service and good technical staff, if you might be getting some of the topics on their forum.

Here's what I've got from them...

"
Hi Paul,

> Hi WebFaction,
>
> I would like to know the versions of tools you have in the server for
a shared hosting plan.
>
> - PHP (if it's php 5 or lower, and what version is it 5.2? 5.3?)
v5.2.4

> - Apache
v2.2.3

> - Python
v2.5.1, v2.4.3

> - Mysql
v5.0.22

> - Ruby
v1.8.6

>
> I wanted also to know if WebFaction runs the PHP as a CGI in Apache
or if it runs PHP as a module. Or is it possible to make these both
running or perhaps if not, possible to change like from PHP on apache
module to PHP on CGI or vice versa.

PHP runs as a module on our main Apache instance. If you need some
other configuration, you could compile, configure, and run your own Apache
from your home directory.

> I'm hoping for you reply because I love to avail on your hosting but
I need first the assurances I wanna have!

Thanks for considering WebFaction for your hosting needs :)

Regards,

Sean Fulmer
"


Well, seems like they are a type of hosting that is running for Web 2.0 standards. Great to have them!
The are ultimately gaining up their popularity in the web hosting business.