<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Coach Beard Jr</title>
    <description>The latest articles on DEV Community by Coach Beard Jr (@vijay2249).</description>
    <link>https://dev.to/vijay2249</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F953197%2F03033d14-edf0-44fa-86b6-e14725305bd2.png</url>
      <title>DEV Community: Coach Beard Jr</title>
      <link>https://dev.to/vijay2249</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vijay2249"/>
    <language>en</language>
    <item>
      <title>Python learning on Steroids</title>
      <dc:creator>Coach Beard Jr</dc:creator>
      <pubDate>Mon, 25 Mar 2024 10:46:03 +0000</pubDate>
      <link>https://dev.to/vijay2249/python-learning-on-steroids-ih1</link>
      <guid>https://dev.to/vijay2249/python-learning-on-steroids-ih1</guid>
      <description>&lt;p&gt;Recently i am going through Network and Security in Python book and wanted to write and test the scripts myself.&lt;/p&gt;

&lt;p&gt;Along the way I wanted to learn and code using Vim editor. &lt;/p&gt;

&lt;p&gt;So my target is this&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Continue learning Vim - there is a great tutorial by fireship (search for "fireship vim tutorial") in youtube I am not giving any details/tricks about Vim, that video explain better than me.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I want to keep all my notes at a single place. In a single file is much better.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Along the way I also want snippets of code in between my notes lets call it NOTES.MD&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;At the bottom of the page you can find the link to github repository where this is used in practice.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;All the things started well, until one moment when i coded my first basic script and then wanted to code the second script and run it.&lt;/p&gt;

&lt;p&gt;Essentially I need to create a new file to execute the second piece of code but need to keep my notes in a single file and also need to attach code snippets in NOTES.MD&lt;/p&gt;

&lt;p&gt;Its just irritating to create multiple files and also to copy paste the same code snippet in NOTES.MD also its just repetition work, which is one thing i hate to do the most as i am lazy.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Putting on thinking hats&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I found a way to solve this problem&lt;/p&gt;

&lt;p&gt;The notes -&amp;gt; write them in the comments&lt;/p&gt;

&lt;p&gt;All the scripts write them in a function and call the respective function to execute the respective method/function/script&lt;/p&gt;

&lt;p&gt;An example will be like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;

&lt;span class="sh"&gt;'''&lt;/span&gt;&lt;span class="s"&gt;
    os.walk(path) 
navigates all the directories in the provided path directory, and
returns three values: _the path directory_, _the names of sub-directories_, _list of filenames in
the current directory path
&lt;/span&gt;&lt;span class="sh"&gt;'''&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;os_walk&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;file_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;directories&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;topdown&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;file_count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nb"&gt;file&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[+] &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;sub_folder&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;directories&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[+][+] &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;sub_folder&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[=] Total files in the current directory: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;file_count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;os_walk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now from the above code snippet, I have my notes about something also the code snippet which i can call from the main method.&lt;/p&gt;

&lt;p&gt;If the function needs some arguments then we provide them from the main function as well.&lt;/p&gt;

&lt;p&gt;All is well and good to go.&lt;/p&gt;

&lt;p&gt;BUT WAIT &lt;br&gt;
We can still enhance this right??&lt;/p&gt;

&lt;p&gt;Thinking about this, the problems we face every time we run the new function are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We need to modify the main function logic to call the necessary function&lt;/li&gt;
&lt;li&gt;Also we have to keep in mind that we might not be knowing before hand the parameters that a function needs. (in my case this is one of the issue, since we are the ones defining the function we might not face this issue, but i want to solve this as well)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Points to note&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User will provide which function to execute&lt;/li&gt;
&lt;li&gt;User will provide necessary arguments/parameters via command line arguments&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So the command should be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python main.py &lt;span class="nt"&gt;-f&lt;/span&gt; some_random_function &lt;span class="nt"&gt;--args&lt;/span&gt; &lt;span class="s2"&gt;"{'args1':'values'}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command should execute the &lt;code&gt;some_random_function&lt;/code&gt; with arguments as 'args1' which value is 'values'&lt;/p&gt;

&lt;p&gt;To capture the command line arguments lets use &lt;code&gt;optparse&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;optparse&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OptionParser&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;capture_arguments&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OptionParser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_option&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;function&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Function to execute&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_option&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--args&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;args&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Arguments needed for functions to execute&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{})&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse_args&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have to modify the main method to call the respective function that user mentions via command line arguments&lt;/p&gt;

&lt;p&gt;Now to call the main method from the function we need to use the &lt;code&gt;globals&lt;/code&gt; function that is provided by python.&lt;/p&gt;

&lt;p&gt;Python &lt;code&gt;globals()&lt;/code&gt; function is a built-in function in Python that returns the dictionary of the current global symbol table.&lt;/p&gt;

&lt;p&gt;A symbol table is a data structure that contains all necessary information about the program such as variables, methods, classes etc...&lt;/p&gt;

&lt;p&gt;If we want to call a function say &lt;code&gt;sum&lt;/code&gt; we can use globals function to call the sum function as &lt;code&gt;globals()['sum']()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this manner, we are passing which function to execute via command line arguments which we are capturing via optparse library, which returns the arguments and its parameters.&lt;/p&gt;

&lt;p&gt;defined below is the code snippet for the main function which call the function and executes the function that we provide via command line arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;capture_arguments&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;func&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;function&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[=] Executing &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; function&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="p"&gt;]()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is all working good.&lt;/p&gt;

&lt;p&gt;What if we need some parameters. Sure we can call &lt;code&gt;input()&lt;/code&gt; function whenever these values are required within the function call itself.&lt;/p&gt;

&lt;p&gt;But I want to pass parameters from cli itself. (Another enhancement)&lt;/p&gt;

&lt;p&gt;Lets begin another journey.&lt;/p&gt;

&lt;p&gt;Since we dont know the amount of arguments and the positional arguments that are required by the function we send "&lt;em&gt;kwargs&lt;/em&gt;" to the function as parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;random_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;#some code
&lt;/span&gt;    &lt;span class="n"&gt;arg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;arg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;capture_arguments&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;func&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;function&lt;/span&gt;
    &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[=] Executing &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; function&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the above snippet wont work. The function is expecting dictionary of positional arguments but we giving a string input which then throws &lt;em&gt;TypeError&lt;/em&gt; error&lt;/p&gt;

&lt;p&gt;To resolve this, lets convert string to dictionary using &lt;code&gt;eval()&lt;/code&gt; function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is done, but still we are facing issues that if we run this code we will get error stating that random_function() is not exepecting any positional arguments.&lt;/p&gt;

&lt;p&gt;For this we convert the args again as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is similar to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arg1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;value1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;arg2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;value2&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;#--- snip----
&lt;/span&gt;
&lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;arg1&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;value1&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;arg2&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;value2&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;#--- snip----
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code snippets represents they way we can pass the keyword arguments as a dictionary.&lt;/p&gt;

&lt;p&gt;so we can modify our main method code as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;capture_arguments&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;func&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;function&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[=] Executing &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; function&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now still there is one more issue pending,&lt;br&gt;
  Not all the functions require arguments to execute the code within it.&lt;/p&gt;

&lt;p&gt;So we include try except block in our main method&lt;br&gt;
The function that receive unexpected arguments results in &lt;code&gt;TypeError&lt;/code&gt; error&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;capture_arguments&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;func&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;function&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[=] Executing &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; function&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[=] Trying to execute function with passing arguments&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;TypeError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[=] Executing function without passing arguments&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="p"&gt;]()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hence the problem resolved.&lt;/p&gt;

&lt;p&gt;Now you can create multiple functions in the same file and pass in the respective method name and arguments to execute the specific section of code.&lt;/p&gt;

&lt;p&gt;We can extend this to multiple files as well&lt;/p&gt;

&lt;p&gt;Create a sample files called sample.py and sample2.py&lt;br&gt;
And write some dummy functions in both the files. Say def1, def2 in sample.py file and def3, def4 in sample2.py&lt;/p&gt;

&lt;p&gt;Now create a main.py file and add the below contents in the file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sample&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sample2&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;optparse&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OptionParser&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;capture_arguments&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OptionParser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_option&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;function&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Function to execute&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_option&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--args&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;args&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Arguments needed for functions to execute&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{})&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse_args&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;capture_arguments&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;func&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;function&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[=] Executing &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; function&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[=] Trying to execute function with passing arguments&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;TypeError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[=] Executing function without passing arguments&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="p"&gt;]()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to execute function def1 with arguments &lt;code&gt;val=[1,2], out=False&lt;/code&gt; we can run the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python main.py &lt;span class="nt"&gt;-f&lt;/span&gt; def1 &lt;span class="nt"&gt;--args&lt;/span&gt; &lt;span class="s2"&gt;"{'val':[1,2],'out':False}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There you go.&lt;/p&gt;

&lt;p&gt;Some python steroids drugs which you might not need at all in your lifetime. :)&lt;/p&gt;

&lt;p&gt;Link to code -&amp;gt; &lt;a href="https://github.com/vijay2249/random-stuff/tree/random/Python_On_Steroids"&gt;Python_On_Steroids&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Automate Windows Theme Changes Based on Time with a Batch Script</title>
      <dc:creator>Coach Beard Jr</dc:creator>
      <pubDate>Mon, 13 Nov 2023 05:54:21 +0000</pubDate>
      <link>https://dev.to/vijay2249/automate-windows-theme-changes-based-on-time-with-a-batch-script-57li</link>
      <guid>https://dev.to/vijay2249/automate-windows-theme-changes-based-on-time-with-a-batch-script-57li</guid>
      <description>&lt;p&gt;Lets try to automate the auto-theme change in windows using dll's&lt;/p&gt;

&lt;p&gt;Why you ask?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Well nothing much, I just need an excuse to learn and know how and where dll's can be used in windows&lt;/em&gt;&lt;br&gt;
So starting we do the most basic stuff which is solve our daily issues.&lt;br&gt;
One of my such issues is I want light windows theme during day time and dark theme in night time, so I am trying to automate this process.&lt;/p&gt;

&lt;p&gt;Lets get started, shall we...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;@echo &lt;span class="na"&gt;off&lt;/span&gt;
&lt;span class="nb"&gt;setlocal&lt;/span&gt; &lt;span class="na"&gt;enabledelayedexpansion&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@echo off&lt;/code&gt;: This command disables command echoing, which prevents the console from displaying the actual commands. To make the output of batch scripts cleaner, it is frequently used at the start of the script.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;setlocal enabledelayedexpansion&lt;/code&gt;: This command enables delayed variable expansion. It's necessary when using variables inside a block of code (inside parentheses), as it allows you to access the updated values of variables within the block. In this script, it's used within the &lt;code&gt;for&lt;/code&gt; loop to update the &lt;code&gt;current_hour&lt;/code&gt; variable.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="c"&gt;rem Get the current time in hours (24-hour format)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="na"&gt;/f &lt;/span&gt;&lt;span class="s2"&gt;"tokens=1,2 delims=:"&lt;/span&gt; &lt;span class="vm"&gt;%%a&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;%time%&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="na"&gt;/a &lt;/span&gt;&lt;span class="s2"&gt;"current_hour=&lt;/span&gt;&lt;span class="vm"&gt;%%a&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;rem&lt;/code&gt;: This is a comment or remark. It's used to insert comments into the batch script that describe what a certain piece of code accomplishes. It serves as a sign that we are receiving the current time in this instance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;for /f "tokens=1,2 delims=:" %%a in ("%time%") do ...&lt;/code&gt;: This &lt;code&gt;for&lt;/code&gt; loop is used to split the current time (in the format HH:MM:SS.ss) and extract the hour (HH) part. It uses &lt;code&gt;:&lt;/code&gt; as the delimiter, and the &lt;code&gt;tokens=1,2&lt;/code&gt; option specifies which parts of the string to capture.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;set /a "current_hour=%%a"&lt;/code&gt;: This line assigns the extracted hour to the &lt;code&gt;current_hour&lt;/code&gt; variable. The &lt;code&gt;/a&lt;/code&gt; option tells the &lt;code&gt;set&lt;/code&gt; command to treat the right-hand side as an arithmetic expression.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="c"&gt;rem Set the time ranges for theme changes&lt;/span&gt;
&lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="kd"&gt;morning_start&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt;
&lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="kd"&gt;morning_end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;11&lt;/span&gt;
&lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="kd"&gt;afternoon_start&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;12&lt;/span&gt;
&lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="kd"&gt;afternoon_end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;17&lt;/span&gt;
&lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="kd"&gt;evening_start&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;18&lt;/span&gt;
&lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="kd"&gt;evening_end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;23&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Here, we define time ranges for when different themes should be applied. The script considers the morning (6 AM - 11 AM), afternoon (12 PM - 5 PM), and evening (6 PM - 11 PM) periods. These time ranges are stored in variables like &lt;code&gt;morning_start&lt;/code&gt;, &lt;code&gt;morning_end&lt;/code&gt;, etc.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="c"&gt;rem Choose the theme based on the current time&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;!current_hour!&lt;/span&gt; &lt;span class="ow"&gt;geq&lt;/span&gt; &lt;span class="nv"&gt;%morning_start%&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;!current_hour!&lt;/span&gt; &lt;span class="ow"&gt;leq&lt;/span&gt; &lt;span class="nv"&gt;%morning_end%&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="nb"&gt;reg&lt;/span&gt; &lt;span class="kd"&gt;add&lt;/span&gt; &lt;span class="s2"&gt;"HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"&lt;/span&gt; &lt;span class="na"&gt;/v &lt;/span&gt;&lt;span class="kd"&gt;AppsUseLightTheme&lt;/span&gt; &lt;span class="na"&gt;/t &lt;/span&gt;&lt;span class="kd"&gt;REG_DWORD&lt;/span&gt; &lt;span class="na"&gt;/d &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="na"&gt;/f
&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;!current_hour!&lt;/span&gt; &lt;span class="ow"&gt;geq&lt;/span&gt; &lt;span class="nv"&gt;%afternoon_start%&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;!current_hour!&lt;/span&gt; &lt;span class="ow"&gt;leq&lt;/span&gt; &lt;span class="nv"&gt;%afternoon_end%&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="nb"&gt;reg&lt;/span&gt; &lt;span class="kd"&gt;add&lt;/span&gt; &lt;span class="s2"&gt;"HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"&lt;/span&gt; &lt;span class="na"&gt;/v &lt;/span&gt;&lt;span class="kd"&gt;AppsUseLightTheme&lt;/span&gt; &lt;span class="na"&gt;/t &lt;/span&gt;&lt;span class="kd"&gt;REG_DWORD&lt;/span&gt; &lt;span class="na"&gt;/d &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="na"&gt;/f
&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;!current_hour!&lt;/span&gt; &lt;span class="ow"&gt;geq&lt;/span&gt; &lt;span class="nv"&gt;%evening_start%&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;!current_hour!&lt;/span&gt; &lt;span class="ow"&gt;leq&lt;/span&gt; &lt;span class="nv"&gt;%evening_end%&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="nb"&gt;reg&lt;/span&gt; &lt;span class="kd"&gt;add&lt;/span&gt; &lt;span class="s2"&gt;"HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"&lt;/span&gt; &lt;span class="na"&gt;/v &lt;/span&gt;&lt;span class="kd"&gt;AppsUseLightTheme&lt;/span&gt; &lt;span class="na"&gt;/t &lt;/span&gt;&lt;span class="kd"&gt;REG_DWORD&lt;/span&gt; &lt;span class="na"&gt;/d &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="na"&gt;/f
&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Here, the script checks the &lt;code&gt;current_hour&lt;/code&gt; against the defined time ranges for the different parts of the day. If the current hour falls within a specified range, it uses the &lt;code&gt;reg&lt;/code&gt; command to change the Windows theme settings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;reg add&lt;/code&gt; command modifies the Windows Registry. In this example, it sets the "AppsUseLightTheme" value under the "Personalize" key to 1 (for light theme) during the morning and afternoon, and 0 (for dark theme) in the evening. The &lt;code&gt;/t REG_DWORD&lt;/code&gt; option specifies the data type as a DWORD.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="c"&gt;rem Trigger a theme change&lt;/span&gt;
&lt;span class="nb"&gt;rundll32.exe&lt;/span&gt; &lt;span class="nv"&gt;%SystemRoot%&lt;/span&gt;\System32\shell32.dll&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="kd"&gt;Control_RunDLL&lt;/span&gt; &lt;span class="nv"&gt;%SystemRoot%&lt;/span&gt;\System32\desk.cpl &lt;span class="kd"&gt;desk&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;@Themes &lt;span class="na"&gt;/Action&lt;/span&gt;&lt;span class="nl"&gt;:OpenTheme&lt;/span&gt; &lt;span class="na"&gt;/file&lt;/span&gt;:&lt;span class="s2"&gt;"Path\To\Your\Theme"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Finally, the script uses &lt;code&gt;rundll32.exe&lt;/code&gt; to open the Windows theme control panel. This line of code triggers a theme change based on the specified theme file path. Be sure to replace &lt;code&gt;"Path\To\Your\Theme"&lt;/code&gt; with the actual path to the theme file you want to apply.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This batch script, which can be manually run or scheduled to run at predetermined periods, automates the process of changing the Windows theme dependent on the time of day.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>windows</category>
      <category>beginners</category>
      <category>development</category>
    </item>
    <item>
      <title>Digital Certificates in Communication - What are THOSE???</title>
      <dc:creator>Coach Beard Jr</dc:creator>
      <pubDate>Sun, 12 Nov 2023 14:03:55 +0000</pubDate>
      <link>https://dev.to/vijay2249/digital-certificates-in-communication-what-are-those-3673</link>
      <guid>https://dev.to/vijay2249/digital-certificates-in-communication-what-are-those-3673</guid>
      <description>&lt;h3&gt;
  
  
  Contents Covered
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Public Key Infrastructure ( #PKI )&lt;/li&gt;
&lt;li&gt;Encryption, Hashing, Digital Signatures&lt;/li&gt;
&lt;li&gt;Installing and configuring PKI solutions&lt;/li&gt;
&lt;li&gt;Secure Sockets Layer ( #SSL )&lt;/li&gt;
&lt;li&gt;Transport Layer Security ( #TLS )&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Prerequisite Knowledge
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;TCP/IP - how it works and what is it.&lt;/li&gt;
&lt;li&gt;Web server/browser configuration -  have a general sense of how you might go about configuring a web browser/server&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;SSL - Secure Socket Layer&lt;br&gt;
TLS - Transport Layer Security&lt;/p&gt;

&lt;h3&gt;
  
  
  Public Key Infrastructure
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Understanding Cryptography
&lt;/h4&gt;

&lt;p&gt;SSL/TLS are security protocols that are used to secure network communications&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cryptography&lt;/strong&gt; is a method of securing data such that it is trusted and is viewable only by authorized parties&lt;/p&gt;

&lt;p&gt;For this to work, cryptographic keys need to be stored somewhere in order to partake in securing things like network communications&lt;/p&gt;

&lt;p&gt;Cryptographic Key Storage ways&lt;br&gt;
-&amp;gt; PKI certificate&lt;br&gt;
-&amp;gt; Smart Card/Common Access Card(CAC)&lt;br&gt;
-&amp;gt; File&lt;br&gt;
-&amp;gt; Trusted Platform Module(TPM)&lt;br&gt;
-&amp;gt; Token Device&lt;/p&gt;

&lt;h4&gt;
  
  
  General Encryption Process
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Plaintext is fed into an encryption algorithm&lt;/li&gt;
&lt;li&gt;A key is also used with the encryption algorithm&lt;/li&gt;
&lt;li&gt;The encryption algorithm results in encrypted data (ciphertext)&lt;/li&gt;
&lt;li&gt;Only those parties with a decryption key can decrypt the ciphertext&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Symmetric Cryptography
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Uses a single secret key&lt;/li&gt;
&lt;li&gt;The secret key encrypts and decrypts the data &lt;/li&gt;
&lt;li&gt;All parties that either trying to encrypt or decrypt needs this key&lt;/li&gt;
&lt;li&gt;This key must be kept secure&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Symmetric Encryption Algorithms&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Algorithm&lt;/th&gt;
&lt;th&gt;Max. Key size(bits)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;AES&lt;/td&gt;
&lt;td&gt;256&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RC4&lt;/td&gt;
&lt;td&gt;2048&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3DES&lt;/td&gt;
&lt;td&gt;168&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Blowfish&lt;/td&gt;
&lt;td&gt;448&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Asymmetric Cryptography
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Uses two mathematically related keys&lt;/li&gt;
&lt;li&gt;Public key and private key are used in implementation of these type of algorithms&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Asymmetric Encryption Algorithms&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Algorithm&lt;/th&gt;
&lt;th&gt;Max. Key size (Bits)&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;RSA&lt;/td&gt;
&lt;td&gt;4096&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Diffie-Hellman&lt;/td&gt;
&lt;td&gt;n/a&lt;/td&gt;
&lt;td&gt;This is more of a key exchange mechanism implemented algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ElGamal&lt;/td&gt;
&lt;td&gt;2048&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ECC&lt;/td&gt;
&lt;td&gt;256&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Asymmetric Email Encryption Process&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sender encrypts the plaintext with receivers public key &lt;/li&gt;
&lt;li&gt;Receiver decrypts the encrypted text received using his private key.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;SSL/TLS Network Security process &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Client sends the list of supported ciphers to web server&lt;/li&gt;
&lt;li&gt;Server sends cipher that will be used along with the PKI certificate, which includes the servers public key and the servers hostname&lt;/li&gt;
&lt;li&gt;Client generates and sends a unique session key(symmetric key)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now to secure that symmetric key which is session key, it is encrypted with web servers public key. The web server then decrypts it with its private key&lt;/p&gt;




&lt;h3&gt;
  
  
  PKI hierarchy
&lt;/h3&gt;

&lt;p&gt;PKI is a collection or hierarchy of digital security certificates.&lt;/p&gt;

&lt;p&gt;These certificates always contain public keys of the registered entities&lt;br&gt;
These certificates can also contain private keys which is are defined by the entities in some specific cases for authentication or authorization&lt;/p&gt;

&lt;p&gt;One of such components of PKI hierarchy is&lt;/p&gt;

&lt;p&gt;-&amp;gt; Certificate Authority (CA)&lt;br&gt;
    This component is used to issue new certificates to entities&lt;br&gt;
    It can also renew, revoke certificates&lt;br&gt;
    This CA also maintains the Certification Revocation List(CRL) which is essentially a list of serial number of revoked certificates&lt;/p&gt;

&lt;p&gt;-&amp;gt; Registration Authority (RA)&lt;br&gt;
    Also called subordinate CA. Also used to manage certificates&lt;/p&gt;

&lt;p&gt;-&amp;gt; Certificate Revocation List (CRL) or Online Certificate Status Protocol (OCSP)&lt;br&gt;
    verification of certificate validity using a serial number&lt;/p&gt;

&lt;p&gt;-&amp;gt; Certificate Template&lt;br&gt;
    Blueprint used when issuing certificates&lt;br&gt;
    This can be customized depending on your needs and how the resultant issued PKI certificates are to be used&lt;/p&gt;

&lt;p&gt;-&amp;gt; Certificate&lt;br&gt;
    contains subject name, signature of CA, expiry information, public/private key&lt;/p&gt;

&lt;p&gt;Revoked certificates cannot partake in part of secure communications&lt;/p&gt;

&lt;p&gt;In case of multi-tier PKI hierarchy, from a security perspective, it makes sense to keep the certificate authority at the top of the hierarchy offline until its needed, since we have registration authority doing the work on behalf of the top certificate authority&lt;/p&gt;




&lt;h3&gt;
  
  
  Certificate Authorities
&lt;/h3&gt;

&lt;p&gt;Certificate/registration authorities have a longer validity period than the issued certificates&lt;/p&gt;

&lt;p&gt;Can also publish certification revocation list over a variety of protocols including things like HTTP  and this certificate revocation list can then be retrieved by clients before they partake in communication that would PKI certificates&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chain of Trust&lt;/strong&gt;&lt;br&gt;
    The digital signatures of the certificate authority will exist in all of the certificates that it issues&lt;br&gt;
    -&amp;gt; We trust CA that implies we trust all the certificates that it issue&lt;/p&gt;

&lt;p&gt;SSL/TLS are directly related to PKI certificates&lt;/p&gt;

&lt;p&gt;PKI certificates are also called &lt;em&gt;X.509 certificates&lt;/em&gt; as it follows X.509 standard&lt;/p&gt;




&lt;h4&gt;
  
  
  What type of data is stored in PKI certificates?
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Version number

&lt;ol&gt;
&lt;li&gt;defines the X.509 or PKI version number&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;Serial number

&lt;ol&gt;
&lt;li&gt;used to track certificates such as through certification revocation list, &lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;CA digital signature and Algorithm used&lt;/li&gt;
&lt;li&gt;validity period&lt;/li&gt;
&lt;li&gt;Certificate usage details&lt;/li&gt;
&lt;li&gt;Subject name such as URL or email address or domain name etc..&lt;/li&gt;
&lt;li&gt;Public or Private keys&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We can use wildcard certificates for multiple DNS second level domain names via the subject&lt;br&gt;
This means that the certificate is issued to top-level DNS domain and all the subdomains are automatically trusted using single PKI certificate&lt;/p&gt;

&lt;p&gt;OCSP Stapling&lt;br&gt;
    certificate owner checks the CA for its status periodically, such as a web server with an SSL/TLS certificate&lt;br&gt;
    Clients connecting to the secured website receive OCSP status for that website&lt;br&gt;
    In this case, clients do not have to query the OCSP responder for website certificate status separately&lt;/p&gt;

&lt;p&gt;PKP - Public Key Pinning&lt;br&gt;
    This is information that is sent between the client web browser and web server so that trusting devices can download a trusted copy of a server certificate which includes public key&lt;br&gt;
    In this we store a copy of that server certificate public key locally on the client device&lt;br&gt;
    Upon future connections to the server, clients require that the server provide a fingerprint that has been previously pinned&lt;br&gt;
    By this we are mitigating certificates issued to known hosts from unauthorized CAs such as &amp;lt;mail.google.com&amp;gt; being issued a certificate from an attackers self-signed CA&lt;br&gt;
    These also have a certified lifetime &lt;/p&gt;




&lt;h4&gt;
  
  
  Certificate Lifecycle
&lt;/h4&gt;

&lt;p&gt;It starts with certificate request, this can be manual or it can be automated&lt;br&gt;
If everything is okay, then the certificate is issued, then it can be used according to its purpose&lt;br&gt;
If the certificate is expired then new certificate must be created and digitally signed and to be send to receiver&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Certificate request

&lt;ol&gt;
&lt;li&gt;depending on the algorithm being used and software is used, public and private key of the entity is created and then public keys are made available to trusted third parties&lt;/li&gt;
&lt;li&gt;Certificate Signing Request(CSR) is generated next, which includes a unique public key commonly in PKCS #10 format&lt;/li&gt;
&lt;li&gt;This CSR is sent to certificate authority for signing&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;Certificate issuance

&lt;ol&gt;
&lt;li&gt;require admin approval before certificate is issued&lt;/li&gt;
&lt;li&gt;certificate is stored in the device trusted certificate store or other media such as a smart card&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;Certificate usage

&lt;ol&gt;
&lt;li&gt;apps can first verify the validity of a certificate before using them (via CRL or OCSP)&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;Certificate revocation&lt;/li&gt;
&lt;li&gt;Certificate renewal&lt;/li&gt;
&lt;li&gt;Certificate expiry&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  SSL vs TSL
&lt;/h3&gt;

&lt;p&gt;Both uses PKI certificates and related keys to secure network communication&lt;/p&gt;

&lt;p&gt;Both in conjunction with PKI certificates, allow for data encryption and confidentiality&lt;br&gt;
Also allows for digital signatures and hashing for authentication, integrity and non-repudiation&lt;/p&gt;

&lt;p&gt;Both protocols are application specific, it must be configured separately for HTTP and SMTP and similar protocols &lt;/p&gt;

&lt;p&gt;Security protocol downgrade attacks are common and are problems with the current standard of SSL protocols and hence it is recommended to use TLS instead of SSL unless its necessary&lt;/p&gt;

&lt;p&gt;For security reasons, disable SSL and use TLS &amp;gt;v1.1&lt;/p&gt;




&lt;h3&gt;
  
  
  Hashing and Digital Signatures
&lt;/h3&gt;

&lt;p&gt;Hashing doesn't provide data confidentiality&lt;/p&gt;

&lt;p&gt;Used to verify the integrity of network messages, files and machine boot-up settings&lt;/p&gt;

&lt;p&gt;Used in both SSL and TLS&lt;br&gt;
Uses a one-way algorithm that results in a unique value from which we cant generate input value except using the brute-force method&lt;/p&gt;

&lt;p&gt;Digital Signatures provides data authentication, integrity and non-repudiation&lt;br&gt;
This is done by using the private key of the user, so if a message is sent by a user that user sings the message using his private key so that once we decrypt it with the users public key we can actually verify the user authentication for the message sent.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What are the different types of DNS records, and what are their specific purposes?</title>
      <dc:creator>Coach Beard Jr</dc:creator>
      <pubDate>Sat, 04 Nov 2023 10:28:19 +0000</pubDate>
      <link>https://dev.to/vijay2249/what-are-the-different-types-of-dns-records-and-what-are-their-specific-purposes-3ef4</link>
      <guid>https://dev.to/vijay2249/what-are-the-different-types-of-dns-records-and-what-are-their-specific-purposes-3ef4</guid>
      <description>&lt;p&gt;DNS (Domain Name System) records are used to manage and translate domain names into IP addresses, allowing computers to locate and communicate with each other over the internet. There are various types of DNS records, each serving a specific purpose. Here are some common types of DNS records and their purposes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;A (Address) Record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Purpose: Maps a domain name to an IPv4 address.&lt;/li&gt;
&lt;li&gt;Example: example.com IN A 192.168.1.1&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;AAAA (IPv6 Address) Record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Purpose: Maps a domain name to an IPv6 address.&lt;/li&gt;
&lt;li&gt;Example: example.com IN AAAA 2001:0db8:85a3:0000:0000:8a2e:0370:7334&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;CNAME (Canonical Name) Record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Purpose: Creates an alias for an existing A or AAAA record. It points one domain name to another.&lt;/li&gt;
&lt;li&gt;Example: &lt;a href="http://www.example.com"&gt;www.example.com&lt;/a&gt; IN CNAME example.com&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;MX (Mail Exchanger) Record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Purpose: Specifies the mail server responsible for receiving email messages for a domain.&lt;/li&gt;
&lt;li&gt;Example: example.com IN MX 10 mail.example.com&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;TXT (Text) Record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Purpose: Used for storing text-based information, such as SPF (Sender Policy Framework) records, DKIM (DomainKeys Identified Mail) keys, and other human-readable data.&lt;/li&gt;
&lt;li&gt;Example: example.com IN TXT "v=spf1 include:_spf.example.com ~all"&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SRV (Service) Record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Purpose: Specifies the location of services, such as SIP, XMPP, and other network services.&lt;/li&gt;
&lt;li&gt;Example: _sip._udp.example.com IN SRV 0 5 5060 sipserver.example.com&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;NS (Name Server) Record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Purpose: Specifies the authoritative name servers for a domain.&lt;/li&gt;
&lt;li&gt;Example: example.com IN NS ns1.example-dns.com&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;PTR (Pointer) Record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Purpose: Used for reverse DNS lookups to map an IP address to a domain name.&lt;/li&gt;
&lt;li&gt;Example: 1.1.168.192.in-addr.arpa IN PTR example.com&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SOA (Start of Authority) Record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Purpose: Contains administrative information about a zone, including the primary name server and contact information.&lt;/li&gt;
&lt;li&gt;Example: example.com IN SOA ns1.example-dns.com admin.example.com 2023102401 7200 3600 604800 3600&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SPF (Sender Policy Framework) Record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Purpose: Specifies which IP addresses are allowed to send email on behalf of a domain, helping to prevent email spoofing and phishing.&lt;/li&gt;
&lt;li&gt;Example: example.com IN TXT "v=spf1 include:_spf.example.com ~all"&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These DNS record types serve different functions and are essential for the proper functioning of the internet. They allow domain names to be associated with various services and resources, such as web servers, email servers, and more. The choice of which record type to use depends on the specific requirements of the domain and the services it provides.&lt;/p&gt;

</description>
      <category>dns</category>
      <category>beginners</category>
      <category>discuss</category>
      <category>network</category>
    </item>
    <item>
      <title>Auto Publish/Release - GitHub Actions</title>
      <dc:creator>Coach Beard Jr</dc:creator>
      <pubDate>Sun, 29 Oct 2023 15:03:28 +0000</pubDate>
      <link>https://dev.to/vijay2249/auto-publishrelease-github-actions-a29</link>
      <guid>https://dev.to/vijay2249/auto-publishrelease-github-actions-a29</guid>
      <description>&lt;p&gt;Continuous Integration(CI) is often coupled with the idea of Continuous Delivery(CD).&lt;/p&gt;

&lt;p&gt;For releasing or publishing our code automatically, we will use the action &lt;a href="https://github.com/marketplace/actions/release-drafter"&gt;Release Drafter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have to configure our actions file.&lt;/p&gt;

&lt;p&gt;We can create new workflow file or we can add this workflow to our already present files.&lt;/p&gt;

&lt;h4&gt;
  
  
  If you want to add the release drafter workflow to already present action file, then the snippet is
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;PreviousContent&amp;gt;&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="s"&gt;&amp;lt;PreviousContent&amp;gt;&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;allPreviousJos&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="s"&gt;&amp;lt;PreviousJobsContent&amp;gt;&lt;/span&gt;

    &lt;span class="na"&gt;update_draft_release&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
        &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;All previous jobs comma separated&lt;/span&gt; &lt;span class="pi"&gt;]&lt;/span&gt;
        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;toolmantim/release-drafter@v5.2.0&lt;/span&gt;
              &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                  &lt;span class="na"&gt;GITHUB_TOKEN&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.GITHUB_TOKEN }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see the above code snippet we added one more keyword &lt;code&gt;needs&lt;/code&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  needs
&lt;/h4&gt;

&lt;p&gt;This just means that this particular jobs requires the mentioned jobs to be executed first then run this particular job.&lt;/p&gt;

&lt;p&gt;In our code, we need our publish job to be executed once all our tests and build process is executed successfully, so in that sense we want to execute the build, test, and all other steps to run perfectly and then execute this publish method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;hi-mom&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo Hi MOM&lt;/span&gt;
    &lt;span class="na"&gt;hi-dad&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="s"&gt;run echo Hi DAD&lt;/span&gt;

    &lt;span class="na"&gt;hi-bro&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
        &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;job1&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;job2&lt;/span&gt;
        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo "Hello BRO"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h4&gt;
  
  
  If you are adding new workflow file for the auto-publish process
&lt;/h4&gt;

&lt;p&gt;create new file with whatever name you want and have the below content in that file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Release Drafter&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# branches to consider in the event; optional, defaults to all&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;master&lt;/span&gt;
  &lt;span class="c1"&gt;# pull_request event is required only for autolabeler&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Only following types are handled by the action, but one can default to all as well&lt;/span&gt;
    &lt;span class="na"&gt;types&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;opened&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;reopened&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;synchronize&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;# pull_request_target event is required for autolabeler to support PRs from forks&lt;/span&gt;
  &lt;span class="c1"&gt;# pull_request_target:&lt;/span&gt;
  &lt;span class="c1"&gt;#   types: [opened, reopened, synchronize]&lt;/span&gt;

&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;update_release_draft&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# permissions:&lt;/span&gt;
      &lt;span class="c1"&gt;# write permission is required to create a github release&lt;/span&gt;
      &lt;span class="c1"&gt;# contents: write&lt;/span&gt;
      &lt;span class="c1"&gt;# write permission is required for autolabeler&lt;/span&gt;
      &lt;span class="c1"&gt;# otherwise, read permission is required at least&lt;/span&gt;
      &lt;span class="c1"&gt;# pull-requests: write&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;# (Optional) GitHub Enterprise requires GHE_HOST variable set&lt;/span&gt;
      &lt;span class="c1"&gt;#- name: Set GHE_HOST&lt;/span&gt;
      &lt;span class="c1"&gt;#  run: |&lt;/span&gt;
      &lt;span class="c1"&gt;#    echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" &amp;gt;&amp;gt; $GITHUB_ENV&lt;/span&gt;

      &lt;span class="c1"&gt;# Drafts your next Release notes as Pull Requests are merged into "master"&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;release-drafter/release-drafter@v5&lt;/span&gt;
        &lt;span class="c1"&gt;# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml&lt;/span&gt;
        &lt;span class="c1"&gt;# with:&lt;/span&gt;
        &lt;span class="c1"&gt;#   config-name: my-config.yml&lt;/span&gt;
        &lt;span class="c1"&gt;#   disable-autolabeler: true&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;GITHUB_TOKEN&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.GITHUB_TOKEN }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once this is done, &lt;br&gt;
The release drafter requires a template to create all the changes and updates that the release had and little like documentation for updated version of release thing.&lt;/p&gt;

&lt;p&gt;So create this template in &lt;code&gt;.github&lt;/code&gt; folder with below contents&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;

  &lt;span class="s"&gt;## What's Changed&lt;/span&gt;

  &lt;span class="s"&gt;$CHANGES&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now commit the changes.&lt;/p&gt;

&lt;p&gt;Remember that the template should be named as &lt;code&gt;release-drafter.yml&lt;/code&gt; in &lt;code&gt;.github&lt;/code&gt; folder in your repo&lt;/p&gt;




&lt;p&gt;Here comes the good part&lt;/p&gt;

&lt;p&gt;Make some random changes in the repo but not in main branch, let those changes be anything&lt;/p&gt;

&lt;p&gt;Here i will do some changes regarding in the index.js file and commit them in the &lt;code&gt;testing&lt;/code&gt; branch&lt;/p&gt;

&lt;p&gt;Once the necessary changes are done, raise the pr and wait for workflows to run and see whether they all checks are passed or not, if not &lt;strong&gt;resolve the issue&lt;/strong&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  Releases
&lt;/h4&gt;

&lt;p&gt;Now if you click on &lt;code&gt;releases&lt;/code&gt; link in your repo, you will see a draft release docs already being created which is created by &lt;em&gt;github-actions&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The draft version may look something like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu2nfttigb1wlxl3ealeb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu2nfttigb1wlxl3ealeb.png" alt="Draft-Release-Content" width="800" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this i have modified some content in the draft release which is title of the release&lt;/p&gt;

&lt;p&gt;You can also edit this draft or delete this draft &lt;/p&gt;

&lt;p&gt;Now release your package...&lt;/p&gt;

&lt;p&gt;GitHub Actions part 3 DONE...&lt;/p&gt;

</description>
      <category>githubactions</category>
      <category>automation</category>
      <category>devops</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Continuous Integration - GitHub Actions</title>
      <dc:creator>Coach Beard Jr</dc:creator>
      <pubDate>Sat, 28 Oct 2023 17:29:20 +0000</pubDate>
      <link>https://dev.to/vijay2249/continuous-integration-github-actions-4goa</link>
      <guid>https://dev.to/vijay2249/continuous-integration-github-actions-4goa</guid>
      <description>&lt;p&gt;Base Repository for this example is &lt;a href="https://github.com/vijay2249/github-actions-playground"&gt;Github-Actions-Playground&lt;/a&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  Topics Covered
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;NodeJs Workflow changes from generated default workflow &lt;/li&gt;
&lt;li&gt;strategy -- what is strategy in github actions&lt;/li&gt;
&lt;li&gt;matrix -- what is the use of this in github actions&lt;/li&gt;
&lt;li&gt;include -- what is the use of this in github actions&lt;/li&gt;
&lt;li&gt;workflow_dispatch -- what is this in github actions&lt;/li&gt;
&lt;li&gt;Actual workflow of our nodejs action&lt;/li&gt;
&lt;li&gt;Building the test node js app.&lt;/li&gt;
&lt;li&gt;Then seeing whether the actions are running correctly or not&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;The playground repository contains the javascript code and we are going to use NodeJs environment to test and build our code.&lt;/p&gt;

&lt;p&gt;For this you can fork this repo or create new one in another language maybe Scala or Python to actually get your hands dirty in all ways.&lt;/p&gt;

&lt;p&gt;Go to repository -&amp;gt; Actions Tab -&amp;gt; Search for lang CI action (in my case it is NodeJs env) -&amp;gt; click on Configure button&lt;/p&gt;




&lt;h4&gt;
  
  
  If you are not using NodeJs workflow you can skip this section
&lt;/h4&gt;

&lt;p&gt;The changes I made from the default yaml file&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I don't need Node 14.x version&lt;/li&gt;
&lt;li&gt;Added &lt;code&gt;name&lt;/code&gt; fields in all &lt;code&gt;npm&lt;/code&gt; commands&lt;/li&gt;
&lt;/ol&gt;




&lt;h4&gt;
  
  
  strategy
&lt;/h4&gt;

&lt;p&gt;This is used to &lt;code&gt;matrix&lt;/code&gt; strategy for jobs, (which we discussed in github-actions series in dev.to post) &lt;a href="https://dev.to/vijay2249/intro-to-github-actions-2ce"&gt;Intro to GITHUB ACTIONS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A matrix strategy lets you use variables in a single job definition to automatically create multiple jobs that are based on the combinations of the variables.&lt;/p&gt;

&lt;p&gt;Example case is that you want to test your code in multiple versions and in multiple os systems&lt;/p&gt;

&lt;p&gt;For this we use &lt;code&gt;matrix&lt;/code&gt; &lt;/p&gt;




&lt;h4&gt;
  
  
  matrix
&lt;/h4&gt;

&lt;p&gt;Use this to define your variables of different job configurations.&lt;br&gt;
Within your matrix, you can define one or more variables followed by an array of values.&lt;/p&gt;

&lt;p&gt;Examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github matrix example&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;matrix_example&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;strategy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;matrix&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                &lt;span class="na"&gt;members&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;MOM"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DAD"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;BRO"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Say hello to everyone&lt;/span&gt;
              &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo Hello ${{matrix.members}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use multiple variables in the matrix&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github matrix example&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;matrix_example&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;strategy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;matrix&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                &lt;span class="na"&gt;members&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;MOM"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DAD"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;BRO"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
                &lt;span class="na"&gt;os&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;windows-latest&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;ubuntu-latest&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
        &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{matrix.os}}&lt;/span&gt;
        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Say hello to everyone&lt;/span&gt;
              &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo Hello ${{matrix.members}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This above workflow will run for each possible combination of the variables "os" and "members"&lt;/p&gt;

&lt;p&gt;To add new values to the matrix variable you can use &lt;code&gt;include&lt;/code&gt; key to do that.&lt;/p&gt;




&lt;h4&gt;
  
  
  include
&lt;/h4&gt;

&lt;p&gt;For each object in the &lt;code&gt;include&lt;/code&gt; list, the key:value pairs in the object will be added to each of the matrix combinations if none of the key:value pairs overwrite any of original matrix values&lt;/p&gt;

&lt;p&gt;If the object cannot be added to any of the matrix combinations, a new matrix combination will be created instead.&lt;br&gt;
The original matrix values will not be overwritten, but added matrix values van be overwritten&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;strategy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;matrix&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;fruit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;apple&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;pear&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;animal&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;cat&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;dog&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;include&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;green&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pink&lt;/span&gt;
        &lt;span class="na"&gt;animal&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;cat&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;fruit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;apple&lt;/span&gt;
        &lt;span class="na"&gt;shape&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;circle&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;fruit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;banana&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;fruit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;banana&lt;/span&gt;
        &lt;span class="na"&gt;animal&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;cat&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the runner have the following combinations to run the job&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;{fruit: apple, animal: cat, color: pink, shape: circle}&lt;/li&gt;
&lt;li&gt;{fruit: apple, animal: dog, shape: circle, color: green}&lt;/li&gt;
&lt;li&gt;{fruit: pear, animal: cat, color: pink}&lt;/li&gt;
&lt;li&gt;{fruit: pear, animal: dog, color: green}&lt;/li&gt;
&lt;li&gt;{fruit: banana, animal: cat}&lt;/li&gt;
&lt;li&gt;{fruit: banana}&lt;/li&gt;
&lt;/ol&gt;




&lt;h4&gt;
  
  
  workflow_dispatch
&lt;/h4&gt;

&lt;p&gt;To run a workflow manually, the workflow must be configured to run on the &lt;code&gt;workflow_dispatch&lt;/code&gt; event&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To trigger the &lt;code&gt;workflow&lt;/code&gt; event, your workflow must be in the default branch.&lt;br&gt;
Based on your configurations, write access might be required to the repository is required to perform jobs&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h4&gt;
  
  
  Actual workflow of our nodejs action
&lt;/h4&gt;

&lt;p&gt;Now coming to the CI part of actions.&lt;/p&gt;

&lt;p&gt;create and commit that yml/yaml file to github repo&lt;/p&gt;

&lt;p&gt;Once you commit your file, if you go to actions tab, you will one action that is automatically started, well there will be multiple if you follow previous article also, but for time being one NodeJs action will be triggered automatically.&lt;/p&gt;

&lt;p&gt;Why you might ask..&lt;/p&gt;

&lt;p&gt;Well the reason is the below code snippet in the yaml file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;main'&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;main'&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;

    &lt;span class="na"&gt;workflow_dispatch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you already know why &lt;code&gt;workflow_dispatch&lt;/code&gt; is added.&lt;/p&gt;

&lt;p&gt;Moving on we also added &lt;code&gt;push&lt;/code&gt; and &lt;code&gt;pull_request&lt;/code&gt; that means that for every pull request and commits in that particular branch of &lt;strong&gt;main&lt;/strong&gt; the action will start automatically.&lt;/p&gt;




&lt;p&gt;So far we have not clearly seen this actions to clear usage I think.&lt;br&gt;
Like we want to use these actions while we are collaborating right.&lt;/p&gt;

&lt;p&gt;So let us create a new branch from the repo and we will make some changes and create a pull request to the default main branch.&lt;/p&gt;

&lt;p&gt;Now my main branch name is &lt;code&gt;main&lt;/code&gt; and i will be creating a branch &lt;code&gt;testing&lt;/code&gt; from the &lt;code&gt;main&lt;/code&gt; branch and I will add a new test case in this &lt;code&gt;testing&lt;/code&gt; branch in &lt;code&gt;index.test.js&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;that weekNum returns a number&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;weekNum&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toBeDefined&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the above code snippet in &lt;code&gt;index.test.js&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Now create a pull request(pr) from your testing branch to your main branch.&lt;/p&gt;

&lt;p&gt;Once the pr is raised you will see the checks from nodejs action file starts running.&lt;br&gt;
You will see something like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0nzmhj4xlfbivjwvvoal.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0nzmhj4xlfbivjwvvoal.png" alt="NodeJs-GitHub-Actions" width="800" height="269"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can see the power of github actions&lt;/p&gt;

&lt;p&gt;You don't have to worry about first merging the changes and go through hell to find out that there are some conflicts in production and then try to find out what are the changes that need to be done again.&lt;/p&gt;

&lt;p&gt;Instead you will implement all those checks for all the PRs and if these checks are successful you can merge these changes and don't have to worry about fixing the errors in production because you are checking them before releasing them or better even before merging new changes to base code.&lt;/p&gt;



&lt;p&gt;So the install and test process of our workflow is done and there are no errors.&lt;/p&gt;

&lt;p&gt;Lets go through build process&lt;/p&gt;


&lt;h2&gt;
  
  
  Build process
&lt;/h2&gt;

&lt;p&gt;The Github Actions workflow allows users to take advantage of vast selection of open source tools and solutions. Since actions workflow &lt;em&gt;runners&lt;/em&gt; are in themselves VMs running on cloud servers.&lt;/p&gt;

&lt;p&gt;This is different from GitHub app workflow, which requires you to host it on your own server&lt;/p&gt;

&lt;p&gt;For this we will use &lt;a href="https://parceljs.org/getting-started/webapp/"&gt;Parcel&lt;/a&gt; to build our scripts.&lt;/p&gt;

&lt;p&gt;First install the module&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; parcel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we have only one file we can build using the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx parcel index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Else in out &lt;code&gt;package.json&lt;/code&gt; file add the following configuration in &lt;em&gt;scripts&lt;/em&gt; variable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"build": "parcel build index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once after adding, this should be the outlook of your &lt;code&gt;package.json&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"github-actions-playground"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.1.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"playground area to learn about github-actions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"main"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"index.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"jest"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"parcel build index.js"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;//here&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;we&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;are&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;directly&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;pointing&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;file&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;we&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;need&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;build&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vijay2249"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"license"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ISC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"devDependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"jest"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^29.7.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"parcel"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^2.10.1"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now once the changes are done, commit your changes and then the actions will run automatically as you mentioned in yml file that the action should run on each pull request and on each push to global repo.&lt;/p&gt;

&lt;p&gt;So now scroll down to the build step and now see for yourself how the output looks like in the build step.&lt;/p&gt;

&lt;p&gt;Consider this as homework or getting your hands dirty.&lt;br&gt;
Side note -&amp;gt; check the errors carefully if there are any, for what and where to make changes in your code.&lt;/p&gt;

&lt;p&gt;BTW &lt;a href="https://github.com/actions/starter-workflows"&gt;starter-workflows&lt;/a&gt;  &amp;lt;- this is official github repository with some examples on github actions.&lt;br&gt;
Just go through them and you have to spend less time reading these type of extra peoples notes :)&lt;/p&gt;

&lt;p&gt;:) :) &lt;/p&gt;

&lt;p&gt;Lets continue the next part some other time.&lt;/p&gt;

</description>
      <category>githubactions</category>
      <category>automation</category>
      <category>devops</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Servlets &amp; Filters - SpringSecurity</title>
      <dc:creator>Coach Beard Jr</dc:creator>
      <pubDate>Fri, 27 Oct 2023 16:23:56 +0000</pubDate>
      <link>https://dev.to/vijay2249/servlets-filters-springsecurity-2ocd</link>
      <guid>https://dev.to/vijay2249/servlets-filters-springsecurity-2ocd</guid>
      <description>&lt;h3&gt;
  
  
  Servlets
&lt;/h3&gt;

&lt;p&gt;In Java web apps, Servlet container (web server) takes care of translating the HTTP messages for &lt;br&gt;
java code to understand. One of mostly used servlet container is Apache Tomcat.&lt;/p&gt;

&lt;p&gt;Servlet Container converts the HTTP messages into ServletRequest and hand over to Servlet method as a parameter&lt;/p&gt;

&lt;p&gt;Similarly, ServletResponse returns as an output to Servlet Container from Servlet. So everything we write inside the Java web apps are driven by Servlets&lt;/p&gt;




&lt;h3&gt;
  
  
  Filters
&lt;/h3&gt;

&lt;p&gt;Filters inside Java Web Applications can be used to intercept each request/response and do some pre-work before our business logic. So using the same filters, Spring Security enforce security based on our configurations inside a web application&lt;/p&gt;




&lt;h3&gt;
  
  
  Spring Security Internal Flow
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Spring Security Filters
&lt;/h4&gt;

&lt;p&gt;A series of spring security filters intercept each request and work together to identify if authentication is required or not.&lt;/p&gt;

&lt;p&gt;If authentication is required, accordingly navigate the user to login page or use the existing details stored during the initial authentication&lt;/p&gt;

&lt;h4&gt;
  
  
  Authentication
&lt;/h4&gt;

&lt;p&gt;Filters like &lt;em&gt;UsernamePasswordAuthenticationFilter&lt;/em&gt; will extract username/password from HTTP request and prepare Authentication type object. Because Authentication is the core standard of storing authenticated user details inside Spring Security Framework&lt;/p&gt;

&lt;h4&gt;
  
  
  AuthenticationProvider
&lt;/h4&gt;

&lt;p&gt;AuthenticationProviders has all the core logic of validating user details for authentication&lt;/p&gt;

&lt;h4&gt;
  
  
  UserDetailsManager/UserDetailsService
&lt;/h4&gt;

&lt;p&gt;UserDetailsManager/UserDetailsService helps in retrieving, creating, updating, deleting the User details from the DB/storage systems&lt;/p&gt;

&lt;h4&gt;
  
  
  PasswordEncoder
&lt;/h4&gt;

&lt;p&gt;Service interface that helps in encoding and hashing passwords. Otherwise we may have to live with plain text passwords&lt;/p&gt;

&lt;h4&gt;
  
  
  SecurityContext
&lt;/h4&gt;

&lt;p&gt;Once the request has been authenticated, the Authentication will usually be stored in a thread-local SecurityContext managed by the SecurityContextHolder.&lt;/p&gt;

&lt;p&gt;This helps during the upcoming requests from the same user&lt;/p&gt;




&lt;h2&gt;
  
  
  Sequence Flow
&lt;/h2&gt;

&lt;p&gt;--&amp;gt; Request --&amp;gt; [&amp;lt;Authentication Filters&amp;gt; {AuthorizationFilter, DefaultLoginPageGeneratingFilter, UsernamePasswordAuthenticationFilter}] --&amp;gt; Extract User Credentials --&amp;gt; [&amp;lt;Authentication&amp;gt;{UsernamePasswordAuthenticationToken}] --&amp;gt; authenticate() --&amp;gt; [&amp;lt;AuthenticationManager&amp;gt;{ProviderManager}] --&amp;gt; authenticate() --&amp;gt; [&amp;lt;AuthenticationProvider&amp;gt;{DaoAuthenticationProvider}] --&amp;gt; loadUserByUsername() --&amp;gt;[&amp;lt;UserDetailsService&amp;gt;{InMemoryUserDetailsManager}] --&amp;gt; UserDetails --&amp;gt;  [&amp;lt;AuthenticationProvider&amp;gt;{DaoAuthenticationProvider}] --&amp;gt; Authentication --&amp;gt; [&amp;lt;AuthenticationManager&amp;gt;{ProviderManager}] --&amp;gt; Authentication --&amp;gt; [&amp;lt;Authentication&amp;gt;{UsernamePasswordAuthenticationToken} --&amp;gt; Authentication --&amp;gt; [&amp;lt;Authentication Filters&amp;gt; {AuthorizationFilter, DefaultLoginPageGeneratingFilter, UsernamePasswordAuthenticationFilter}]  --&amp;gt; Response&lt;/p&gt;

</description>
      <category>springsecurity</category>
      <category>java</category>
      <category>backend</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Intro to GITHUB ACTIONS</title>
      <dc:creator>Coach Beard Jr</dc:creator>
      <pubDate>Wed, 25 Oct 2023 17:54:01 +0000</pubDate>
      <link>https://dev.to/vijay2249/intro-to-github-actions-2ce</link>
      <guid>https://dev.to/vijay2249/intro-to-github-actions-2ce</guid>
      <description>&lt;p&gt;Contents covered:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;jobs --  what are jobs in github workflow&lt;/li&gt;
&lt;li&gt;runs-on -- what is this keyword mean&lt;/li&gt;
&lt;li&gt;steps -- what are steps in github actions&lt;/li&gt;
&lt;li&gt;Environment Variables -- what are env values, and how to use and reuse them

&lt;ol&gt;
&lt;li&gt;Defining environment variables for a single workflow&lt;/li&gt;
&lt;li&gt;Defining configuration variables for multiple workflows&lt;/li&gt;
&lt;li&gt;Writing values into GITHUB_ENV&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;JOBS_OUTPUT -- using one job output by another job&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;You can create a workflow file configured to run on specific events &lt;/p&gt;

&lt;p&gt;Official Docs -&amp;gt;  &lt;a href="https://help.github.com/en/articles/configuring-a-workflow"&gt;Configuring a workflow&lt;/a&gt; and &lt;a href="https://help.github.com/en/articles/workflow-syntax-for-github-actions"&gt;Workflow syntax for GitHub Actions&lt;/a&gt; and  &lt;a href="https://help.github.com/en/articles/about-github-actions#core-concepts-for-github-actions"&gt;GitHub Actions&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Assuming you know the basics of actions like what are they I am continuing the explanation&lt;/p&gt;




&lt;p&gt;Now the basic thing is that the actions must include &lt;strong&gt;jobs&lt;/strong&gt; keyword and its actions &lt;/p&gt;

&lt;h3&gt;
  
  
  jobs
&lt;/h3&gt;

&lt;p&gt;A &lt;code&gt;job&lt;/code&gt; is defined task made up of &lt;code&gt;steps&lt;/code&gt;. Each job is run in a fresh instance of virtual environment.&lt;/p&gt;

&lt;p&gt;You can define the dependency rules for how jobs run in a workflow file. Jobs can run at the same time in parallel to be dependent on the status of a previous job and run sequentially&lt;/p&gt;

&lt;p&gt;Example case:&lt;br&gt;
    Workflow can have two sequential jobs that build and test code, where the test job is dependent on the status of the build job. If the build job fails, then test job will not run&lt;/p&gt;


&lt;h3&gt;
  
  
  runs-on
&lt;/h3&gt;

&lt;p&gt;Github hosts virtual machine to run these jobs as mentioned above, we can mention which OS to run these jobs on&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;First-job&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;windows'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ubuntu'&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;second-job&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ubuntu'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All the mentioned jobs execute in the same instance of the virtual environment by default but you can change it, allowing the actions in that job to share information using the file system&lt;/p&gt;




&lt;h3&gt;
  
  
  steps
&lt;/h3&gt;

&lt;p&gt;A step is a set of tasks performed by a job.&lt;br&gt;
Each step in a job executes in the save environment, allowing the actions in that job to share information using the filesystem if necessary.&lt;/p&gt;

&lt;p&gt;These steps can run system commands or actions that user require&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;start-action&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Add&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Steps&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;in&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;workflow"&lt;/span&gt;
        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;MOM"&lt;/span&gt;
              &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo "Hello MOM"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Environment Variables
&lt;/h2&gt;

&lt;p&gt;Now some command or actions might require some env variables that we cannot hardcode these values in our code, they might be some username passwords or api keys etc.&lt;/p&gt;

&lt;p&gt;You can set a custom variables in two ways&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To define an environment variable for use in a single workflow, you can use the &lt;code&gt;env&lt;/code&gt; key in the workflow file.&lt;/li&gt;
&lt;li&gt;To define a configuration variable across multiple workflows, you can define it at the organization, repository, or environment level.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now how can we mention them in our actions file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;env-example&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Env&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;vals&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;example"&lt;/span&gt;
        &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ubuntu'&lt;/span&gt;
        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;MOM"&lt;/span&gt;
              &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;hello&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;$WHO"&lt;/span&gt;
              &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
               &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;WHO&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;MOM&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now github by default gives access to some environment variables which depends on github user and varies from user to user&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;github-env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="s"&gt;name:"Github ENV example"&lt;/span&gt;
        &lt;span class="s"&gt;runs-on&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ubuntu'&lt;/span&gt;
        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Hello MOM&lt;/span&gt;
              &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;$GITHUB_ACTOR"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The complete list of github env variables that github provides by default are here &lt;a href="https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables"&gt;default-environment-variables&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Defining environment variables for a single workflow
&lt;/h3&gt;

&lt;p&gt;To set a custom env variable for a single workflow, you can define it using the &lt;code&gt;env&lt;/code&gt; key in the workflow file&lt;/p&gt;

&lt;p&gt;The scope of custom variable is set by this method is limited to the element in which it is defined.&lt;/p&gt;

&lt;p&gt;You can define variables that are scoped&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the entire workflow, by using &lt;code&gt;env&lt;/code&gt; at the top level of the workflow&lt;/li&gt;
&lt;li&gt;the contents of a job within a workflow, by defining the key value pair inside a job&lt;/li&gt;
&lt;li&gt;a specific step within a job, by defining that key value pair inside that particular step
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;This is env variable example defining in workflow&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="s"&gt;workflow_dispatch&lt;/span&gt;
&lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;BOSS&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;MOM"&lt;/span&gt; &lt;span class="err"&gt;%%&lt;/span&gt; &lt;span class="s"&gt;this env is avaiable for all the jobs/steps in the workflow %%&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;greeting_job&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;Greeting&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Good"&lt;/span&gt; &lt;span class="err"&gt;%%&lt;/span&gt; &lt;span class="s"&gt;this env is available to all steps within this job %%&lt;/span&gt;
        &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;wishes&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;to&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;MOM"&lt;/span&gt;
              &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo "$Greeting $BOSS, have a great $DAY"&lt;/span&gt;
              &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                  &lt;span class="na"&gt;DAY&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Friday"&lt;/span&gt; &lt;span class="err"&gt;%%&lt;/span&gt; &lt;span class="s"&gt;this env value is available to only this step %%&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The commands in the &lt;code&gt;run&lt;/code&gt; steps of a workflow, or referenced actions, are processed by the shell you are using on the runner. The instructions in the other parts of a workflow are processed by Github Actions and are not sent to the runner.&lt;/p&gt;

&lt;p&gt;Because runner environment variable interpolation is done after a workflow job is sent to a runner machine, you must use the appropriate syntax for the shell that's used on the runner.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
    when you use &lt;code&gt;ubuntu&lt;/code&gt; these use bash shell, so you must use the syntax &lt;code&gt;$KEY&lt;/code&gt; , and for windows env use PowerShell, so you would use the syntax &lt;code&gt;$env:KEY&lt;/code&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Now you cant just name these env variables as you want, there are some default env variables that github gives you to use them and you cant name your env keys to be these names&lt;/li&gt;
&lt;li&gt;Example in the above code snipper where we used, GITHUB_ACTOR as env value into run command directly you can't create env value with key as GITHUB_ACTOR&lt;/li&gt;
&lt;li&gt;If you try to override the value of one of these default variables, the assignment is ignored by github runners&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;


&lt;h3&gt;
  
  
  Defining configuration variables for multiple workflows
&lt;/h3&gt;

&lt;p&gt;You can create configuration variables for use across multiple workflows, and can define them at either the organization, repository or environment level&lt;/p&gt;

&lt;p&gt;Example, you can use configuration variables to set default values for parameters passed to build tools at an organization level, but then allow repository owners to override these parameters on case-by-case basis&lt;/p&gt;

&lt;p&gt;When you define configuration variables, they are automatically available in the &lt;code&gt;vars&lt;/code&gt; context, &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If a configuration variable has not been set, the return value of a context referencing the variable will be empty string&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;var usage example workflow&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;workflow_dispatch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# Setting an environment variable with the value of a configuration variable&lt;/span&gt;
  &lt;span class="na"&gt;env_var&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.ENV_CONTEXT_VAR }}&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;display-variables&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.JOB_NAME }}&lt;/span&gt;
    &lt;span class="c1"&gt;# You can use configuration variables with the `vars` context for dynamic jobs&lt;/span&gt;
    &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.USE_VARIABLES == 'true' }}&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.RUNNER }}&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.ENVIRONMENT_STAGE }}&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Use variables&lt;/span&gt;
      &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
        &lt;span class="s"&gt;echo "repository variable : $REPOSITORY_VAR"&lt;/span&gt;
        &lt;span class="s"&gt;echo "organization variable : $ORGANIZATION_VAR"&lt;/span&gt;
        &lt;span class="s"&gt;echo "overridden variable : $OVERRIDE_VAR"&lt;/span&gt;
        &lt;span class="s"&gt;echo "variable from shell environment : $env_var"&lt;/span&gt;
      &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;REPOSITORY_VAR&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.REPOSITORY_VAR }}&lt;/span&gt;
        &lt;span class="na"&gt;ORGANIZATION_VAR&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.ORGANIZATION_VAR }}&lt;/span&gt;
        &lt;span class="na"&gt;OVERRIDE_VAR&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.OVERRIDE_VAR }}&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.HELLO_WORLD_STEP }}&lt;/span&gt;
      &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.HELLO_WORLD_ENABLED == 'true' }}&lt;/span&gt;
      &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/hello-world-javascript-action@main&lt;/span&gt;
      &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;who-to-greet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.GREET_NAME }}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The if conditionals are processed by Github Actions and only the steps where the check resolves as true are sent to the runner. &lt;/p&gt;




&lt;h3&gt;
  
  
  Writing values into GITHUB_ENV
&lt;/h3&gt;

&lt;p&gt;If you generate a value in one step of a job, you can use the value in subsequent steps of the same job by assigning the value to an existing or new environment variable and then writing this to the &lt;code&gt;GITHUB_ENV&lt;/code&gt; environment file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"{environment_variable_name}={value}"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$GITHUB_ENV&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Set the value&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;step_one&lt;/span&gt;
    &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
      &lt;span class="s"&gt;echo "action_state=yellow" &amp;gt;&amp;gt; "$GITHUB_ENV"&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Use the value&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;step_two&lt;/span&gt;
    &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
      &lt;span class="s"&gt;printf '%s\n' "$action_state" # This will output 'yellow'&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The environment file can be used directly by an action, or from a shell command in the workflow file by using the &lt;code&gt;run&lt;/code&gt; keyword.&lt;/p&gt;

&lt;h2&gt;
  
  
  JOBS_OUTPUT
&lt;/h2&gt;

&lt;p&gt;If you want to pass a value from a step in one job in a workflow to a step in another job in the workflow, you can define the value as a job output&lt;br&gt;
Then you can then reference this job output from a step in another job&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;job1&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="c1"&gt;# Map a step output to a job output&lt;/span&gt;
    &lt;span class="na"&gt;outputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;output1&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ steps.step1.outputs.test }}&lt;/span&gt;
      &lt;span class="na"&gt;output2&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ steps.step2.outputs.test }}&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;step1&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo "test=hello" &amp;gt;&amp;gt; "$GITHUB_OUTPUT"&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;step2&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo "test=world" &amp;gt;&amp;gt; "$GITHUB_OUTPUT"&lt;/span&gt;
  &lt;span class="na"&gt;job2&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;job1&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;OUTPUT1&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{needs.job1.outputs.output1}}&lt;/span&gt;
          &lt;span class="na"&gt;OUTPUT2&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{needs.job1.outputs.output2}}&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo "$OUTPUT1 $OUTPUT2"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These outputs are "UNICODE" string, and can be a maximum of 1MB. The total of all outputs in a workflow can be a max of 50MB&lt;/p&gt;

&lt;p&gt;Jobs outputs containing expressions are evaluated on the runner at the end of each job. Outputs containing secrets are redacted on the runner and not sent to the github actions&lt;/p&gt;




&lt;p&gt;Lets continue this &lt;em&gt;Discussion on GitHub Actions&lt;/em&gt;, with examples whenever necessary in upcoming explanation notes.&lt;/p&gt;

</description>
      <category>githubactions</category>
      <category>automation</category>
      <category>devops</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Testing with auto push and publishing</title>
      <dc:creator>Coach Beard Jr</dc:creator>
      <pubDate>Tue, 24 Oct 2023 17:45:31 +0000</pubDate>
      <link>https://dev.to/vijay2249/testing-with-auto-push-and-publishing-55mc</link>
      <guid>https://dev.to/vijay2249/testing-with-auto-push-and-publishing-55mc</guid>
      <description>&lt;p&gt;this is paragraph&lt;/p&gt; &lt;em&gt;this is italics&lt;/em&gt;&lt;br&gt; All the above is written in body_markdown property&lt;span&gt;also note that main_image property is added. &lt;a href="https://wallpaperaccess.com/full/1264330.jpg"&gt;&lt;/a&gt;&lt;a href="https://wallpaperaccess.com/full/1264330.jpg"&gt;https://wallpaperaccess.com/full/1264330.jpg&lt;/a&gt; this as value to property&lt;br&gt;
&lt;/span&gt;

</description>
    </item>
    <item>
      <title>GRUB. what is it?</title>
      <dc:creator>Coach Beard Jr</dc:creator>
      <pubDate>Tue, 24 Oct 2023 07:31:26 +0000</pubDate>
      <link>https://dev.to/vijay2249/grub-what-is-it-448p</link>
      <guid>https://dev.to/vijay2249/grub-what-is-it-448p</guid>
      <description>&lt;p&gt;&lt;em&gt;Intro&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A boot loader is one of the most important components of Linux operating systems boot process.&lt;br&gt;
When a device starts up, working memory must be loaded with operating system data. The so-called bootloader, usually referred to as a boot program or bootstrap loader, enables this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Grand Unified Bootloader(GRUB)
&lt;/h2&gt;

&lt;p&gt;The boot process on Linux is a series of activities that occur from the time you press the power on button on your PC until the login screen appears&lt;/p&gt;

&lt;p&gt;Stages of boot process&lt;/p&gt;

&lt;p&gt;There are four main stages in the boot process&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;BIOS

&lt;ol&gt;
&lt;li&gt;mainly responsible for loading the bootloader&lt;/li&gt;
&lt;li&gt;When the computer starts, it runs a Power On Self Test(POST) to make sure that the core hardware such as memory and hard disk is working properly&lt;/li&gt;
&lt;li&gt;Afterwards, the BIOS will check the primary hard drives Master Boot Record(MBR), which is a section on your hard drive where the bootloader is located&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;Bootloader

&lt;ol&gt;
&lt;li&gt;Loads the kernel into RAM with a set of kernel parameters&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;Kernel

&lt;ol&gt;
&lt;li&gt;The kernel primary function is to initialize devices and memory&lt;/li&gt;
&lt;li&gt;Afterwards it loads the init process&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;Init

&lt;ol&gt;
&lt;li&gt;Responsible for starting and stopping essential services on your system
GRUB is mainly responsible for providing you with an options menu from which you can select the operating system or environment that you want to boot into&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;GRUB is not only limited to booting into Linux operating system, you can also use it to boot into other operating systems such as windows&lt;/p&gt;

&lt;p&gt;The Role of GRUB&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Once you select the operating system to boot into, GRUB will load the selected kernel&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;GRUB uses kernel parameters to know where the kernel is located and other important parameters to use&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;initrd
    1. used for specifying the initial RAM disk

&lt;ol&gt;
&lt;li&gt;BOOT_IMAGE

&lt;ol&gt;
&lt;li&gt;the location of the linux kernel image&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;root

&lt;ol&gt;
&lt;li&gt;specifies the location of root file system, used by the kernel to find init which in turn loads the critical services&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;ro

&lt;ol&gt;
&lt;li&gt;responsible for mounting the file system in read-only mode&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;quiet

&lt;ol&gt;
&lt;li&gt;hides some system specific messages as your PC is booting&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;splash

&lt;ol&gt;
&lt;li&gt;used for displaying the splash screen when your system is booting&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;When you are in the GRUB options menu, you can edit kernel parameters by pressing the “E” key&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;GRUB 2 gives you a lot of flexibility and power when it comes to configuring your bootloader&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The /boot/grub directory contains a file named “grub.cfg” which is the main configuration file for GRUB&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;However, it is advised not to edit the grub.cfg file directly, instead you should edit the “/etc/default/grub” file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When you make changes to the “/etc/default/grub” file, you should make sure to run the command below, so that your changes are written to the grub.cfg file automatically&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;sudo update-grub&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Test</title>
      <dc:creator>Coach Beard Jr</dc:creator>
      <pubDate>Sun, 08 Oct 2023 07:01:10 +0000</pubDate>
      <link>https://dev.to/vijay2249/test-30l</link>
      <guid>https://dev.to/vijay2249/test-30l</guid>
      <description>&lt;p&gt;A Test Post&lt;/p&gt;

</description>
      <category>test</category>
    </item>
  </channel>
</rss>
