Wednesday, September 12, 2018

Create Simple application with Nodejs using npm

Below are the summary of the steps I did to create a simple application using nodejs. I have used npm package manager to create this.

Needed Software
1. Download visual studio. get the zip from https://code.visualstudio.com/docs/?dv=winzip
2. Download Nodejs    64 bit binary zip https://nodejs.org/en/download/

Start your first application with Nodejs
1. Create a folder "TuteDemo"
2. Install JSPM and http-server
 a) npm install -g jspm http-server

     This will install jspm and http-server (-g)globally, across server anybody can use it. http-server is very light weight.
  If you have any issues encounter while setting up eg: rename error with path , copy the files to root directory (c:\).
  This will make foder path little less in length.
 
  you will get below output.
---------------------------------
 
C:\Code\React\TuteDemo>npm install -g jspm http-server
C:\node-v8.12.0-win-x64\hs -> C:\node-v8.12.0-win-x64\node_modules\http-server\bin\http-server
C:\node-v8.12.0-win-x64\http-server -> C:\node-v8.12.0-win-x64\node_modules\http-server\bin\http-server
C:\node-v8.12.0-win-x64\jspm -> C:\node-v8.12.0-win-x64\node_modules\jspm\jspm.js
+ http-server@0.11.1
+ jspm@0.16.53
added 341 packages from 233 contributors in 69.733s



2. Initialze the application
 b) nmp init
 press enter and will take default values.
 This will create 'package.json' file with all the initial information related to project.
 Note , root folder name "TuteDemo" automatically taken as package name with lower case.
 Others are set default values and save in json format.


Folder structure

TuteDemo
  -- package.json


{
  "name": "tutedemo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Below is the output
------------------------

C:\Code\React\TuteDemo>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.



3. Install jspm locally.
  for debugging purposes and our ease of use, we install jspm locally.

 c) npm install jspm --save
  
 this will install and --save for run time depnedency. --save-dev  for build

This will add "node_modules" folder and "package-lock.json" under root folder "TuteDemo" 
update "package.json"

"dependencies": {
    "jspm": "^0.16.53"
  }



Folder structure

TuteDemo
  -- node_modules   --> include all files with /bin folder
  -- package.json
  -- package-lock.json

 output - forgot to add --save at first run
 -----------------------------------------------

C:\Code\React\TuteDemo>npm install jspm
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN tutedemo@1.0.0 No description
npm WARN tutedemo@1.0.0 No repository field.
+ jspm@0.16.53
added 316 packages from 212 contributors and audited 2285 packages in 46.101s
found 1 critical severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details

C:\Code\React\TuteDemo>npm install jspm --save
npm WARN tutedemo@1.0.0 No description
npm WARN tutedemo@1.0.0 No repository field.



4. Configure github with jspm registry.

 you need to have github account before running this step. Please go to https://github.com/ and make an account if yo do not have, else check your credential and confirm your username and password are working fine.
 just run "jspm" in command prompt, you will get the all the options associated with it.
 Just press enter and will take default values, only babel need to be set for ES6 Transpiler.
 This will create "config.js" and update "package.json"
 I have got few errors in gitgub account verification. However i have included the output as it is.

 with error in github token config.js as follows

 System.config({
  baseURL: "/",
  defaultJSExtensions: true,
  transpiler: "babel",
  paths: {}
});

 "package.json" you will see below

 "jspm": {
    "dependencies": {}
  }

 d) jspm  registry config github

 output
 ------
 C:\Code\React\TuteDemo>jspm  registry config GitHub

Would you like to set up your GitHub credentials? [yes]:yes
     If using two-factor authentication or to avoid using your password you can generate an access token at https://github.com/settings/tokens. Ensure it has public_repo scope access.
Enter your GitHub username:vrtugit
Enter your GitHub password or access token:
Would you like to test these credentials? [yes]:yes
err  Error: self signed certificate in certificate chain
         at TLSSocket. (_tls_wrap.js:1116:38)
         at emitNone (events.js:106:13)
         at TLSSocket.emit (events.js:208:7)
         at TLSSocket._finishInit (_tls_wrap.js:643:8)
         at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:473:38)

Would you like to try new credentials? [yes]:yes
     If using two-factor authentication or to avoid using your password you can generate an access token at https://github.com/settings/tokens. Ensure it has public_repo scope access.
Enter your GitHub username:vrtugit
Enter your GitHub password or access token:
Would you like to test these credentials? [yes]:no
ok   Registry github configured successfully.


Second time

C:\Code\React\TuteDemo>jspm init

Would you like jspm to prefix the jspm package.json properties under jspm? [yes]:yes

Enter server baseURL (public folder path) [./]:
Enter jspm packages folder [.\jspm_packages]:
Enter config file path [.\config.js]:
Configuration file config.js doesn't exist, create it? [yes]:
Enter client baseURL (public folder URL) [/]:
Do you wish to use a transpiler? [yes]:
Which ES6 transpiler would you like to use, Babel, TypeScript or Traceur? [babel]:babel
ok   Verified package.json at package.json
     Verified config file at config.js
     Looking up loader files...
warn Error on lookup for github:systemjs/systemjs, retrying (1).
     Error: fatal: unable to access 'systemjs/systemjs.git/': SSL certificate problem: self signed certificate in certificate chain

warn Error on lookup for github:systemjs/systemjs, retrying (2).
     Error: fatal: unable to access 'systemjs/systemjs.git/': SSL certificate problem: self signed certificate in certificate chain

warn Error on lookup for github:systemjs/systemjs, retrying (3).
     Error: fatal: unable to access 'systemjs/systemjs.git/': SSL certificate problem: self signed certificate in certificate chain

warn Error on lookup for github:systemjs/systemjs
     Error: fatal: unable to access 'systemjs/systemjs.git/': SSL certificate problem: self signed certificate in certificate chain

err
err  Error downloading loader files.
err




Friday, August 31, 2018

GIT ssl error

I got an ssl error executing git commands.

eg:

$ git push origin master
fatal: unable to access 'https://github.com/vrtugit/git-github.git/': SSL certificate problem: self signed certificate in certificate chain


Solution ( Workaround)

switch off ssl verification

 git -c http.sslVerify=false push origin master

Thursday, August 16, 2018

To be Professional

To be Professional
1. Analytical and Problem solving skill
2. Technical skill
3. Domain knowledge
4. Communication skills - u don't have to be expert, but to be good at with it
5. How to learn

XML Short Note


XML Basics

<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
  <book category="cooking">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
  </book>
</bookstore>

A prolog defines the XML version and the character encoding: this line is called “prolog”
<?xml version="1.0" encoding="UTF-8"?>

next line is the root element of the document:

<bookstore>

The next line starts a <book> element: child element
<book category="cooking">

Every tag should have a closing tag.

Attribute values must always be quoted.

<note date="12/11/2007">
  <to>Tove</to>
  <from>Jani</from>
</note>

Entity References
Character like "<" has special meaning
This will generate an XML error:
<message>salary < 1000</message>
To avoid this error, replace the "<" character with an entity reference:
<message>salary < 1000</message>

< < less than
> > greater than
& & ampersand 
' ' apostrophe
" " quotation mark












<!-- This is a -- comment -->
 Strange, but allowed:
<!-- This is a - - comment -->
White-space is Preserved in XML
XML does not truncate multiple white-spaces (HTML truncates multiple white-spaces to one single white-space):

XML: Hello           Tove
HTML: Hello Tove

XML Stores New Line as LF
Windows applications store a new line as: carriage return and line feed (CR+LF).
Unix and Mac OSX uses LF.
Old Mac systems uses CR.
XML stores a new line as LF.
What is an XML Element?
An XML element is everything from (including) the element's start tag to (including) the element's end tag.
<price>29.99</price>
An element can contain:
• text
• attributes
• other elements
• or a mix of the above

<bookstore>
  <book category="children">
    <title>Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
</bookstore>

<title>, <author>, <year>, and <price> have text content because they contain text (like 29.99).
<bookstore> and <book> have element contents, because they contain elements.
<book> has an attribute (category="children").

Note: you can have space after the name given in the start element tag, not before 
<title      >    - allowed
< title>,  -> Disallowed, Illegal

Empty XML Elements
In XML, you can indicate an empty element like this:
<element></element>
Or
<element />

XML Naming Rules
• Element names are case-sensitive
• Element names must start with a letter or underscore
• Element names cannot start with the letters xml (or XML, or Xml, etc)
• Element names can contain letters, digits, hyphens, underscores, and periods
• Element names cannot contain spaces

Best Naming Practices
Create descriptive names, like this: <person>, <firstname>, <lastname>.
Create short and simple names, like this: <book_title> not like this: <the_title_of_the_book>.
Avoid "-". If you name something "first-name", some software may think you want to subtract "name" from "first".
Avoid ".". If you name something "first.name", some software may think that "name" is a property of the object "first".
Avoid ":". Colons are reserved for namespaces (more later).
Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your software doesn't support them.
Naming Styles
There are no naming styles defined for XML elements. But here are some commonly used:
Style Example Description
Lower case <firstname> All letters lower case
Upper case <FIRSTNAME>
Underscore <first_name> Underscore separates words
Pascal case <FirstName> Uppercase first letter in each word
Camel case <firstName> Uppercase first letter in each word except the first

XML Elements are Extensible
XML elements can be extended to carry more information.
Look at the following XML example:
<note>
  <to>Tove</to>
  <from>Jani</from>
  <body>Don't forget me this weekend!</body>
</note>

Imagine that the author of the XML document added some extra information to it:
<note>
  <date>2008-01-10</date>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

Should the application break or crash?
No. The application should still be able to find the <to>, <from>, and <body> elements in the XML document and produce the same output.
This is one of the beauties of XML. It can be extended without breaking applications.
XML Attributes
Attribute values must always be quoted. Either single or double quotes can be used.
For a person's gender, the <person> element can be written like this:
<person gender="female">
or like this:
<person gender='female'>

If the attribute value itself contains double quotes you can use single quotes, like in this example:
<gangster name='George "Shotgun" Ziegler'>
or you can use character entities: this is more preferable
<gangster name="George "Shotgun" Ziegler">
Note: Metadata (data about data) should be stored as attributes, and the data itself should be stored as elements.

Below is more preferable
<note>
  <date>
    <year>2008</year>
    <month>01</month>
    <day>10</day>
  </date>
  <to>Tove</to>
  <from>Jani</from>
</note>
Avoid XML Attributes?
Some things to consider when using attributes are:
• attributes cannot contain multiple values (elements can)
• attributes cannot contain tree structures (elements can)
• attributes are not easily expandable (for future changes)

Don't end up like this:
<note day="10" month="01" year="2008"
to="Tove" from="Jani" heading="Reminder"
body="Don't forget me this weekend!">
</note>

XML Attributes for Metadata
Sometimes ID references are assigned to elements. These IDs can be used to identify XML elements in much the same way as the id attribute in HTML. This example demonstrates this:
<messages>
  <note id="501">
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
  </note>
</messages>
The id attributes above are for identifying the different notes. It is not a part of the note itself.
Metadata (data about data) should be stored as attributes, and the data itself should be stored as elements.

XML Namespaces
provide a method to avoid element name conflicts.







windows command : findstr


1.       Check pattern start at beginning
h\s1>findstr /b /c:"2017-01-31 11:37:35,85" Test.txt

/b    = from beginning
/c:  = give search string

Some useful SQL Queries


Block queries


SELECT
    spid
    ,sp.status
    ,loginame   = SUBSTRING(loginame, 1, 12)
    ,hostname   = SUBSTRING(hostname, 1, 12)
    ,blk        = CONVERT(char(3), blocked)
    ,open_tran
    ,dbname     = SUBSTRING(DB_NAME(sp.dbid),1,10)
    ,cmd
    ,waittype
    ,waittime
    ,last_batch
    ,SQLStatement       =
        SUBSTRING
        (
            qt.text,
            er.statement_start_offset/2,
            (CASE WHEN er.statement_end_offset = -1
                THEN LEN(CONVERT(nvarchar(MAX), qt.text)) * 2
                ELSE er.statement_end_offset
                END - er.statement_start_offset)/2
        )
FROM master.dbo.sysprocesses sp
LEFT JOIN sys.dm_exec_requests er
    ON er.session_id = sp.spid
OUTER APPLY sys.dm_exec_sql_text(er.sql_handle) as qt
WHERE spid IN (SELECT blocked FROM master.dbo.sysprocesses)
AND blocked = 0


      

Kill process  - kill and processID

kill 201;


check Index

select the db and run

SELECT ps.database_id, object_name(ps.OBJECT_ID) as table_name, ps.index_id, b.name as index_name, ps.avg_fragmentation_in_percent,ps.page_count
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS ps
INNER JOIN sys.indexes AS b ON ps.OBJECT_ID = b.OBJECT_ID
inner join sys.tables as c ON b.object_id = c.object_id
AND ps.index_id = b.index_id
WHERE ps.database_id = DB_ID()
and b.name is not null
ORDER BY ps.avg_fragmentation_in_percent desc



Check last executed stats


/* 1.Query to check when statistics was last executed */
SELECT
  st.object_id                          AS [Table ID]
, OBJECT_NAME(st.object_id)             AS [Table Name]
, st.name                               AS [Index Name]
, STATS_DATE(st.object_id, st.stats_id) AS [LastUpdated]
, modification_counter                  AS [Rows Modified]
FROM
sys.stats st
CROSS APPLY
sys.dm_db_stats_properties(st.object_id, st.stats_id) AS sp
WHERE
STATS_DATE(st.object_id, st.stats_id)<=DATEADD(DAY,-1,GETDATE()) 
AND modification_counter > 0
AND OBJECTPROPERTY(st.object_id,'IsUserTable')=1
order by OBJECT_NAME(st.object_id)





read sp


sp_helptext 'myDb.spName'



few




SELECT
       r.session_id
       ,st.TEXT AS batch_text
       ,SUBSTRING(st.TEXT, statement_start_offset / 2 + 1, (
                     (
                           CASE
                                  WHEN r.statement_end_offset = - 1
                                         THEN (LEN(CONVERT(NVARCHAR(max), st.TEXT)) * 2)
                                  ELSE r.statement_end_offset
                                  END
                           ) - r.statement_start_offset
                     ) / 2 + 1) AS statement_text
       ,qp.query_plan AS 'XML Plan'
       ,r.*
FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS st
CROSS APPLY sys.dm_exec_query_plan(r.plan_handle) AS qp
ORDER BY cpu_time DESC





select
    P.spid,
       P.status
,   right(convert(varchar,
            dateadd(ms, datediff(ms, P.last_batch, getdate()), '1900-01-01'),
            121), 12) as 'batch_duration'
,   P.program_name
,   P.hostname
,   P.loginame
from master.dbo.sysprocesses P
where P.spid > 50
and      P.status not in ('background', 'sleeping','runnable')
and      P.cmd not in ('AWAITING COMMAND'
                    ,'MIRROR HANDLER'
                    ,'LAZY WRITER'
                    ,'CHECKPOINT SLEEP'
                    ,'RA MANAGER')
order by batch_duration desc





Disable and enable windows taskschedular

move "C:\Windows\System32\Tasks\Test\TestPS" "C:\Windows\System32\Tasks\Test\TestPS.bak"


-- enable

move "C:\Windows\System32\Tasks\Test\TestPS.bak" "C:\Windows\System32\Tasks\Test\TestPS"