Sunday, February 28, 2021

JSDoc disable source code references:

If you use the default template, then use a configuration file with templates.default.outputSourceFiles set to false. For instance:


{

    "templates": {

        "default": {

            "outputSourceFiles": false

        }

    }

}


You'd pass the path to this file to jsdoc using the -c option on the command line.


The template is the entity providing this functionality so if you use another template than the default one, you have to check its documentation to find whether there is a setting you can set to do this.


References:

https://stackoverflow.com/questions/20907501/how-can-i-omit-the-source-links-in-jsdoc

JSDoc for Javascript Documentation

There are many ways for documenting a piece of code. For example you can write:

  • howtos guides for using your code
  • a nice README for the repo
  • code documentation in the source


Speaking of JavaScript, we can use a documentation layer called, JSDoc. It's a command line tool and a "documentation language" at the same time. Let's see how it can helps.


First thing first what's the anatomy of a JSDoc annotation? JSDoc is simple as adding a comment before the function:


But let's make things interesting with JSDoc annotations for function parameters. Here's the syntax:


/**

*

* @param {param type} param name - description

*

*/


  • its type, i.e. string, number, HTMLTableElement and so on
  • its name
  • description



Example is like below 


/**

 * Generates a table head

 * @param {HTMLTableElement} table - The target HTML table

 * @param {Array} data - The array of cell header names

 */

function generateTableHead(table, data) {

  const thead = table.createTHead();

  const row = thead.insertRow();

  for (const i of data) {

    const th = document.createElement("th");

    const text = document.createTextNode(i);

    th.appendChild(text);

    row.appendChild(th);

  }

}



Adding JSDoc documentation has a side effect. Auto completion will improve in your IDE and you'll get real-time hints:


Moreover, the editor will scream if you try to pass the wrong kind of parameters:

It might sound crazy, but adding JSDoc annotations before writing the code, not after, is another thing you can do. And it has two nice outcomes. First, you will probably write better, simpler code because of the idea of it you formed while writing the documentation.



Other samples are:


/**

 * Generates a table head

 * @author Valentino Gagliardi <valentinoDOTvalentinog.com>

 * @param {HTMLTableElement} table - The target HTML table

 * @param {Array} data - The array of cell header names

 */



/**

 * A silly logger function

 * @param {string} message

 * @return {void} Nothing

 */



/**

 * Raises a number to exponent

 * @param {number} value - The base to raise

 * @param {number} exponent - The exponent

 * @return {number} - The exponent power

 */



JavaScript With JSDoc: generating the docs


mkdir jsdoc-tutorial && cd $_

npm init -y

npm i jsdoc --save-dev


To run Jsdoc in entire directory, below to be done 


$ jsdoc -r .


This may needs to be installed globally to make it available entire system. 


Nam install -g jsdoc


References:

https://www.valentinog.com/blog/jsdoc/



Best Way to document Javascript 




References:

https://gomakethings.com/whats-the-best-way-to-document-javascript/

Wednesday, February 24, 2021

DNS Record Management between GoDaddy and Firebase

To add a custom domain to the firebase app, just need to do this 


  1. Go to hosting and press on Add Custom domain 
  2. Now the firebase will give TXT record details 
  3. Go to the Go Daddy domain management console and add the TXT record 
  4. Once the TXT record is verified, A records will be given by the firebase
  5. Very important to note is on Go daddy, the root is @ and not the domain given by the firebase. So add the domain as @ and then give the IP as the A record IPs given by firebase 
  6. May need to wait for 10-15 minutes to have this change happened. But then good to go! 

Tuesday, February 23, 2021

Android How to set custom Font for entire application

In the styles.xml, define a custom style 


     <style name="CustomTextViewStyle" parent="android:Widget.TextView">

       <item name="android:fontFamily">@font/fonts</item>

     </style>


now inside the fonts folder, create a fonts.xml file and define the below


 <?xml version="1.0" encoding="utf-8"?>

 <font-family xmlns:android="http://schemas.android.com/apk/res/android">

   <font

        android:fontStyle="normal"

        android:fontWeight="400"

        android:font="@font/montserrat" />

    <font

        android:fontStyle="normal"

        android:fontWeight="700"

        android:font="@font/montserrat_bold" />

 </font-family>


and place the font files in the fonts folder itself. 


references:

https://stackoverflow.com/questions/2711858/is-it-possible-to-set-a-custom-font-for-entire-of-application