~ overflow ~

Archive for August, 2009

jQuery + XML + IE = xmlDOM issue … or no??

by z3n on Aug.29, 2009, under Coding, Notes

Problem:

In the middle of the developing of a very complex script i figured out that IE was simply ignoring the xml documents i sent to it by ajax. Searching the web i’ve found this $.xmlDOM jQuery extension that is supposed to fix the IE issue with xmls. Although the extesion was clear and other people claims it work, it didn’t worked for me, how lucky is that?

Solution:

This took a while to solve, and i will skip all the boring process. Turns out that i didn’t needed the $.xmlDOM extension at all, the issue was on the xml. I’m developing this script in a language that has accents, i need to use `á` like html entities in order to avoid malfuncioning with data transport, so this little ampersand was breaking IE.

How nice is that?

Leave a Comment :, , , , more...

JASC Paint Shop Pro 8-9 Issues

by z3n on Aug.26, 2009, under Tips & Hints

For as much as I like bleeding edge technologies,  I tend to use old programs to do simple tasks, like, you don’t need photoshop cs4 to do a simple screenshot copy-paste, neither you don’t need to loose time on paint doing that so. Also cs4 gif transparency and gif optmizing is just awful terrible and lame.

I still using paint shop pro 9, even deprected and replaced by corel’s super crap photo-paint.

It turns out that this program don’t work right with non-english languages, it simply gives a message `no valid temp directory defined` and quits.

I fixed this before but i keep forgetting. This is how to do it:

Open system at control painel or if you are leet, windows + pause, go on advanced -> system variables -> set/add TMP and TEMP variables for your user into a `easy` path  not that %USER% windows crapola, for me i just set both to d:\temp and that’s it. Now you can have fun with paint shop pro.

1 Comment :, , more...

MSSQL Hell

by z3n on Aug.25, 2009, under Coding, lol

One might say that mssql is more powerfull and versatile than the other free choices around, this person should be slapped in the face repeated times.

MS SQL is the most awful and horrible SQL server ever.

Moving data to a server to another turns into a hell specially when you use the official microsoft tools to do that. Somehow, microsoft managed to put their legacy bugs on this product as well. The default `copy database` tool from SQL Management Studio 2008 comes factory broken. You can’t use it due some unknown mistake. The more i searched about the `Object reference not set to an instance of an object` issue the more crap i found about it. This is also a C# error message, making it harder to find on google, although many people discussed about this specific sql issue, nobody apparently found an fix it.

There’s some patches at microsoft site, but none of them worked.

So, I was tired of SQL Management studio when i found a tool to export/import sql databases, also from microsoft. Despite the timeouts, it worked right…. until, after 3 hours i found out that it didn’t copied the identity columns, which i specificly checked to copy at the program.

Back at Manager, i happly found that you can’t add identity columns without dropping the table and loosing all the data.

So, none of microsoft tools to manage microsoft sql server were able to do a simple database copy, what could be done with a single command line at mysql turns into a hell spiral because of microsoft great tools.

I was tired of it then i decided to look for a third party tool, and i found out MS SQL Maestro, which surprisingly only had a little bug on connection passwords, with this program i was able to do a script of the database, with the identity columns included, and now, at 4am i’m inserting it back on the new database, just hope i don’t fall into another happy error, since client will want his database working at 8am :)

Just easy as that.

Leave a Comment :, more...

.htaccess 401 note

by z3n on Aug.20, 2009, under Notes

401 redirects must be within the same domain without the full url:

ErrorDocument 401 /error_page.ext <– right
ErrorDocument 401 http://www.example.com/error_page.ext <– wrong, EVEN if your domain is the same that it’s being redirect to.


Leave a Comment :, , , , more...

overflow reloaded

by z3n on Aug.19, 2009, under Notes

I’ve been using those crappy generic themes for a while, so today i decided to do a ripoff on pixeled and do my own theme.

Nothing so much amazing, just black and simple, the way i like to read in the dark.

Leave a Comment more...

jQuery hoverpulse different image ratio fix

by z3n on Aug.18, 2009, under Coding

The jQuery’s extension hoverpulse created allows you to have images that resize themselfs on a mouse hover, very usefull when you need to have larger thumbs without showing the full image like other extensions does.

However hoverpulse has a issue when it comes to resize non square images, it simply stretches them, so I wrote this little custom version of hoverpulse in order to have this gap filled:

Links:

Modified Source

jQuery

HoverPulse Plugin

2 Comments :, , , more...

little jQuery to loop through checkboxes

by z3n on Aug.18, 2009, under Coding

This is a little function to loop throught a specific form or id with checkboxes, it will check if the checkbox is checked and then you can `do something`.

  1. function (what)
  2. {
  3. jQuery.each(jQuery("#"+what+" :checkbox"),function(){    
  4.  if (jQuery(this).is(':checked')) {
  5.                         // do something
  6.  }
  7. });
  8. }
1 Comment :, , , more...

Ultimate PHP Resize Function

by z3n on Aug.15, 2009, under Coding

In the last few days I’ve been developing some new stuff that required my old img_resizer php function to be refurbished, I also found a issue with wBMP not being the same as BMP format.

Apart from that i got some extra file checking and the ability of recognizing the file format independent of the extension (this will only work with exif extension, which when not enabled will fall back to a try and error little loop).

There’s also some new stuff added, when you don’t want to automatically crop an `out of ratio` resized image you can enable the $nocrop option which will resize the image to the right ratio without cropping or stretching it.

So this is the v2.7, not sure if it will be the last one, but so far it’s the ultimate.

// (c) z3n – R1V2.7@090815 – www.overflow.biz – z3n666@gmail.com
  1.  
  2. function _o($x) { echo $x."’n"; }
  3.  
  4. function _ckdir($fn) {
  5.  if (strpos($fn,"/") !== false) {
  6.   $p=substr(substr($fn,0,strrpos($fn,"/")),0,250);
  7.   if (!is_dir($p)) {
  8.    mkdir($p,755,true);
  9.   }
  10.  }
  11. }
  12. function imagecreatefrombmp($p_sFile) { // by alexander@alexauto.nl at http://www.php.net/manual/en/function.imagecreatefromwbmp.php
  13.   // Load the image into a string
  14.   $file = fopen($p_sFile,"rb");
  15.   $read=fread($file,10);
  16.   while(!feof($file)&amp;&amp;($read&lt;&gt;""))
  17.    $read.=fread($file,1024);
  18.   $temp=unpack("H*",$read);
  19.   $hex=$temp[1];
  20.   $header=substr($hex,0,108);
  21.  
  22.   // Process the header
  23.   // Structure: http://www.fastgraph.com/help/bmp_header_format.html
  24.   if (substr($header,0,4) == "424d") {
  25.     // Cut it in parts of 2 bytes
  26.     $header_parts=str_split($header,2);
  27.  
  28.     // Get the width4 bytes
  29.     $width=hexdec($header_parts[19].$header_parts[18]);
  30.  
  31.     // Get the height4 bytes
  32.     $height=hexdec($header_parts[23].$header_parts[22]);
  33.  
  34.     // Unset the header params
  35.     unset($header_parts);
  36.   }
  37.  
  38.   // Define starting X and Y
  39.   $x=0;
  40.   $y=1;
  41.  
  42.   // Create newimage
  43.   $image=imagecreatetruecolor($width,$height);
  44.  
  45.   // Grab the body from the image
  46.   $body=substr($hex,108);
  47.  
  48.   // Calculate if padding at the end-line is needed
  49.   // Divided by two to keep overview.
  50.   // 1 byte = 2 HEX-chars
  51.   $body_size=(strlen($body)/2);
  52.   $header_size=($width*$height);
  53.  
  54.   // Use end-line padding? Only when needed
  55.   $usePadding=($body_size&gt;($header_size*3)+4);
  56.  
  57.   // Using a for-loop with index-calculation instaid of str_split to avoid large memory consumption
  58.   // Calculate the next DWORD-position in the body
  59.   for ($i=0;$i&lt;$body_size;$i+=3) {
  60.     // Calculate line-ending and padding
  61.     if ($x&gt;=$width) {
  62.       // If padding needed, ignore image-padding
  63.       // Shift i to the ending of the current 32-bit-block
  64.       if ($usePadding)
  65.        $i+=$width%4;
  66.  
  67.       // Reset horizontal position
  68.       $x=0;
  69.  
  70.       // Raise the height-position (bottom-up)
  71.       $y++;
  72.  
  73.       // Reached the image-height? Break the for-loop
  74.       if ($y &gt; $height)
  75.        break;
  76.     }
  77.  
  78.     // Calculation of the RGB-pixel (defined as BGR in image-data)
  79.     // Define $i_pos as absolute position in the body
  80.     $i_pos=$i*2;
  81.     $r=hexdec($body[$i_pos+4].$body[$i_pos+5]);
  82.     $g=hexdec($body[$i_pos+2].$body[$i_pos+3]);
  83.     $b=hexdec($body[$i_pos].$body[$i_pos+1]);
  84.  
  85.     // Calculate and draw the pixel
  86.     $color=imagecolorallocate($image,$r,$g,$b);
  87.     imagesetpixel($image,$x,$height-$y,$color);
  88.  
  89.     // Raise the horizontal position
  90.     $x++;
  91.   }
  92.  
  93.   // Unset the body / free the memory
  94.   unset($body);
  95.  
  96.   // Return image-object
  97.   return $image;
  98. }
  99. function img_force($src,$quality,$w,$h,$saveas,$nocrop,$force) {
  100.  foreach (array("jpg","gif","png") as $x) { // will skip bmp formats
  101.   if ($x != $force) {
  102.    if (img_resizer($src,$quality,$w,$h,$saveas,$nocrop,$x)) {
  103.     return 1;
  104.     break;
  105.    }
  106.   }
  107.  }
  108.  return 0;
  109. }
  110. function img_resizer($src,$quality,$w,$h,$saveas,$nocrop=0,$force=0) { /* v2.71 with auto crop, no crop, automatic file type detection when avalible (requires exif library) */
  111.  
  112.  if (!is_file($src)) { _o("Source is not a file.");return 0; }
  113.  if (!is_readable($src)) { _o("Can't read: ".$src);return 0; }
  114.  if ((file_exists($saveas)) && (!is_writeable($saveas))) { _o("Can't write to: ".$saveas);return 0; }
  115.  
  116.  $r=1;
  117.  
  118.  if (function_exists('exif_imagetype')) { // automatic filetype detection
  119.    $e=exif_imagetype($src);
  120.    if ($e == IMAGETYPE_JPEG) {
  121.     if (!$OldImage=@ImageCreateFromJpeg($src)) { $r=0; }
  122.    } elseif ($e == IMAGETYPE_GIF) {
  123.     if (!$OldImage=@ImageCreateFromGif($src)) { $r=0; }
  124.    } elseif ($e == IMAGETYPE_BMP) { // custom
  125.     if (!$OldImage=@ImageCreateFrombmp($src)) { $r=0; }
  126.    } elseif ($e == IMAGETYPE_WBMP) {
  127.     if (!$OldImage=@ImageCreateFromwbmp($src)) { $r=0; }
  128.    } elseif ($e == IMAGETYPE_PNG) {
  129.     if (!$OldImage=@ImageCreateFromPng($src)) { $r=0; }
  130.    } else {
  131.     _o("Not a Valid Image! (".$e.") — ".$src);$r=0;
  132.    }
  133.  } else { // filename based filetype detection, might be subject to incorrect file extensions, resulting on a error, which when enabled will fall into a try and error `force` mode
  134.    $e=($force == "0") ? strtolower(substr($src,strrpos($src,".")+1)) : $force;
  135.    if (($e == "jpg") || ($e == "jpeg")) {
  136.     if (!$OldImage=@ImageCreateFromJpeg($src)) { $r=0; }
  137.    } elseif ($e == "gif") {
  138.     if (!$OldImage=@ImageCreateFromGif($src)) { $r=0; }
  139.    } elseif ($e == "bmp") { // this is NOT wbmp
  140.     if (!$OldImage=@ImageCreateFrombmp($src)) { $r=0; }
  141.    } elseif ($e == "png") {
  142.     if (!$OldImage=@ImageCreateFromPng($src)) { $r=0; }
  143.    } else {
  144.     _o("Not a Valid Image! (".$e.") — ".$src);$r=0;
  145.    }
  146.  }
  147.  
  148.  if ($r) {
  149.   list($width,$height)=getimagesize($src);
  150.   // check if ratios match
  151.   $_ratio=array($width/$height,$w/$h);
  152.   if ($_ratio[0] != $_ratio[1]) { // ratio don't match
  153.    if ($nocrop) { // since we can't crop we will need to do image on a different height/width
  154.       $hx = (100 / ($width / $w)) * .01;
  155.       $hx = @round ($height * $hx);
  156.  
  157.       $wx = (100 / ($height / $h)) * .01;
  158.       $wx = @round ($width * $wx);
  159.  
  160.       if ($hx &lt; $h) {
  161.        $h = (100 / ($width / $w)) * .01;
  162.        $h = @round ($height * $h);
  163.       } else {
  164.        $w = (100 / ($height / $h)) * .01;
  165.        $w = @round ($width * $w);
  166.       }
  167.    } else { // crop image
  168.      // find the right scale to use
  169.      $_scale=min((float)($width/$w),(float)($height/$h));
  170.  
  171.      // coords to crop
  172.      $cropX=(float)($width-($_scale*$w));
  173.      $cropY=(float)($height-($_scale*$h));
  174.  
  175.      // cropped image size
  176.      $cropW=(float)($width-$cropX);
  177.      $cropH=(float)($height-$cropY);
  178.  
  179.      $crop=ImageCreateTrueColor($cropW,$cropH);
  180.      ImageCopy($crop,$OldImage,0,0,(int)($cropX/2),(int)($cropY/2),$cropW,$cropH); // crop the middle part of the image to fit the thumbnail's proportions
  181.    }
  182.   }
  183.  
  184.   // do the thumbnail
  185.   $NewThumb=ImageCreateTrueColor($w,$h);
  186.   if (isset($crop)) { // been cropped
  187.    ImageCopyResampled($NewThumb,$crop,0,0,0,0,$w,$h,$cropW,$cropH);
  188.    ImageDestroy($crop);
  189.   } else { // ratio match, regular resize
  190.    ImageCopyResampled($NewThumb,$OldImage,0,0,0,0,$w,$h,$width,$height);
  191.   }
  192.   _ckdir($saveas);
  193.   ImageJpeg($NewThumb,$saveas,$quality);
  194.   ImageDestroy($NewThumb);
  195.   ImageDestroy($OldImage);
  196.  } elseif (($force == "0") &amp;&amp; (!function_exists('exif_imagetype'))) {
  197.   $r=img_force($src,$quality,$w,$h,$saveas,$nocrop,$e);
  198.  }
  199.  return $r;
  200. }
Leave a Comment :, , , , , more...

Keep it simple, stupid jQuery experience

by z3n on Aug.14, 2009, under Coding, Notes

As much as I like jQuery I must admit that it’s far away from simplifying things. Although it might be a great idea using it on 100% jQuery scripts, it’s a real bad idea using it to refurbish an old script.

Today I’ve spent over 2 hours implement jQuery on a old script I have, and I felt into so many issues that it didn’t worth at all.

My script was simple, I had a huge variable list that could be edited by a form, script loops through the variables building a form with input fields for each variable. I will not get into specific details because it’s boring, but I needed to allow the user to add a new variable inside an array, so i thought that jQuery would help a lot since i only would need to dynamic add a new input field as needed then post everything back to script to save the file.

First I spent an hour figuring out that jQuery was ruining the text by converting the whole thing into UTF-8, loosing all the accents, eventually I found out about contentType encoding ajax variable:

contentType:"application/json; charset=utf-8"
which could be changed to the charset i wanted.

It was useless, jQuery still posting into the wrong charset, there’s some other tweks on this, but they are also useless.

I was able to fix the accent issue with this php statement:

mb_convert_encoding(urldecode($variable),”ISO-8859-1″,”auto”);

This is much more obscure though, but I was familiar with it since i coded in japanese charsets which are a pain to convert.

After having this cleared, and searching a lot of useless blogs and postings, turns out that jQuery was using the hard coded form names to post the data, which could be overlapped by an dynamic added field, I did a script to change the name of the hard coded inputs, something like this:

$(“#field_id”).attr(’name’,’new_name’);

Theorically, it worked, but when I did:

$(“#form”).serialize();

jQuery used the dynamic fields with the ordinary hard coded ignoring the attr changes.

Now I had to add a handler to dynamic convert and read all the inputs and do my own serialize in order to TRY to make it work…and that’s because i didn’t tested it on IE yet.

So that’s when I quit using jQuery for this script and do something plain and simple, which took me about 20 minutes and 0 searches.

It looks like that if I had used DOM elements for the whole form, all elements generated by jQuery itself, not hard coded, i would have less trouble with the form, although, the charset issues still.

Super Fun Sources:

Stack overflow posting

Stack overflow posting 2

jQuery Ajax Documentation (completly useless since contentType explanation has 2 lines)

Leave a Comment :, , , , , more...

MySQL procedure related functions

by z3n on Aug.05, 2009, under Notes

Since i keep forgetting this I will post as reminder:

show procedure status;

Lists procedures stored on current database.

show create procedure database.procedure_name;

Shows the source of the stored procedure.

grant execute on procedure database.procedure_name to username;

Grants execute privileges to the specific procedure and user.

Those are somehow obscure functions on mysql documentation, I think that they are still improving the procedures usability.

Leave a Comment :, , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!