Search This Blog

Friday, 23 February 2018

fix bootstrap errors with angular 4

Uninstall bootstrap@4.0.0-beta.3:
npm uninstall bootstrap --save
Then installed bootstrap@4.0.0-beta.2:
npm install bootstrap@4.0.0-beta.2 --save

OR 

upgrade angular cli from 1.6.3 to 1.7.0-rc.0. but this has some problems with fonts

but issues coming up with both, click events aren't working for hamburger in mobile view.

so, i finally felt better to go with ng-bootstrap or the mdbootstrap (material design). material isn't yet in a production mode. 

here are the steps to install ng-bootstrap.

  1.  npm install --save @ng-bootstrap/ng-bootstrap
  2. add the following to algular-cli.json - styles:[], so it would be styles:["../node_modules/bootstrap/dist/css/bootstrap.min.css", "styles.css"]
  3. start using the angular bootstrap components looking at: https://ng-bootstrap.github.io/#/getting-started 


Saturday, 28 October 2017

switch between DEV, QA and PROD easily in angular 4/ionic 3

While building any apps its important for a developer to switch between the environments.
below is a simple way i felt for switching environment in angular 2/4 or ionic 2/3.

its easy with a provider and associative arrays. below is an example:

create a provider called environments and use the below:

_envs = {
dev:{
baseURL:"https://somedev.exaple.net/api/mobile",
    config:{
    serviceRefName:"/demo1",
    serviceRefname2:"/demo2",
    serviceRefname3:"/demo3",
    //...
    //...
    }
}
    qa:{
    baseURL:"https://someqa.exaple.net/api/mobile",
    config:{
    serviceRefName:"/demo1",
    serviceRefname2:"/demo2",
    serviceRefname3:"/demo3",
    //...
    //...
    }
    },
    prod:{
    baseURL:"https://someprod.exaple.net/api/mobile",
    config:{
    serviceRefName:"/demo1",
    serviceRefname2:"/demo2",
    serviceRefname3:"/demo3",
    //...
    //...
    }
    }
 };

 _env={};
 _selectedEnv = "qa";

 //add this line in constructor
 this._env = this._envs[this._selectedEnv];

 //add this method to the environment provider
 getURL(configUrl){
    console.log("configUrl Sec : "+configUrl);
    //console.log("this._env="+JSON.stringify(this._env));
    console.log("URL="+this._env["baseURL"]+this._env["config"][configUrl]);
    return this._env["baseURL"]+this._env["config"][configUrl];
  }

In components, where you want to call a service,

  • add environment provider dependency
  • use this:  this.environment.getURL("YourSericeName")
for ex: this.environment.getURL("serviceRefname3")

whenever you need to change, simple change the _selectEnv in you Environment provider.
 For ex:
 _selectedEnv = "prod";

It will take the service names from prod obj of _env. this way with a very simple step, you can switch environment in angular.

Note: It has nothing much specific to angular. this logic can be used in any programming language with respective object constructs.

Monday, 9 October 2017

MODS 17


OCT 5
  • A11Y - for accessibility not disability 
    • tota11y.com,  a11y.org, koa11y.tool
  • Scott Davis company - Thirsty Head
  • Future is all micro services, currently its all monolithic
  • Kubernetes - IBM's ., container orchestration
  • Swift for web
    • REPL
    • Chris Latner is a genius
    • Protocol oriented
    • LLVM?
    • CodableProtocol - Swift 4 JSON type
    • TaskStorage - delete, save etc 4 props
  • Kitura
    • Open API 2.0 Spec - swagger
  • React Native
    • DogFooding
    • Hot Reloading
    • Configuring instant updates?
    • Expo - Dev tool
      • expo kit for managing custom needs
      • CRNA
    • Testing:
      • Jest - Snapshot Testing
      • Enzyme
    • StoryBook
      • Interactive Dev & Testing
      • Loki - Visual Regression Testing
      • Monkey Runner tests
    • Build & Deploy:
      • fastlane
  • Tools:
    • Lottie - Animations
    • Crashlytics, Sentry
    • Expo Snack
    • Detox - replacement for appium/selenium
    • appitools - Visual automated testing
    • Open STF - for certain devices testing
    • Electrode native - convert to react
  • Building for Next Billion  Users:
    • about PWA's
    • Performance in google chrome set to slow 3G 
    • In slow 3g expected performance:
      • First meaningful paint - 1.6s
      • Time to interactive - 2.5s
      • Page Ready - 3.6s
  • React with GraphQL & Apollo:
    • Redux - State Management
    • Graph QL is server side, which decouples Server endpoints and client
    • GraphQL
      • Only one end point will be there 
      • Client has to query details it needs and GraphQL will call corresponding service/db and executes a query and returns queried data.
      • Its kind of agreement between client and server so, client need not bother about service side changes. it will always return the details queried by the client and in the same format as the query.
      • Query - Read, Mutation - Write, Subscription - Push
      • cycle: Query -> Resolvers (Functions to calculate how to fetch data) -> Connectors
    • Apollo:
      • Client side for GraphQL mostly. it replaces the need for Relay.
OCT 6
  • Data - J.Paul Getty's quote
  • Deep leaning:
    • Yousha Bengio book on deep learning
    • Super long sequence pattern recognition
    • Alpha GO -by google
    • Over fitting in Neural networks
  • BFF (Backend for frontend) with swift:
    • Micro services
    • Be part of swift evolution - Chris Latner
    • Swift on linux works on Ubuntu 14.0 onwards, linux one server platform and android platform as well
    • Foundation & Dispatch are in progress for apple & Linux platforms
    • Web service frame works based on swift are  - Kitura, Perfect, Vapour
    • Swift is best for web interms of performace and storage when compared with Node, Java
  • Citizen Data Scientist:
    • epilipsy?
    • Lyfas
    • ibm.biz/heartmotion - ibm's project
    • PCA - principle component analysis
    • Data science experience in Bluemix
  • Deep Learning by (methods)
    • blundering - experimentation
    • transfer learning - japan cucumber example
    • Simulation
  • Swift Stack developer is a upcoming profile
  • Robust introduction AI:
    • Recurrent neural networks
    • Tensor layer
  • Appless environment:
    • Conversational UI
      • Intents
      • Entity
      • Action
    • Cloud functions (Google) & Lamda (AWS)
    • Siri - apple, Google Assistant - Google, Amazon - Alexa
    • console.actions.google.com - for cloud functions
    • Amazon echo, echo dot,
    • Earcon instead of icon
    • Siri kit by apple for ConvoUI
    • Chat bubbles - Response
    • Mood Analysis - Urgency etc
    • Seamless UI - b/w devices etc
  • RxJS: @ladyleet
    • IxJS - Matt Podwyski is working on
    • Sync .of, .from  -synchronus functions in Rx
    • .share?
    • SpeechRecognition - mozilla/api/web_search_api
    • .switchmap?
    • .merge?
  • Native Script:
    • from teleric like react
    • snippets plugin for easy coding of native script in atom




















Sunday, 26 February 2017

Ionic 2 - Hello World!!

After installing Ionic 2, let start coding with it. Ionic 2 project creation is not much different form ionic 1. it uses the same CLI. so, lets issue the command to create the project

ionic start ItsMyCodeShare --v2
so, this creates a blank ionic 2 project. to see it, run the same serve command after going to the project folder:
ionic serve

this will open your project normally with this URL: http://localhost:8100/ with 3 tabs.

let us understand how ionic 2 project structure and how is it rendering your page on to the WebView.
after creating the blank project your folder structure will look like this:

config.xml, src, www are important for development. forget the rest for now.
config.xml contains all the spec, preferences, plugins for each platform.
src contains the source code that we are going to develop.
www contains the transpiled code. 

src contains below folders based on what all will be used:
app
pages
providers
components
pipes

initially it contains only pages folder as the other were not yet created.
app: is the key folder where the app will be initialised. it contains
app.components.ts - this is the file where app starts (after index.html upto my understanding)
app.html - contains the root nav i.e. a placeholder for all navigation of the app
app.module.ts - all the app components, pages, providers to be declared soon after generating them.
app.scss - contains the style for app.html
main.ts 

app.html has <ion-nav [root]="rootPage"></ion-nav>. this ion-nav is the holder for all of the app. the root is loaded when a component is assigned to variable rootPage

if you observe the app.components.ts, the rootPage will be assigned with the component TabsPage.
When the rootPage was assigned, it looks for TabsPage, it is imported in the .ts file at the top.

import { TabsPage } from '../pages/tabs/tabs';

it was being imported from ../pages/tabs/tabs means, from pages->tabs folder it looks for tabs.ts file.
@Component is decorator which contains meta info like it view, providers etc.,
templateUrl tell what to load for tabsPage. so, tabs.html is loaded.

let us observe, tabs.html:
<ion-tabs>
  <ion-tab [root]="tab1Root" tabTitle="Home" tabIcon="home"></ion-tab>
  <ion-tab [root]="tab2Root" tabTitle="About" tabIcon="information-circle"></ion-tab>
  <ion-tab [root]="tab3Root" tabTitle="Contact" tabIcon="contacts"></ion-tab>
</ion-tabs>

ion-tabs is the directive which is the holder for tabs. it contains 3 ion-tabs which holds respective pages. [root] sets the root page for each of the tab.

so now 3 more pages will be loaded based on their paths mentioned in .ts files.

so i guess you got the crux of it. after app initialization, all the things works based on the .ts typescript files and respective html will be loaded from the templateUrl and styles are taken from respective .scss files.

that's it. to understand flow, i would suggest to keep console.log(); and serve.

Ionic 2 - Installation & installation issues

With ionic 2, the top level stack stays as like ionic 1 (internally lots of changes were) i.e. Cordova for communication with hardware, Angular 2 for javascript events and ionic 2 styles/classes for CSS.

so, installing ionic 2 also like ionic 1. Install nodejs & Install corodva, ionic.

  1. Download latest node.js from https://nodejs.org/en/
  2. run the command:  sudo npm install -g ionic cordova
thats it. you are done with the installation. 

sometimes, users who have ionic 1 are getting problems like, if you create a project it will get created some where else etc. for such, completely remove ionic and re-install.

follow the steps below (in mac):
  1. kill running nodejs via terminal: killall -9 node
  2. completely remove below folders
    1.  /usr/local/lib/node_modules
    2. /usr/local/include/node and /node_modules

thats it, run above install command to re-install ionic 2.

Tuesday, 29 March 2016

CDVPlugin not found/Mach -o error while archiving or exporting ipa of ionic/cordova apps

When you have a plugin written in swift in your ionic/cordova app, it builds but when archive or export it returns CDVPlugin not found error. Follow the steps below to resolve the issue.
Note: Run all ionic commands build, add etc using sudo only.
Ex: sudo ionic build ios
As we are moving code from windows to mac, permissions are arising.
Steps:
  1. In terminal change give permissions
$ Sudo chown –R:staff <your folder path>
$  sudo chown –R 777 *
  1. Now go to Target-> build settings
    1. Look for RunPaths and add below if it’s not there:
$(inherited)@executable_path/Frameworks
@executable_path/Frameworks

  
    1. Now look for Header Search Paths and add the below:
$(OBJROOT)/UninstalledProducts/$(PLATFORM_NAME)/include

    1. Set Enable Bit code to No

    1. In Deployment section, clear Install Owner and Groups

  1. Now go to Build Phases and
    1. Empty Embedded Frameworks, (if any swift plugins are there)

  1. Go to general and in frameworks add UIKit if not added


Sunday, 20 March 2016

Markers with different colors in ionic using angularJS, Centering the map

for getting maps in maps in ionic project follow steps in this post

now lets see
1. how to center the map to your screen
2. place markers of different colors
3. increase bounds of your map
4. Show window/message on click of marker

1. Centering the map to current location:
$cordovaGeolocation.getCurrentPosition(options).then(function(position){

var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var mapOptions = {
 center: latLng,
 zoom: 15,
 mapTypeId: google.maps.MapTypeId.ROADMAP

};
                $scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
});

here getCurrentPositions return the lattitude (lat) and longitude (lon) of my current place.
i will use it in my map options to center it. highlighted above line will set my current location to center my map.

2&3. Place Markers:
lets say i want to place markers in my below lat, lons

var latlons = [{lat:"12.9450362",lon:"77.6970354",title:"msg1"},{lat:"12.9550364",lon:"77.6890356",title:"msg2"},{lat:"12.9950366",lon:"77.6800358",title:"msg3"}];

create a pin to show the marker:

var RedPinColor = "FE7569";
var RedPinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + RedPinColor,
new google.maps.Size(21, 34),
new google.maps.Point(0,0),
new google.maps.Point(10, 34));

var bounds = new google.maps.LatLngBounds(); //for increase/decrease zoom

for (var i = 0; i < markers.length; i++) {
var data = markers[i];
var myLatlng = new google.maps.LatLng(data.lat, data.long);
var marker = new google.maps.Marker({
position: myLatlng,
map: $scope.map,
title: data.title,
icon:RedPinImage,
shadow:pinShadow
});
bounds.extend(myLatlng);
                              $scope.fitBounds(bounds);
}

i am adding bounds which will help me in increase/decrese zoom of my map according to the markers i am adding.

the pin Image can be changed as you need, below are 2 ex:
var GreenPinColor = "69fe75";//"FE7569";
var YellowPinColor = "FFFF00";
var RedPinColor = "FE7569";
var RedPinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + RedPinColor,
new google.maps.Size(21, 34),
new google.maps.Point(0,0),
new google.maps.Point(10, 34));
var YellowPinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + YellowPinColor,
new google.maps.Size(21, 34),
new google.maps.Point(0,0),
new google.maps.Point(10, 34));
var GreenPinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + GreenPinColor,
new google.maps.Size(21, 34),
new google.maps.Point(0,0),
new google.maps.Point(10, 34));
var pinShadow = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
new google.maps.Size(40, 37),
new google.maps.Point(0, 0),
new google.maps.Point(12, 35));

Display window/message on click of markers:
google maps offers a InfoWindow to display message on click of markers created above.

the below line create a infowindow.
var infoWindow = new google.maps.InfoWindow();

now need to bind to click event of marker. let see how to do it in a loop (as most of us need to do in looping always)
var infoWindow = new google.maps.InfoWindow();
var bounds = new google.maps.LatLngBounds();


for (var i = 0; i < markers.length; i++) {
var data = markers[i];
var myLatlng = new google.maps.LatLng(data.lat, data.long);
var marker = new google.maps.Marker({
position: myLatlng,
map: $scope.map,
title: data.title,
icon:RedPinImage,
shadow:pinShadow
});
bounds.extend(myLatlng);

//Attach click event to the marker.
(function (marker, data) {
var infoWindowContent = "<div style = 'width:200px;min-height:40px'>"+"<p>" + data.DisplayName + "</p>"
+ "<button ng-click="+"\""+"MarkerClick('"+data.SensorName+"')"+"\""+">"+"Schedule Pick"+"</button>"+"</div>";
console.log(infoWindowContent);
var compiled = $compile(infoWindowContent)($scope);
// console.log(compiled["body"]);
google.maps.event.addListener(marker, "click", function (e) {
//Wrap the content inside an HTML DIV in order to set height and width of InfoWindow.
infoWindow.setContent(compiled[0]);
infoWindow.open($scope.map, marker);
});
})(marker, data);
$scope.map.fitBounds(bounds);
}
});

after a marker is created, using a function and creating a content to be displayed on its click: infoWindwContent

as angular restricts direct html binding need to compile it before attaching it to my window using $compile service. sometimes if the html is unsafe you may need to use $sce service to bind unsafe html.

use setContent to set create content info window
open actually assigns the map and marker to which this infowindow to be attached