AngularJS 2.0 : Environment setup

Here are simple steps you need to follow to get Angular Js 2.0 application up and running on your box.

# Make sure you have latest nodejs download link>   https://nodejs.org/en/

# Using npm install type script from command line>  npm install g typescript

# Download latest angular cli too > npm install g angularcli@latest

You are all set up create your new dream app, Angular CLI tool would create the basic structure required for a new app, since you have environment ready, lets create your dream app and run it on cli server

# Run Below commands, it would create you app.

$ng new my-dream-app

$cd my-dream-app

$ng serve

 

 

You might want to download atom IDE with supporting package from  https://atom.io/

Java Tutorial : Hands on project for library management application

I am coding Library Management Project in Java and teaching it in simple steps.
If you are interested in doing or learning Java with hands on project then check out this play list from my youtube video 🙂

Git Repo :
https://github.com/ProjectsbyPrem/LibraryManagement

Project requirements:
https://docs.google.com/document/d/1ZzAuMQ5jqCwh1qvF5DIvuVP6J1QwUugTuQ1uQjIXRkg/edit
For details visit : http://www.premaseem.com

NodeJs : Convert json to csv using node module

Its very common usecase to convert json docs or Mongo doucments into csv and share with other. I am sharing a simple node module with example to accomplish the same.

Details of package - https://www.npmjs.com/package/json2csv

# To install node module from cmd 
npm install json2csv --save



# create a converter.js javascript file as below with you input json and mapping.

var json2csv = require('json2csv');
var fs = require('fs');
var fields = ['car.make', 'car.model', 'price', 'color'];
var myCars = [

    {
        "car": {
            "make": "Hundai", "model": "sonata"
        },
        "price": 30000,
        "color": "white"
    },
    {
        "car": {
            "make": "Audi", "model": "A3"
        },
        "price": 40000,
        "color": "blue"
    }, {
        "car": {"make": "BMW", "model": "F20"},
        "price": 35000,
        "color": "black"
    }, {
        "car": {"make": "Porsche", "model": "9PA AF1"},
        "price": 60000,
        "color": "green"
    }
];
var csv = json2csv({ data: myCars, fields: fields });

fs.writeFile('file.csv', csv, function(err) {
if (err) throw err;
console.log('file saved');
});


# now run javascript file on node
node converter.js

# This will create a csv file in the current directory called as file.csv open it in excell and you are done.

MongoDB : Java program to do basic crud operation

Sample Java program to connect MongoDb and perform Crud Operations.

Copy paste, run and learn 😉

note :- Please ensure you have installed mongo dependency using jar, github or mvn

 

package com.premaseem.core;

import com.mongodb.*;

import java.util.Date;

/**
 * Java + MongoDB Crud operation example
 *
 */
public class App {
    public static void main(String[] args) {

        try {

            /**** Connect to MongoDB ****/
            // Since 2.10.0, uses MongoClient
            MongoClient mongo = new MongoClient("localhost", 27017);

            // or, to connect to a replica set, with auto-discovery of the primary, supply a seed list of members
//            MongoClient mongoClient = new MongoClient(Arrays.asList(new ServerAddress("localhost", 27017),
//                    new ServerAddress("localhost", 27018),
//                    new ServerAddress("localhost", 27019)));

            /**** Get database ****/
            // if database doesn't exists, MongoDB will create it for you
            DB db = mongo.getDB("testdb");

            /**** Get collection / table from 'testdb' ****/
            // if collection doesn't exists, MongoDB will create it for you
            DBCollection table = db.getCollection("user");

            /**** Insert ****/
            // create a document to store key and value
            BasicDBObject document = new BasicDBObject();
            document.put("name", "premaseem");
            document.put("age", 30);
            document.put("createdDate", new Date());
            table.insert(document);

            /**** Find and display ****/
            BasicDBObject searchQuery = new BasicDBObject();
            searchQuery.put("name", "premaseem");

            DBCursor cursor = table.find(searchQuery);

            while (cursor.hasNext()) {
                System.out.println(cursor.next());
            }

            /**** Update ****/
            // search document where name="premaseem" and update it with new values
            BasicDBObject query = new BasicDBObject();
            query.put("name", "premaseem");

            BasicDBObject newDocument = new BasicDBObject();
            newDocument.put("name", "premaseem-updated");

            BasicDBObject updateObj = new BasicDBObject();
            updateObj.put("$set", newDocument);

            table.update(query, updateObj);

            /**** Find and display ****/
            BasicDBObject searchQuery2
                    = new BasicDBObject().append("name", "premaseem-updated");

            DBCursor cursor2 = table.find(searchQuery2);

            while (cursor2.hasNext()) {
                System.out.println(cursor2.next());
            }

            /**** Done ****/
            System.out.println("Done");

        }  catch (MongoException e) {
            e.printStackTrace();
        }

    }
}

Certificate : Google’s Go Lang programming

Google’s recent programming language called as Go Lang is super awesome. Here is the certificated of completion for a Google’s Go Programming Language course by Todd Mcleod

golang-certificate

This certificate above verifies that Aseem Jain successfully completed the course Learn How To Code: Google’s Go (golang) Programming Language on Jan. 29, 2017 as taught by Todd McLeod on Udemy. The certificate indicates the entire course was completed as validated by the student.