Friday, February 8, 2013

jquery color picker

<div id="colorSelector"><div style="background-color: #0000ff"></div></div>

$('#colorSelector').ColorPicker({
 color: '#0000ff',
 onShow: function (colpkr) {
  $(colpkr).fadeIn(500);
  return false;
 },
 onHide: function (colpkr) {
  $(colpkr).fadeOut(500);
  return false;
 },
 onChange: function (hsb, hex, rgb) {
  $('#colorSelector div').css('backgroundColor', '#' + hex);
 }
});
Download zip file from here:
https://docs.google.com/file/d/0B5nZNPW48dpFaGF0OENKakkzX1k/edit?usp=sharing 
https://www.box.com/s/882opl3kwb9m5ne0olhp 
http://www.eyecon.ro/colorpicker/ 
 

php get file list from location ends or start with some string preg_match

<?php 
$fontList = array();

$fontLocation = WWW_ROOT."img/brief/graphic/font_style";

if(file_exists($fontLocation) && is_dir($fontLocation)) {

    $dirs = array_diff( scandir( $fontLocation ), Array( ".", ".." ) );

    foreach($dirs as $fileName) {

        /* ENDS WITH .jpg */

        if(is_file($fontLocation."/".$fileName) && preg_match("/\.jpg$/i", $fileName)) {

            echo "MATCH: ".$fileName."<BR>";

        }

        /* STARTS WITH 'godhuli' */

        if(is_file($fontLocation."/".$fileName) && preg_match("/^godhuli/i", $fileName)) {

            echo "MATCH: ".$fileName."<BR>";

        }

    }

}

$list = array_filter($list, "__private_checkPregReplace54131256");

function __private_checkPregReplace54131256($input) {
    if(preg_match("/\./i", $input)) {
        return true;
    }
    return false;
}
?>

Sunday, February 3, 2013

Find size of file behind download link with jquery before download from server

You could make a HTTP HEAD request, and get a file size approximate by reading the Content-Length HTTP Header.
This kind of request is used to obtain meta-information about the URL implied by the request, without transferring any content of it in the response.
var xhr = $.ajax({
  type: "HEAD",
  url: "http://domain.com/file.ext",
  success: function(msg){
    alert(xhr.getResponseHeader('Content-Length') + ' bytes');
  }
});

Friday, February 1, 2013

Remove horizontal and vertical scrollbar from facebook apps

Set scroll=no and overflow:hidden to your body and use FB.Canvas.setAutoGrow() to remove the scrollbar.
<body scroll="no" style="overflow:hidden">
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function () {
    window.setTimeout(function () {
        FB.Canvas.setAutoGrow()
    }, 250)
};
(function () {
    var e = document.createElement('script');
    e.async = true;
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e)
}());
</script>
 
Follow the link. 
Remove-horizontal-and-vertical-scrollbar-from-facebook-apps 

get file size by jquery before upload

You actually don't have access to filesystem (for example reading and writing local files), however, due to HTML5 File Api specification, there are some file properties that you do have access to, and the file size is one of them.
For the HTML bellow
<input type="file" id="myFile" />
try the following:
//binds to onchange event of your input field
$('#myFile').bind('change', function() {

  //this.files[0].size gets the size of your file.
  alert(this.files[0].size);

});
As it is a part of the HTML5 specification, it will only work for modern browsers (and IE is not one of them).

php array delete by value (not key)

Using array_seach(), try the following:
if(($key = array_search($del_val, $messages)) !== false) {
    unset($messages[$key]);
}

array_search() returns the key of the element it finds, which can be used to remove that element from the original array using unset(). It will return FALSE on failure, however it can return a "falsey" value on success (your key may be 0 for example), which is why the strict comparison !== operator is used.
The if() statement will check whether array_search() returned a value, and will only perform an action if it did.

View print cakephp generated mysql query

$log = $this->controller->UserRequestFeed->getDataSource()->getLog(false, false);
debug($log);