Wednesday, February 15, 2017

Multiplication of two numbers as array - In Javascript

Javascript Code 

var arry1 = [3,4,6,9,9,9];
var arry2 = [9,8,9,8,5];
$("#arry1").html(arry1.toString());
$("#arry2").html(arry2.toString());
var directResult = arry1.join('') * arry2.join(''); // to compare result 
$("#result").html(directResult);
var calResult = [];
var vadi=0;
for(var i=0;i<arry2.length;i++){
  calResult[i]=[];
  vadi = 0;
  for(var j=arry1.length-1;j>=0;j--){
    var temp= arry1[j]*arry2[i]+vadi;
    if(temp.toString().length > 1){
      vadi = parseInt(temp.toString().substr(0, 1));
      temp = parseInt(temp.toString().substr(1, 1));
    } else{
      vadi = 0;
    }
    calResult[i].unshift(temp);
  }
  for(var k=i+1;k<arry2.length;k++){
      calResult[i].push(0);
  }
  if(vadi!=0){
    calResult[i].unshift(vadi);
    vadi = 0;
  }
  if(calResult[i].length != calResult[0].length){
    var lengthDiff = calResult[0].length-calResult[i].length;
    for(var p=0;p<lengthDiff;p++){
      calResult[i].unshift(vadi);  
    }
  }
}
var finalResult = [];
var finalvadi = 0;
for(var m =calResult[0].length-1;m>=0;m--){
  var tempr = 0;
  for(var n=0; n<calResult.length;n++){
    tempr+=calResult[n][m];
  }
  tempr+=finalvadi;
  finalvadi=0;
  if(tempr.toString().length > 1){
    finalvadi = parseInt(tempr.toString().substr(0, 1));
    tempr = parseInt(tempr.toString().substr(1, 1));
  } else{
    finalvadi = 0;
  }
 finalResult.unshift(tempr);
}
if(finalvadi!=0){
    finalResult.unshift(finalvadi);
}
$("#finalResult").html(finalResult.toString());

HTML Code

 <div id="arry1"></div>
<div id="arry2"></div>
<div>-----------</div>
<div id="result"></div>
<br/><br/>
<div>------------------</div>
<div id="finalResult" style=""></div>


Output: 


3,4,6,9,9,9
9,8,9,8,5
-----------
34347696015


------------------
3,4,3,4,7,6,9,6,0,1,5

Tuesday, September 6, 2016

IONIC - data binding on header title not working

By using the new ion-nav-title directive in Ionic beta 14, the binding seems to work correctly.
Rather than
<ion-view title="{{content.title}}">

Do this
<ion-view> <ion-nav-title>{{content.title}}</ion-nav-title>

Works a treat.

Monday, August 8, 2016

Self Signed SSL Certificates in PhoneGap

Code to allow self signed certs on PhoneGap 

Android:

  • If you are doing development: android:debuggable="true" in the manifest, you should allow the browser to request data from servers with a self-signed or bad SSL cert 
  • If you are releasing an application, you should remove the android:debuggable="true" (Android Market won't let you release with this on anyway) and you will NOT be able to send data to a server with a bad SSL cert 
  • If you don't have this flag set, the default will be what the default is now, which is that you won't be able to send data to servers with a self-signed cert 

iOS: 

Just Add below code at the end of you AppDelegate.m file
@implementation NSURLRequest(DataController)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES; 
}
@end

Thursday, June 9, 2016

Error: Database location or iosDatabaseLocation value is now mandatory in openDatabase call

if you are using Cordova sqlite plugin you may have this issue while open local DB file.

 _sqlLiteDB = $cordovaSQLite.openDB({ name: "testDB.db", iosDatabaseLocation:'default'}); 
// Works on android but not in iOS

                   

Error: Database location or iosDatabaseLocation value is now mandatory in openDatabase call



Use below to open DB:
window.sqlitePlugin.openDatabase({ name: "testDB.db", location: 2, createFromLocation: 1});


Solution:

if(isAndroid){
                    // Works on android but not in iOS
                    _sqlLiteDB = $cordovaSQLite.openDB({ name: "testDB.db", iosDatabaseLocation:'default'}); 
} else{
                    // Works on iOS 
                    _sqlLiteDB = window.sqlitePlugin.openDatabase({ name: "testDB.db", location: 2, createFromLocation: 1}); 
 }



Friday, June 3, 2016

Warning: sqlite3.c Ambiguous expansion of macro - Xcode - iOS

Plugin: cordova-sqlite-storage

Version: 1.4.1

Warning: sqlite3.c Ambiguous expansion of macro - Xcode - iOS

This issue also helps on native app code. 


Issue Solution:

Open Xcode project Build settings


add “-Wno-ambiguous-macro” into  “Other C flags”