My Sites


Tuesday, March 29, 2016

Node.js Essentials

http://expressjs.com/en/4x/api.html

    req.params
    req.body
    req.query
----------------------------------------------------------------
    app.get('/user/:id', function(req, res){
      res.send('user ' + req.params.id);
    });

-----------------------------------------------------------------
    var app = require('express')();
    var bodyParser = require('body-parser');
    var multer = require('multer'); // v1.0.5
    var upload = multer(); // for parsing multipart/form-data

    app.use(bodyParser.json()); // for parsing application/json
    app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded


    app.post('/profile', upload.array(), function (req, res, next) {
      console.log(req.body);
      res.json(req.body);
    });

Tuesday, March 1, 2016

Angular 2 + Common Issues and Fixes



The main tutorial 
https://angular.io/docs/ts/latest/quickstart.html#!#main
https://www.youtube.com/watch?v=W14_ZArh6eo

Angular2 QuickStart npm start is not working correctly.
  • make sure set access permission to /usr/lib/mode_modules.
  • make sure to run with sudo.
  • sudo npm install -g concurrently     
  • sudo npm install -g lite-server     
  • sudo npm install -g typescript

Wednesday, February 10, 2016

Angular Nodejs Session and Cookie Management

Angular Cookie
var testApp = angular.module('testAppModule',['ngRoute','ngMaterial','ngCookies','ngMessages']);

testApp.controller("TestController", function($cookieStore,$timeout,$routeParams, $q, $log,$http,$scope,$rootScope,$location,$mdDialog) {
var value =[];

value[0] = dataObj1;
value[1] = dataObj2;
$cookieStore.put('sessionCookie', value);

var cookieRelease =$cookieStore.get('sessionCookie');

});


https://docs.angularjs.org/api/ngCookies/service/$cookieStore
https://docs.angularjs.org/api/ngCookies/service/$cookies
An HTTP cookie (also called web cookie, Internet cookie, browser cookie or simply cookie) 4093 bytes

HTML 5 Local Storage

http://www.w3schools.com/html/html5_webstorage.asp
http://stackoverflow.com/questions/19867599/what-is-the-difference-between-localstorage-sessionstorage-session-and-cookies

if (typeof(Storage) !== "undefined") {
    // Store
    localStorage.setItem("lastname", "Smith");
    // Retrieve
    document.getElementById("result").innerHTML = localStorage.getItem("lastname");
} else {
    document.getElementById("result").innerHTML = "Sorry, your browser does not support Web Storage...";
}


Node.js Cookie parser and Express-Session
https://www.npmjs.com/package/express-session 
https://www.npmjs.com/package/cookie-parser

Thursday, November 5, 2015

(pending—Waiting for next available executor) - FIX

For the master, this is set in Manage Jenkins > Configure System > # of executors
For the slaves (nodes), it is set in Manage Jenkins > Nodes > (each node) > Configure > # of executors

How to schedule jobs (Cron) in Jenkins

Cron job - run periodically at fixed times, dates, or intervals.

A CRON expression is a string comprising five or six fields separated by white space[10] that represents a set of times, normally as a schedule to execute some routine.
    MINUTES Minutes in one hour (0-59)
    HOURS Hours in one day (0-23)
    DAYMONTH Day in a month (1-31)
    MONTH Month in a year (1-12)
    DAYWEEK Day of the week (0-7) where 0 and 7 are sunday

If you want to shedule your build every 5 minutes, this will do the job : */5 * * * *
If you want to shedule your build every day at 8h00, this will do the job : 0 8 * * *
15 13 * * * you tell jenkins to schedule the build every day of every month of every year at the 15th minute of the 13th hour of the day. (13:15)

http://www.unixgeeks.org/security/newbie/unix/cron-1.html

01 * * * * root echo "This command is run at one min past every hour"
17 8 * * * root echo "This command is run daily at 8:17 am"
17 20 * * * root echo "This command is run daily at 8:17 pm"
00 4 * * 0 root echo "This command is run at 4 am every Sunday"
* 4 * * Sun root echo "So is this"
42 4 1 * * root echo "This command is run 4:42 am every 1st of the month"
01 * 19 07 * root echo "This command is run hourly on the 19th of July"

Wednesday, November 4, 2015

Unable to debug in Java with eclipse + Fix

ERROR: transport error 202: connect failed: Connection refused
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:708]
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)

It seams that in some cases DNS is expected to resolve this, and if
firewall prevents localhost requests to DNS - stuff breaks. I had to
alter hosts file and remove comments in following lines.
# 127.0.0.1 localhost    # ::1 localhost   

Use the $in Operator with a Regular Expression + Mongo + Java + Morphia

https://docs.mongodb.org/v3.0/reference/operator/query/in/
The $in operator can specify matching values using regular expressions of the form /pattern/. You cannot use $regex operator expressions inside an $in.

Perform Case-Insensitive Regular Expression Match
https://docs.mongodb.org/manual/reference/operator/query/regex/#perform-case-insensitive-regular-expression-match

Example :-
db.Course.find( { $and: [{callNo: {$in : ["testcourse"]} },{myId :123456 }]})
db.Course.find( { $and: [{callNo: {$in : [/^testcourse$/i]} },{myId :123456 }]})

jmkgreen/morphia (MongoDB object-document mapper in Java. Uses mongo-java-driver. )
https://github.com/jmkgreen/morphia/blob/master/morphia/src/main/java/com/github/jmkgreen/morphia/query/Query.java

Pattern regexDbObject = Pattern.compile("^" + originalCourseCallNo + "$", Pattern.CASE_INSENSITIVE);
mongoDatastore.find(EmployeeEntity.class).filter("email", regexp).get();

List<Pattern> courseCallNoList = new ArrayList<Pattern>();courseCallNoList.add(regexDbObject); 
List<Course>  courses= getDataStore().createQuery(Course.class).field
(Constants.Course.COURSE_CALL_NO).in(courseCallNoList).field
(Constants.Course.CLIENT_ID).equal(clientId).field
(Constants.Course.COURSE_CALL_NO_EXPIRATION_DATE).greaterThanOrEq(courseCallNoExpDate).asList();


http://www.tutorialspoint.com/java/java_regular_expressions.htm