Thursday, March 15, 2018

Get unique values from an array

var array = [1,2,3,4,1,2,1];
array.filter((x,i,a) => a.indexOf(x) == i);
// --result is as below
[1, 2, 3, 4];

filter method is explained as below
x--> the item in array
i--> the index of item
a--> the array itself

Looking for much shorter script? :-)
[... new Set(array)]
This gives the same result
[1, 2, 3, 4]

Thursday, February 15, 2018

Lazy enough with repetitive typing?

Are you lazy enough to repetitive typing in your emails, web apps, content management etc and be more productive with work? Use Auto Text Expander Prokeys for chrome. It's Awesome!

Try it from below URL

https://chrome.google.com/webstore/detail/prokeys/ekfnbpgmmeahnnlpjibofkobpdkifapn?hl=en

Friday, February 2, 2018

What is the difference between toString() and join() in JavaScript

There is a very subtle difference. Example codes below explain much better than lengthy paragraphs.

I am using Node command terminal to work on the example(cleared earlier commands using ctrl+l).

The example in the order of execution from the command prompt:
1. Assign an array of integers to a variable x.
2. Display the content of variable
3. Use of toString()
4. Use of toJoin() - we can see there is no difference in the result. However, join function can take parameter defining the type of delimiter. The default parameter is ",".
5-7. Use of different delimiters







Thursday, February 1, 2018

Lazy to pick mouse to scrawl through site? - Go Vimium

Oh yeah... I am lazy to do things, things which are repetitive which can be either automated or have a better way of doing it. And I mostly get rid off using the mouse while programming but had no choice while browsing through a site. And then what - I searched for a workaround and came across this - Vimium. It's awesome! Try!

The link for this cool chrome extension is below

http://vimium.github.io/

Wednesday, January 31, 2018

cURL - client for URLs

Have been hearing about the tool cURL but never looked into its expansion - its client for URL!

Yes, it deals with URL and hence can also be called as "see URL"

cURL Commands in action:

1. To display content of the site page in your terminal

          curl http://cmshiyas.com

2. Save the output of an URL to a file
   
         curl -o website http://cmshiyas.com

this command saves the output of the site page to the file named website in the current working directory

  • -o (lowercase o) the result will be saved in the filename provided in the command line
  • -O (uppercase O) the filename in the URL will be taken and it will be used as the filename to store the result
        $ curl -O http://cmshiyas.com/index.html

3. Download files

          curl -o archive.zip http://cmshiyas.com/ShiyasFullStackDeveloper.docx

download multiple files

          curl -o archive.zip http://cmshiyas.com/ShiyasFullStackDeveloper.docx -o http://cmshiyas.com/ShiyasFullStackDeveloperNew.docx

to download files securely via SSH

          $ curl -u user ftp://cmshiyas.com

4. Get http header information

           $ curl -I https://google.com

5. Access FTP server

download a file via FTP

                $ curl ftp://ftp.cmshiyas.com/ShiyasFullStackDeveloper.docx --user username:password

upload  a file to server

                $ curl -T file.zip ftp://ftp.cmshiyas.com/ --user username:password

to check cURL man page

               man cURL

Reference:
https://curl.haxx.se/docs/faq.html#What_is_cURL
https://www.rosehosting.com/blog/curl-command-examples/
https://www.thegeekstuff.com/2012/04/curl-examples/

Wednesday, January 17, 2018

How to launch Visual Studio Code from Windows command prompt or Mac Terminal

Launching from the Command Line:

You can also run VS Code from the terminal by typing 'code' after adding it to the path:

  • Launch VS Code.
  • Open the Command Palette (Ctrl+Shift+P) and type 'shell command' to find the Shell Command: Install 'code' command in PATH command.
Mac shell commands
  • Restart the terminal for the new $PATH value to take effect. You'll be able to type 'code .' in any folder to start editing files in that folder.
Note: If you still have the old code alias in your .bash_profile (or equivalent) from an early VS Code version, remove it and replace it by executing the Shell Command: Install 'code' command in PATH command.

How to do tag wrapping in VS code?


  1. Launch VS Code Quick Open (Ctrl+P)
  2. paste 'ext install htmltagwrap' and enter
  3. select HTML
  4. press "Alt + W" ("Option + W" for Mac) and enter the tag name you want to provide.