Thursday, February 9, 2017

Ionic 2 error : build dev failed: Cannot read property 'indexOf' of undefined


I got error suddenly when running ionic 2 app

build dev failed: Cannot read property 'indexOf' of undefined 

Fix for the issue

Update the app-script to latest -> npm install @ionic/app-scripts@latest --save-dev
Change tsconfig.js -> compilerOptions insert "sourceMap": true, and remove lib option


Credits : https://github.com/driftyco/ionic-app-scripts/issues/597

Monday, November 21, 2016

Create different size thumbnails, while uploading the image


Recently I came across  a problem where I had to upload different size of thumbnails to amazon s3, after going through several  stackoverflow answers created small function which exactly addressed my requirement.

 private function createThumbs( $file, $w, $h){
    try{      
        list($width, $height) = getimagesize($file);
        $r = $width / $height;      
             
          if ($w/$h > $r) {
             $newwidth = $h*$r;              
             $newheight = $h;          
          } else {            
             $newheight = $w/$r;              
             $newwidth = $w;        
          }      
               
          $src = imagecreatefromjpeg($file);      
          $dst = imagecreatetruecolor($newwidth, $newheight);      
          imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth,
               $newheight, $width, $height);
         // Begin capturing the byte stream    
         ob_start();      
         // generate the byte stream      
         imagejpeg($dst, null, 100);      
         // and finally retrieve the byte stream      
         $rawImageBytes = ob_get_clean();      
         imagedestroy($dst);
        return $rawImageBytes;
     } catch (\Exception $e){      
     throw new \Exception($e->getMessage());  
  }
 }


get the image data

 // 600px 600px image
$image_600_data = $this->createThumbs($_FILES["fileToUpload"]["tmp_name"], 600, 600);
// 300px 300 px image
$image_300_data = $this->createThumbs($_FILES["fileToUpload"]["tmp_name"], 300, 300);
// 100px 100px image
$image_100_data = $this->createThumbs($_FILES["fileToUpload"]["tmp_name"], 100, 100);

this will display the 100/300/600 images separately. just to make sure ;)

echo "<img src="data:image/jpeg;base64,&quot; . base64_encode( $image_100_path ) . " />";
echo "<img src="data:image/jpeg;base64,&quot; . base64_encode( $image_300_path ) . " />";
echo "<img src="data:image/jpeg;base64,&quot; . base64_encode( $image_600_path ) . " />";

Sunday, April 22, 2012

Get value by tag name from the XML result using PHP


        /**
* A simple process to retrive XML data
*/
function get_value_by_tag_Name( $str, $s_tag, $e_tag)
{
$s = strpos( $str,$s_tag) + strlen( $s_tag);
$e = strlen( $str);
$str= substr($str, $s, $e);
$e = strpos( $str,$e_tag);
$str= substr($str,0, $e);
$str= substr($str,0, $e);
return  $str;
}




Credits
http://reazulk.wordpress.com

Friday, April 20, 2012

PHP Encrypt and Decrypt function


/*you can chage the key as your wish*/
$key = "+OmENio4F8/8895tSQXaS13hire3FjXAQ5EfRfgHseI=";

function encrypt( $string )
{
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
}

function decrypt( $encrypt_string )
{
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypt_string), MCRYPT_MODE_CBC, md5(md5($key))));
}

$srt ='malinda';
$en = encrypt( $srt );
$de = decrypt( $en );

echo "String - " . $srt.'<br/>';

echo "Encrypt String - " . $en.'<br/>';

echo "Decrypt String - " . $de.'<br/>';


Credits -  http://ideone.com/yQIAX

Monday, October 31, 2011

How to compare the two dates in PHP

function compare_date ($date_one,$date_two){


//your input should be dd/mm/yy
$arr_date_one= explode ("/", $date_one);
$arr_date_two= explode ("/", $date_two);
//remove the '/'


$days_one = $arr_date_one[0];
$months_one = $arr_date_one[1];
$year_one = $arr_date_one[2];

$days_two = $arr_date_two[0];
$months_two = $arr_date_two[1];
$year_two = $arr_date_two[2];

$date_one_jul = gregoriantojd($days_one , $months_one , $year_one );
$date_two_jul = gregoriantojd($days_two , $months_two , $year_two );

return $date_one_jul - $date_two_jul ;
}




//out put will be  +/- value depend on your parameters

Saturday, July 30, 2011

How to get news feed using facebook API

$app_id = 'APP_ID';
    $app_secret = "APP_SECRET";
    $my_url = "http://YOURDOMAIN/";
  
    $code = $_REQUEST["code"];

    if(empty($code)) {
        $dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
            . $app_id . "&redirect_uri=" . urlencode($my_url)."&scope=email,read_stream,publish_stream";

        echo("<script> top.location.href='" . $dialog_url . "'</script>");
    }

    $token_url = "https://graph.facebook.com/oauth/access_token?client_id="
        . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret="
        . $app_secret . "&code=" . $code;

    $access_token = file_get_contents($token_url);
    $graph_url = "https://graph.facebook.com/me?" . $access_token;
    $user = json_decode(file_get_contents($graph_url));
  
  
   //print the current user details
    print_r($user);
   
 
    $query = "https://api.facebook.com/method/fql.query?query=";
    $query .= urlencode("SELECT post_id, actor_id, target_id, message FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed') AND is_hidden = 0");

    //$query .= "&access_token=".$access_token."&format=json";
    $out = file_get_contents($query);
    $response = json_decode($out);
    
    //print the current users news feeed
    print_r($response);