~ overflow ~

Archive for February, 2010

Gracefully overriding fixed width/height divs

by z3n on Feb.25, 2010, under Coding, Tips & Hints

Problem:

It’s like a industry standard now having everthing tableless, although i still thinking that EVERYTHING is too much, this been like the motto of many programmers around. But let’s skip the blablaing about this and go straight to the point:

You have 2 fixed width div/li `rows` on a site, they are nested and inside the content, due the complex nature of the layout, there’s some other complications. All of sudden the client decides that he wants to ruin your layout adding a long, waaaaaaaaay long, horizontal listing, which not also overlapps the width of your left column but mostly like will make user’s screen to horizontally scroll.

Solution:

As much i like to discuss with client, it’s useless and i will be just wasting my time. This is also a tricky thing to fix since the column sizes are fixed, i would need to make the whole content column bigger, ruining the rest of the top elements. Let’s take a look on the example:

<div style=”width:600px”>

content div header code here

<div style=”width:2000px”>

way long client designed div to ruin layouts

</div>

</div>

(styles are just to simplifly)

so the solution (1) would be something like this:

<div style=”width:600px”>

content div header code here

<div style=”width:2000px;position:absolute;“>

way long client designed div to ruin layouts

</div>

<img src=”blank_image.gif” width=1 height=same height as the long width div>

</div>

solution (2), if your abomination div is also height dynamic:

<div style=”width:600px” id=”container”>

content div header code here

<div style=”width:2000px;position:absolute;id=”abomination”>

way long client designed div to ruin layouts

</div>

</div>

<script type=”text/javascript”>

// after loading all the content of the abomination div, also assuming that you’re using jquery

$(“#container”).height(parseFloat($(“#abomination”).height()+50)+”px”);

</script>

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

MySQL mass union query issue

by z3n on Feb.17, 2010, under Tips & Hints

Problem:

MySQLd 5.0.18 (and some others) will bug on queries with more than 128 joins.

The error issued has nothing todo with the limit, and there’s no var to raising this limit, this is a mysql bug for this specific version.

Solution:

Upgrade.

Sources:

bugs.mysql

Leave a Comment :, , , more...

Fatal error: Cannot use object of type stdClass as array (php json_decode)

by z3n on Feb.17, 2010, under Coding, Notes, Tips & Hints

Problem:

$var=json_decode($_POST['something']);

echo $var['value'];

returns error: Fatal error: Cannot use object of type stdClass as array

Solution:

echo $var->value;

2 Comments :, , , , more...

Flash policy-file-request

by z3n on Feb.09, 2010, under Coding, Tips & Hints

Problem:

So you developed an socket flash application using the newest Action Script 3.0, all good on tests and debug

Now when you put on production server, you see a request “<policy-file-request/>“  on the begginig of the connection, WTF is that man?!

Solution:

Let’s ignore all the documents and detailed sample-less (aka useless) explanations.

This is a new security feature introducted on flash 9+, you maybe aware of the crossdomain.xml file that should be present on your’s domain root folder, however this don’t work for socks server, only for other type of projects (streaming players for example).

First let’s see what we can’t see, <policy-file-request/> is not only <policy-file-request/>, there’s a null character after it, so if you are doing a $input == “<policy-file-request/>” you will go wrong, a null character is a chr(0) (zero), something like $input == “<policy-file-request/>”.chr(0) or substr($input,0,22) == “<policy-file-request/>” should solve this problem (in php of course) .

Sooo, for this first request (<policy-file-request/>) you should return this:

<?xml version=”1.0″?>
<!DOCTYPE cross-domain-policy SYSTEM “/xml/dtds/cross-domain-policy.dtd”>
<cross-domain-policy>
<site-control permitted-cross-domain-policies=”master-only”/>
<allow-access-from domain=”your_domain” to-ports=”666” />
</cross-domain-policy>

Where your_domain is your domain, doh, but you can also put * so it will work at any domain, if you have more than one domain using this, it will be usefull.

The other bold, 666, is the port that flash should be expecting data to come from, you can also put * here or a port range, or both, check official docs for more info, there are more options you can put on this xml, depending on your needs it will be usefull.

Note that there’s another trick here, you need to put a null character (chr(0)) in the end of this reply! Also, you don’t need to send any special headers like Content-Type.

If it’s all right, flash will disconnect and reconnect, if something is wrong it will just disconnect, make sure you do a handler on your socket server for this, it might ruin things like it did for me.

Sources:

Posting where i found about the chr(0)

Policy file changes in Flash Player 9 and Flash Player 10 (full article)

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

PHP Strong Encode

by z3n on Feb.01, 2010, under Coding

Problem:

I needed a strong reversible encode algorithm to send user and retrieve back somewhere.

Solution:

I wrote 2 little functions to do that, you can change the key to a unique value that way having your encoding unique. This isen’t 100% safe, but very hard to crack assuming you use the same 256-bit cipher i’m using on this example. Also this function is safe to pass by http gets and posts.

Note that you will need php’s mcrypt support to have this running, depending on your distro you might not have the cipher i used on this example, refeer to php’s documentation to be sure.

  1.  
  2. define('c_key',md5("your key string, can be random or anything you like")); // ecryption key
  3. define('c_alg',MCRYPT_RIJNDAEL_256); // ecryption cipher
  4. define('c_mod',MCRYPT_MODE_ECB); // ecryption mode
  5. define('c_rnd',MCRYPT_RAND); // ecryption random type, MCRYPT_DEV_* are only supported on linux
  6.  
  7. function _enc3($value,$key=c_key) { // v1.01
  8.  if (!$value) {
  9.   return false;
  10.  }
  11.  $iv_size = mcrypt_get_iv_size(c_alg, c_mod);
  12.  $iv = mcrypt_create_iv($iv_size, c_rnd);
  13.  return rawurlencode(trim(base64_encode(mcrypt_encrypt(c_alg, $key, $value, c_mod, $iv))));
  14. }
  15. function _dec3($value,$key=c_key) { // v1.01
  16.  if (!$value) {
  17.   return false;
  18.  }
  19.  $iv_size = mcrypt_get_iv_size(c_alg, c_mod);
  20.  $iv = mcrypt_create_iv($iv_size, c_rnd);
  21.  return trim(mcrypt_decrypt(c_alg, $key, urldecode(base64_decode($value)), c_mod, $iv));
  22. }
  23.  
  24. // usage example
  25.  
  26. $string="and you just visited a stupid blog so what";
  27.  
  28. echo "Encoded:"._enc3($string)."<BR>Decoded:"._dec3(_enc3($string));
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!