Monday, February 11, 2019

How to round float numbers in javascript?

Float value rounded number

javascript "toFixed()" predefined function  using

(6.688689).toFixed(); // equal to 7
(6.688689).toFixed(1); // equal to 6.7
(6.688689).toFixed(2); // equal to 6.69
MDN using rounded value

Math.round10(5.25, 0);  // 5
Math.round10(5.25, -1); // 5.3
Math.round10(5.25, -2); // 5.25
Math.round10(5, 0);     // 5
Math.round10(5, -1);    // 5
Math.round10(5, -2);    // 5

Thursday, January 31, 2019

How can I send a Firebase Cloud Messaging notification without use the Firebase Console?

FCM cloud message notification send mobile device on simple method try this code

$ch = curl_init();
$registration_ids="YOUR DEVICE ID";
ignore_user_abort();
ob_start();
$url = 'https://fcm.googleapis.com/fcm/send';
$message = 'Name:"Vengadeshwaran" Contact number:"888XXXX-XXX"';
$fields = array(
'registration_ids' => array($registration_ids),
'priority' => 10,
'notification' => array('title' => 'Birthday', 'body' => $message ,'sound'=>'Default'),
);
$google_api_key = 'WEB API KEY';
$headers = array(
'Authorization:key='.$google_api_key,
'Content-Type: application/json'
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$status = curl_exec($ch);
curl_close($ch);
echo $status;

Wednesday, August 29, 2018

Laravel Mail send multiple email and cc

        $data=['email'=>$email,'subject'=>'ISS WORLD Account Details','bodymessage'=>$msg,'admin'=>$adminId];
     $result= Mail::send(array(), $data,function($message) use ($data){
                $message->from('vengadeschinz@gmail.com','ISS-WORLD');
               $message->to($data['email']);
             
                $message->cc($data['admin']);
                $message->subject($data['subject']);
);
      

Thursday, August 23, 2018

HTML to XLS export

 $("#export_xls").click(function(e){
    // alert('asdfasd');
    // $("#reports").table2excel({
    //   // exclude CSS class
    //   exclude: ".noExl",
    //   name: "Worksheet Name",
    //   filename: "SomeFile" //do not include extension
    // });
   // alert('hello');
    //getting values of current time for generating the file name
    var tab_text = '<html xmlns:x="urn:schemas-microsoft-com:office:excel">';
  tab_text = tab_text + '<head><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>';
  tab_text = tab_text + '<x:Name>Test Sheet</x:Name>';
  tab_text = tab_text + '<x:WorksheetOptions><x:Panes></x:Panes></x:WorksheetOptions></x:ExcelWorksheet>';
  tab_text = tab_text + '</x:ExcelWorksheets></x:ExcelWorkbook></xml></head><body>';
  tab_text = tab_text + "<table border='1px'>";
  var exportTable = $('#reports').clone();
  exportTable.find('input').each(function (index, elem) { $(elem).remove(); });
  tab_text = tab_text + exportTable.html();
  tab_text = tab_text + '</table></body></html>';
  var fileName = 'yearplanner_' + parseInt(Math.random() * 10000000000) + '.xls';

  //Save the file
  var blob = new Blob([tab_text], { type: "application/vnd.ms-excel;charset=utf-8" })
  window.saveAs(blob, fileName);
  /////////////////////////////
   
  });

Saturday, June 2, 2018

Wednesday, May 9, 2018

XML to string in php

Input:

<list version="1.0">

<meta>

<type>resource-list</type>
</meta>

<resources start="0" count="188">

<resource classname="Quote">

<field name="name">USD/KRW</field>

<field name="price">1080.800049</field>

<field name="symbol">KRW=X</field>

<field name="ts">1525856454</field>

<field name="type">currency</field>

<field name="utctime">2018-05-09T09:00:54+0000</field>

<field name="volume">0</field>
</resource>
</resources>
</list>


Code:

<?php
$request_url = "https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote";

//Setup cURL Request
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $request_url);
curl_setopt($curl, CURLOPT_TIMEOUT, 130);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($curl);
curl_close($curl);
$xml = simplexml_load_string(trim($response), "SimpleXMLElement", LIBXML_NOCDATA );
$data = json_decode( json_encode( $xml ), true );
$values = array();

foreach ($xml->resources->resource->field as $text) {
$values[] = $text->__toString();
}
foreach ($xml->resources->resource as $element) {
foreach($element as $key => $val) {
echo "value:".$val."<br>";
}
}

?>

Output:


value:USD/KRW
value:1080.800049
value:KRW=X
value:1525859664
value:currency
value:2018-05-09T09:54:24+0000
value:0