Thursday, January 24, 2019

Python - downgrade PIP

After upgrading PIP to version 10, I started to face issues with installation of python modules. Hence, I downgraded it to version 9 using the following command:

sudo pip install --force-reinstall pip==9.0.3

References:
https://github.com/pypa/pip/issues/5290

Monday, December 31, 2018

Python - Using virtualenv

Step1: Create a virtual environment:

/opt3$ virtualenv runs02
Running virtualenv with interpreter /usr/bin/python2
New python executable in /opt3/runs02/bin/python2
Also creating executable in /opt3/runs02/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
/opt3$

Step 2: Activate the environment:

$ cd runs02
/opt3/runs02$ ls -l
total 0
drwxr-xr-x 2 mhc mhc 320 Dec 31 12:51 bin
drwxr-xr-x 2 mhc mhc  60 Dec 31 12:51 include
drwxr-xr-x 3 mhc mhc  60 Dec 31 12:51 lib
drwxr-xr-x 2 mhc mhc 100 Dec 31 12:51 local
drwxr-xr-x 3 mhc mhc  60 Dec 31 12:51 share
/opt3/runs02$ which source
opt3/runs02$ $ source bin/activate
(runs02) /opt3/runs02$

Step 3: Now install the needed packages using pip.

Installing pandas:

(runs02) /opt3/runs02$ pip install pandas
Collecting pandas
  Downloading https://files.pythonhosted.org/packages/b7/e3/f52d484244105fa3d558ce8217a5190cd3d40536076bef66d92d01566325/pandas-0.23.4-cp27-cp27mu-manylinux1_x86_64.whl (8.9MB)
    100% |████████████████████████████████| 8.9MB 2.2MB/s 
Collecting pytz>=2011k (from pandas)
  Downloading https://files.pythonhosted.org/packages/f8/0e/2365ddc010afb3d79147f1dd544e5ee24bf4ece58ab99b16fbb465ce6dc0/pytz-2018.7-py2.py3-none-any.whl (506kB)
    100% |████████████████████████████████| 512kB 10.7MB/s 
Collecting numpy>=1.9.0 (from pandas)
  Downloading https://files.pythonhosted.org/packages/de/37/fe7db552f4507f379d81dcb78e58e05030a8941757b1f664517d581b5553/numpy-1.15.4-cp27-cp27mu-manylinux1_x86_64.whl (13.8MB)
    100% |████████████████████████████████| 13.8MB 1.4MB/s 
Requirement already satisfied: python-dateutil>=2.5.0 in ./lib/python2.7/site-packages (from pandas) (2.7.5)
Requirement already satisfied: six>=1.5 in ./lib/python2.7/site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)
Installing collected packages: pytz, numpy, pandas
Successfully installed numpy-1.15.4 pandas-0.23.4 pytz-2018.7
(runs02) /opt3/runs02$



Reference:

Monday, December 17, 2018

VueJS - tools - vue.js dev tools



Step 1: In our chrome browser let us visit the site: https://chrome.google.com/webstore/category/extensions

Step 2: Search for Vue.js devtools:

Step 3: Click on Add to Chrome



Step 4: Click on Add extension:



Now Vue.js devtools has been added to our chrome browser. 

Sunday, December 2, 2018

curl - fetch headers of URL

To fetch only the headers of a HTTP URL, we can use the curl with the -I switch. Consider the following command line:


HTTP/2 200 
server: nginx
date: Sun, 02 Dec 2018 10:09:19 GMT
content-type: text/html; charset=UTF-8
set-cookie: wordpress_google_apps_login=3612792336cb3b1361acd56bb0addf07; path=/; secure
link: <https://www.stanford.edu/wp-json/>; rel="https://api.w.org/"
link: <https://www.stanford.edu/>; rel=shortlink
x-frame-options: SAMEORIGIN
vary: Accept-Encoding
wpe-backend: apache
x-wpe-loopback-upstream-addr: 127.0.0.1:6783
x-cacheable: NO:Set Known Cookie
cache-control: max-age=0, must-revalidate, private
x-cache: MISS
x-pass-why: 
x-cache-group: normal
x-type: default

$ 


In this we fetch the headers sent from the URL of the stanford university. 

Friday, November 16, 2018

TypeScript - Namespaces - drawbacks of namespaces

In our examples of Namespaces - the number of files and namespaces were limited. Consider a case, where the number of files and namespaces are huge in number. In such case managing the dependencies become very difficult.

Hence, in TypeScript we have another feature to better tackle dependency management  - modules.

Reference:

TypeScript - Namespaces - nested namespaces and import alias

In TypeScript, it is possible to include a namespace inside another namespace. This is called nesting of namespaces. Consider the file:

circleArea.ts
namespace myArea {
const PI = Math.PI;
export function circleArea(radius: number){
return PI*radius*radius;
}
}

We can rewrite it to include a circleStuff namespace inside it. 

namespace myArea {
namespace circleStuff {
const PI = Math.PI;
export function circleArea(radius: number){
return PI*radius*radius;
}
}
}

To be able the circleStuff namespace, we must export it - or else, it will be private. Hence, we have to rewrite it again as follows:

namespace myArea {
export namespace circleStuff {
const PI = Math.PI;
export function circleArea(radius: number){
return PI*radius*radius;
}
}
}

To make this work, we must visit our app.ts file and include the nested namespace - circleStuff:
///<reference path="circleArea.ts"/>
///<reference path="squareArea.ts"/>
console.log(myArea.circleStuff.circleArea(5));
console.log(myArea.squareArea(5));

Now, let us compile and reload the browser:

$ tsc app.ts --outFile app.js
$ python -m SimpleHTTPServer 3000
Serving HTTP on 0.0.0.0 port 3000 ...
127.0.0.1 - - [16/Nov/2018 08:04:34] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [16/Nov/2018 08:04:34] "GET /app.js HTTP/1.1" 200 -

Console Output:
78.53981633974483
25

Also, instead if multiple chains of access, we can also create an alias for the nested namespace and then use it in the console.log to access the function using the alias. 

app.ts - rewritten
///<reference path="circleArea.ts"/>
///<reference path="squareArea.ts"/>

// aliasing for circleStuff
import circleStuffImport = myArea.circleStuff;

console.log(circleStuffImport.circleArea(5));
console.log(myArea.squareArea(5));


Now, if we compile and re-run:

$ tsc app.ts --outFile app.js
$ python -m SimpleHTTPServer 3000
Serving HTTP on 0.0.0.0 port 3000 ...
127.0.0.1 - - [16/Nov/2018 08:09:32] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [16/Nov/2018 08:09:32] "GET /app.js HTTP/1.1" 200 -


We observe the same Console Output:
78.53981633974483
25

These are the various ways in which we can use namespaces in TypeScript. 

TypeScript - Namespaces - multiple files using reference path

In our previous blogpost:  https://sashankexpresstech.blogspot.com/2018/11/typescript-namespaces-multiple-files.html ... we have explored how to split a namespace into multiple files and compile them. In both the techniques mentioned, work done to use the files becomes tedious. TypeScript has one more technique to address this issue using reference path

Technique 03:

In our app.ts file, let us include the first two lines mentioned below:
///<reference path="circleArea.ts"/>
///<reference path="squareArea.ts"/>
console.log(myArea.circleArea(5));
console.log(myArea.squareArea(5));

The triple slash mentioned above is a comment. The contents of the comment are used as a compiler directives. They can only be contained in the top of the containing file. For more information, let us refer the following link:
https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html

Now, after we save our app.ts file - let us compile the file by using the following command:
$ tsc app.ts --outFile app.js

Let us start the webserver and then open the address: localhost:3000 in our web browser.

$ python -m SimpleHTTPServer 3000
Serving HTTP on 0.0.0.0 port 3000 ...
127.0.0.1 - - [16/Nov/2018 06:08:47] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [16/Nov/2018 06:08:48] "GET /app.js HTTP/1.1" 200 -

Output in browser console:
78.53981633974483
25

This technique appears to be the most convenient way to include the namespace in multiple files and compiling them for usage.

Reference: