tag:blogger.com,1999:blog-60734607603403895712024-03-12T19:33:22.379-05:00DataGenX - Atul's NotesMy scrapbook about almost anything I stumble upon in my tech world. If you find anything useful don't forget to give thumbs-up :) Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.comBlogger365125tag:blogger.com,1999:blog-6073460760340389571.post-11078231356311504192024-02-08T19:56:00.006-05:002024-02-08T19:58:27.119-05:00Sign your Github Commit with GPG or SSH KeyGPG Key is your identity in digital world as there are very rare chances (almost nil) for regeneration of same GPG keys twice, hence you must safe keep your GPG keys as malicious personnel can use this key (if stolen) to represent you. Github allows you to sign your git commits with your GPG key which is to prove that It was you and only you have made this commit. It's pretty straightforward if you followed below steps -<br /><a href="https://www.datagenx.net/search/label/Git" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="800" data-original-width="1540" height="104" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEge0QBGdLMmqVOUDKDIZ7f-YZo1-Pr7KgP1Ec1jL1AerAbsI1oSDXXqtBCZUvqrMsfZK1QBqM9AaTLVO37moT7k4WNkvQ2DjuFupKwGLySzZOMZIiBVROQYnnEJXpZ0zagQ8FB9hkimTJSEPSFYWMR502s9RUqDMgVq0aGFhh0uwJo3ITqDqn4WCxWECec/w200-h104/git1.png" width="200" /></a><a href="https://www.datagenx.net/2023/12/how-do-we-revoke-gpg-key.html" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="138" data-original-width="163" height="138" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW1leaYhFUFOgvpvgaAjO_R5r_41vpaxZ6G54XBrviWJf5NxMLCU_H8dVhBRwax1vQlFwXwwYYRd_-ayUpzxS1-CPogBCkG_tIwnhyphenhyphenSsOYvB_18BvOptI06Ls1sURm9gYT2HglICNfpSSP7OGWMIX8F_82d9iLszX6hfxgRa_DxMM7T6O8nC75mNFJdu0/s1600/encrypt.png" width="163" /></a>
<h3 style="text-align: left;">Steps:</h3><ul style="text-align: left;"><li>First. Reset if you have GPG key setup for Git, You can skip this step if not. <br /><pre>git config --global --unset gpg.format
</pre></li><li>List your GPG Key/s<br /><pre>gpg --list-secret-keys --keyid-format=long</pre>This will display the output as below - <pre>> gpg --list-secret-keys --keyid-format=long
/home/atul/.gnupg/pubring.kbx
-----------------------------
sec ed25519/DC720CCF9BCEDF17 2023-09-08 [SC] [expires: 2026-12-07]
E4458C3F9BCEDF17CF9BCEDF1728DC720CCF9BCEDF17
uid [ultimate] AtulS (Encrypt n Sign Key for AtulS) <dummy@mail.com>
ssb cv25519/E4458C3F9BCEDF17 2023-09-08 [E] [expires: 2026-12-07]</pre>Your KEY-ID is <i style="font-weight: bold;">DC720CCF9BCEDF17 </i>( line starts from "sec" ) <br /><br /></li><li>Now, Let Git know to use this KEY ID <br /><pre>git config --global user.signingkey DC720CCF9BCEDF17</pre><br /></li><li>Last configure Git to Sign all the commits with this key<br /><pre>git config --global commit.gpgsign true</pre><br />As GPG keys are password protected, Git will ask the GPG key password to sign the commits in each new terminal which is kind of a hassle but this is what it make this more secure. There are some agent tools available which you can use to keep the GPG key open in the terminal, but personally, I will not advise to use those. <br /><br />Below is the screenshot of not-signed and signed git commit - <br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhZ_TAkxmbQ0Xm74vbPAxAJXIEVfFTD6GR88k0CoO73EmqIgZVXsPrF-aApF2UkCQjeEJZciFb-GxXpzdyC3Oq6qsS13NeJ4iOTyUOi7J8rNPi830ltQlOxl50Q5RYVlqCCWgIIhDy78X6xabgUf6YZE-Y3o7m4yI9xvT98w1yo_7sHaoBK3SSowiuKX0Y" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img alt="" data-original-height="302" data-original-width="956" src="https://blogger.googleusercontent.com/img/a/AVvXsEhZ_TAkxmbQ0Xm74vbPAxAJXIEVfFTD6GR88k0CoO73EmqIgZVXsPrF-aApF2UkCQjeEJZciFb-GxXpzdyC3Oq6qsS13NeJ4iOTyUOi7J8rNPi830ltQlOxl50Q5RYVlqCCWgIIhDy78X6xabgUf6YZE-Y3o7m4yI9xvT98w1yo_7sHaoBK3SSowiuKX0Y=s16000" /></a></div><br /><br /><br /><br /><br /> You can use SSH key as well to sign your commits (if don't want to manage one another additional key), All the commands are pretty much same. </li><pre># Unset the existing GPG config
git config --global --unset gpg.format
# Use SSH for GPG signing
git config --global gpg.format ssh
# Config the SSH key which sign the commit
git config --global user.signingkey "$(cat $HOME/.ssh/id_ed25519.pub)"
# Enable the commit signing
git config --global commit.gpgSign true
</pre><span><ul style="text-align: left;"><span><br /></span></ul>Now, you can choose which way you want to go, If you are not using GPG keys at all, use SSH way else you know what to do :-) </span><br /><span> </span><span> </span><br /><b><br /><br />Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b>
<br /><br />
<br /></ul><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-40445992382980218612023-12-06T16:14:00.008-05:002023-12-06T16:22:02.983-05:00How do we revoke GPG Key?In last 2 post, we have learnt about how to <a href="https://buff.ly/3Ssidbe" target="_blank"><b><i>generate GPG key</i></b></a> and <i style="font-weight: bold;"><a href="https://buff.ly/412wnlO" target="_blank">Revocation Certificate</a>, </i>But real question are, how to use Revocation Certificate to revoke the GPG key? If we do, does it really revoke it such that nobody can use the old GPG key? and many more. This post is more around these questions and their answers :-) So let's take a dive - <div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.datagenx.net/search/label/GPG" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="138" data-original-width="163" height="138" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggMTy3TNAiMA5u9W2PST4hv3C1GP96eiBUPvYrb2q59b96KAIb0-KHqc4Ey6D918sn4NJUNR5fAnTr4vfh0wPJ_qzmxsQGituPbyB950oa-p6pd3sN1-Dnp3ieDuVaRhPEdZn3XFpexMo7h7XmYNtlhwQEL6-5X8r8G8LG5Kr-uaPQHUq-U0UvmF56KgA/s1600/encrypt.png" width="163" /></a></div><br /></div>Before we proceed, let's assume few things - <div>a. You have a compromised GPG Key</div><div>b. A Revocation Certificate for the same key </div><div>c. You have published the GPG (Public) Key on KeyServers </div><div><div><br />Revoking a GPG key is a shared step for You as well as Receiver. You are responsible to share/publish the revoke cert which tells the world about the expired/revoked key and Receiver have to import the your revocation certificate to revoke the GPG key which they are using to communicate with you. If any step is miss, the KEY is not actually revoked. </div><div><br /></div><div><b>Steps to Revoke GPG Key - <br /></b><br /><li>The revoke certificate is somewhat like below - <br /><br /></li><pre style="text-align: left;"> This is a revocation certificate for the OpenPGP key:
pub ed25519 2023-03-29 [S]
873D8D13C2XXXXXXXXXXXXXXXXXXX734A6PPF87
uid dummy (this is gpg key) dummy@dummy.com
A revocation certificate is a kind of "kill switch" to publicly
declare that a key shall not anymore be used. It is not possible
to retract such a revocation certificate once it has been published.
Use it to revoke this key in case of a compromise or loss of
the secret key. However, if the secret key is still accessible,
it is better to generate a new revocation certificate and give
a reason for the revocation. For details see the description of
of the gpg command "--generate-revocation" in the GnuPG manual.
To avoid an accidental use of this file, a colon has been inserted
before the 5 dashes below. Remove this colon with a text editor
before importing and publishing this revocation certificate.
:-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: This is a revocation certificate
iHgEIadcIDentaSTWo0TwrM0DnOiGFnpnNc00192jaaJPKQJbQIdAAAKCRDpnNc0
pq10d6OBAPyyyyy4nPDmWxxxxxxxCmaINiTd4SmEYRUHZy7CsuuuAQEA4PVVkCaE
vYgvdadadadaog/OiD0gkaRokaOgoYbewou2=
=5G/c
-----END PGP PUBLIC KEY BLOCK-----</pre><ul style="text-align: left;"><li>As the comment in Revocation cert, It is one way path, once revoked is Revoked. </li><li>Remove the colon (:) as the instruction say and save it</li><li>Import the Revocation Certificate to your KEY Ring<br /><pre><b>gpg --import REVOKE_CERT_FILE_NAME</b></pre></li><li>This will revoke the GPG Key locally</li><li>Send the revoked Key to KeyServers<pre><b>
# Upload Public key on keyserver/s<br />gpg --keyserver hkps://</b><b>keys.openpgp.org </b><b>--send-key KEYID
<b>
# or
gpg --keyserver https://</b><b>keyserver.ubuntu.com </b><b>--send-key KEYID</b>
# or
gpg --keyserver https://pgp.mit.edu --send-key KEYID</b> </pre></li></ul><div><ul style="text-align: left;"><li>Your part is done, <b><i>Next step is for Receiver</i></b>, they have to re-sync the revoked KEY once again to revoke the locally stored GPG KEY, which can be done via - <br /><pre><b># Import from Keyserver
<b>gpg --keyserver https://<b>keys.<b>openpgp</b><b>.com </b></b></b><b>--recv-keys KEYID</b><br />
# or
gpg --keyserver https://<b>keyserver</b></b><b>.</b><b>ubuntu</b><b>.org --recv-keys KEYID <br />
# or </b><br /><b>gpg --keyserver https://pgp.mit.edu --recv-keys KEYID<br /></b></pre> </li><li>You will see below output when you import the revocation certs - </li><br />
<pre>❯ gpg --import ~/.gnupg/openpgp-revocs.d/873D8D13C2XXXXXXXXXXXXXXXXXXX734A6PPF87.rev
gpg: key E99CD734A6PPF87: "dummy (this is gpg key) dummy@dummy.com" revocation certificate imported
gpg: Total number processed: 1
gpg: new key revocations: 1
gpg: marginals needed: 3 completes needed: 1 trust model: pgp
gpg: depth: 0 valid: 3 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 3u
gpg: next trustdb check due at 2024-09-05
</pre><li>and this one when you list the same KEYID<br /><pre>❯ gpg --list-keys 873D8D13C2XXXXXXXXXXXXXXXXXXX734A6PPF87
pub ed25519 2023-03-29 [SC] [revoked: 2023-03-29]
873D8D13C2XXXXXXXXXXXXXXXXXXX734A6PPF87
uid [ revoked] dummy (this is gpg key) dummy@dummy.com</pre></li></ul></div><div><span style="font-family: Georgia, Times New Roman, serif;"><b><i><br /></i></b></span></div><div><span style="font-family: Georgia, Times New Roman, serif;"><b><i>Keep in mind that the GPG key that has been sent to the key server cannot be deleted, It will still be listed indefinitely. You only can revoke your public key and notify other users that this key is no longer useful so that they can re-sync your key from the KEYServers.</i></b></span></div><div><span style="font-family: Georgia, Times New Roman, serif;"><b><i><br /></i></b></span></div><div class="MsoFootnoteText"></div>
</div><div><span style="font-family: Georgia, Times New Roman, serif;"><b><br /></b></span></div><div><span style="font-family: Georgia, Times New Roman, serif;"><b><br /></b></span></div><div><span style="font-family: Georgia, Times New Roman, serif;"><b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b></span>
</div></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-79952076528048813272023-11-30T13:51:00.003-05:002023-11-30T13:51:57.774-05:00Generate Revocation Certificate for GPG Key<a href="https://buff.ly/3Ssidbe" target="_blank">In the last post,</a> We learnt about GPG Key, How to generate and publish the key for the world. The next step is to Generate the Revocation Certificate for your GPG key. Revocation certificate will allow you to make public announcement (kind of) that you are discontinuing this (compromised) key. <div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.datagenx.net/search/label/GPG" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="380" data-original-width="728" height="167" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjict4LAozf_yAVZ_M1cXqhr9WnL748z4AiNTiDxW-vuwDDvo0FTM1yQJsQfD4dgmSLksrFd8uMZIMT85xni6d6_YCfkPr2nDlUIvwHpPMvJ2csq2jBj6oEgZRUQem8kJBL94gVaCEK8iEaLfcTfa0ktiU9pPoXpG8OX6qzLiYmFFU5ileLcy_IXfrwSJ0/s320/security.png" width="320" /></a></div><span> Why you ask? Because, If the key is (1) compromised and bad actor use that compromised key to be you (stole your identity) can be avoided or (2) you have forgotten the password of your existing GPG key and want to use another GPG key from now on. </span><br /><br />If you have used the latest GPG CLI to generate the GPG key, by default, it will generate the revocation certificate which can be found in <b>$HOME/.gnupg/openpgp-revocs.d/ (Linux), </b>Location can be different in different OSs. <br />
<br />If you do not find the Revocation certificate, No worry, <i style="font-weight: bold;">You can regenerate it IF and ONLY IF you remember the GPG key password. </i>To generate you can run below command - </div><div><br /></div><div><pre>gpg --output KEYID-revoke-cert.asc --gen-revoke KEYID<br /></pre>
<div>Replace KEYID with your GPG KeyID, The CLI prompt will ask the GPG key password to generate the revocation certificate, Once generated, Keep this certificate safe for future use in case of compromised key. Because, <b><i>The Revocation Certificate generation process prompt the GPG key password, It is a Good practice to generate it as soon as you generate the GPG key. </i></b></div><div><br /></div><div><br /></div>
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b></span><script>
var a=document.createElement('a');
a.href='https://www.buymeacoffee.com/datagenx';
var image = document.getElementById('mydiv').getElementsByTagName('img')[0];
b=a.appendChild(image);
document.getElementById('mydiv').appendChild(a);
block.setAttribute("style", "text-align:center");
</script></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-40281328461891193142023-11-05T13:43:00.004-05:002023-11-30T13:53:18.693-05:00Intro to GnuPG (GPG) - Generating KeysGnuPG aka GPG is widely use in IT word to secure communication, data encryption, digital signature and many more. It is always a first choice of security personnel to make use of GPG as it is little hard to break (considering today's computational power). GPG make use of many cryptography concept which includes<span style="background-color: white;"> </span><i class="FIRSTTERM" data-darkreader-inline-bgcolor="" style="--darkreader-inline-bgcolor: #0c0e0e;"><span style="background-color: white;">symmetric ciphers</span></i><span style="background-color: white;"><div class="separator" style="clear: both; text-align: center;"><a href="https://www.datagenx.net/search/label/GPG" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="380" data-original-width="728" height="167" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYN_W0rPslnX1exO3bSPrraZ-WFyQUUY0PBQ4NcZ4TyyGcagO9rSKCA30gNpXSR65P0rFeTs18552KpJaPPV8vvCqnRdGBIuvO1KYJ7bsBY5GzsQXzNEJKXzWnpOYc_eHZmX805DaNEdTcGeJbuGbXqGZZyGaTczo5BF_0DIb6VNC-2yS6R1kdjpdizcM/s320/security.png" width="320" /></a></div><span data-darkreader-inline-bgcolor="" style="--darkreader-inline-bgcolor: #0c0e0e;">, </span><i class="FIRSTTERM" data-darkreader-inline-bgcolor="" style="--darkreader-inline-bgcolor: #0c0e0e;">public-key ciphers</i><span data-darkreader-inline-bgcolor="" style="--darkreader-inline-bgcolor: #0c0e0e;">, and </span><i class="FIRSTTERM" data-darkreader-inline-bgcolor="" style="--darkreader-inline-bgcolor: #0c0e0e;">one-way hashing.</i><i class="FIRSTTERM" data-darkreader-inline-bgcolor="" style="--darkreader-inline-bgcolor: #0c0e0e;"> </i>In this p</span>ost, we are only going to focus to create/generate GPG key. <div><br /></div><div> Very first thing you need is the command line tool to generate the keys which you can <a href="https://www.gnupg.org/download/" rel="nofollow" target="_blank"><b><i>download from here</i></b></a> for your operating system. I advise you to use the latest version whenever possible. <br /></div><div><br /></div><h3 style="text-align: left;">How to generate GPG keys:</h3><div><ul style="text-align: left;"><li>Open terminal</li><li>Considering you are using the latest version of GPG command line, run the below command to generate the GPG key (Keep in mind, it is going to ask multiple questions, answer them truthfully as much as possible) - <br /><pre><b>gpg --full-generate-key</b></pre></li><ul><li>Now, very first thing is the Algorithm to generate the GPG key, if you are generating it first time, press Enter to choose the default but if you are generating for any application, choose the algorithm which is supported by your application encryption/decryption logic. </li><li>Based on the algorithm selected, it might ask for the key length, provide the maximum length for better security unless you have some specific requirement to fill. </li><li>Next, To select the validity period, I advise to input "1y" for 1 year but remember you have to rotate the key when it get expire. If this seems like a hassle, choose default by pressing Enter for "No Expiration"<br /></li><li>Verify, all your selections are correct</li><li>Provide your Name, Email ID and Description about key usage</li><li><i style="font-weight: bold;">Most Important - </i>Provide a passphrase for key security, longer the better but <b>DO NOT </b>forget the passphrase, If you forget it, there is NO WAY you can recover, So choose, Wisely</li><li>If all information is accurate, provide input to generate the key. </li><li>(Optional) For better entropy generation, keep moving your mouse when system is trying to generate the key. </li></ul><li>Your GPG key is generated and stored in your home directory (<b><i>~/.gnupg/pubring.kbx</i></b>). </li><li>To list all your GPG keys, you can run below command - <br /></li><pre><b>gpg --list-keys --keyid-format=long</b></pre><div><li><b>gpg</b> command will generated 3 things - Private and Public gpg key and Revocation certificate. Revocation certificate is required when you want to revoke your key if compromised, it is just to tell the world that this key is not valid anymore. <b>Remember, </b>This will only mark your key invalid, it will not block the bad actor to encrypt/decrypt the message with stolen key of yours. So It is a good idea to revoke your key when compromised that way all other user will be aware if someone trying to be you with your compromised key. </li><li>Though, <b>gpg </b>command will generate the revocation key but in case it is not generated, you can generate the certificate via below command - </li><pre><b>gpg --gen-revoke KEYID > KEYID.revoke.asc</b></pre></div><li>So, next, let's export the keys for safekeeping - <pre><b># Export Public Key
gpg --armor --export KEYID > KEYID.pub
# Export Secret Key
<b>gpg --armor --export-secret-keys KEYID > KEYID.key</b><br />
</b></pre></li><li>Upload Your Public key on KeyServers to let world know about your key - <br /><pre><b>
# Upload Public key on keyserver/s<br />gpg --keyserver hkps://</b><b>keys.openpgp.org </b><b>--send-key KEYID
<b>
# or
gpg --keyserver https://</b><b>keyserver.ubuntu.com </b><b>--send-key KEYID</b>
# or
gpg --keyserver https://pgp.mit.edu --send-key KEYID</b>
</pre></li><li>Search Public Keys - <pre><b># Search Keys<br />gpg --keyserver hkps://keys.<b>openpgp</b><b>.com --search KEYID</b><br />
# or
gpg --keyserver https://<b><b>keyserver</b></b><b>.<b><b>ubuntu</b></b><b><b>.org --search KEYID</b></b><br /></b>
# or
gpg --keyserver https://pgp.mit.edu --search KEYID</b>
</pre></li><li> Import Public Keys - <pre><b style="font-weight: bold;"># Import Keys from file<br />gpg --import PUBLIC-KEY-FILE<br />
# Import from Keyserver
<b>gpg --keyserver https://<b>keys.<b>openpgp</b><b>.com </b></b></b><b>--recv-keys KEYID</b><br />
# or
gpg --keyserver https://<b>keyserver</b></b><b>.</b><b style="font-weight: bold;"><b>ubuntu</b></b><b>.org --recv-keys KEYID <br />
# or
gpg --keyserver https://pgp.mit.edu --recv-keys KEYID
</b></pre></li><li>List keys (public) in your keyring via below command - <pre><b># List Public Keys in local keyring
gpg --list-keys
</b> </pre></li><li>List Secret keys (private) in your keyring via below command <pre><b># List Secret Keys in local keyring
gpg --list-secret-keys</b></pre></li></ul><div><span style="font-family: Georgia, Times New Roman, serif;"><b><br /></b></span></div><div><span style="font-family: Georgia, Times New Roman, serif;">In next post, We will learn <a href="https://buff.ly/412wnlO" target="_blank">about Revocation Certificate.</a> </span></div><div><span style="font-family: Georgia, Times New Roman, serif;"><b><br /></b></span></div><div><span style="font-family: Georgia, Times New Roman, serif;"><b>Video:<br /><script async="" id="asciicast-SVFbOh6J9UdQTPGOXdMAvzU6H" src="https://asciinema.org/a/SVFbOh6J9UdQTPGOXdMAvzU6H.js"></script></b></span></div><div><span style="font-family: Georgia, Times New Roman, serif;"><b><br /></b></span></div><div><br /></div><div><span style="font-family: Georgia, Times New Roman, serif;"><b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b></span>
</div></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-50346220163437947242023-09-18T23:04:00.002-05:002023-09-18T23:04:57.666-05:00Securing the SSH Keys<p style="text-align: left;"></p><p style="text-align: left;"></p><div class="separator" style="clear: both; text-align: center;"><a href="https://www.datagenx.net/search/label/Shell" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="156" data-original-width="323" height="155" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqSIp8DBt3PYrCn0ZKfz4Ej2WUPH2WiKtiN6sDISpwK1zQxpo-BInv6Be8IrBgYafSn8Bvj8Qfhds83QYNivpZBX9VqA0oHm7EprbnCZ-_S45BC_iwCoT_lXr_pS_NFdkbjLiGcVw8vx4h6V0vpTrXMu_cihRT8dd9_7w13-AgozgTu_7ufcd79nCFHP8/s320/linux3.jpg" width="320" /></a></div><b>SSH</b> or <b>S</b>ecure <b>SH</b>ell keys are access credentials to anything, any task which support secure tunnel to perform some operations where it can be managing network, operating systems, configurations or to perform secure file transfer. Day to day a typical user use SSH keys to access Source Management System (Git, Bitbucket..etc) or to do Password-less login to remote server. Keeping these keys secure is as much as critical as your username and password and sadly, we as a user don't do a good job in that zone. <p style="text-align: left;"></p><p style="text-align: left;"><span> </span>Technically SSH keys are cryptography keys which creates a secure session between local and remote system, they grant access and control who can do and what. Let's see how to make sure our SSH keys are more secure ( as nothing is 100% secure ) than usual. </p><h3 style="text-align: left;">Use <span class="hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text" data-hs-cos-general-type="meta_field" data-hs-cos-type="rich_text" id="hs_cos_wrapper_post_body"><b>ECDSA or ED25519</b> algorithm rather than <b>RSA</b> algorithm to generate key:</span></h3><p style="text-align: left;"><span class="hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text" data-hs-cos-general-type="meta_field" data-hs-cos-type="rich_text" id="hs_cos_wrapper_post_body"><span> </span>This doesn't mean that RSA keys are not secure but It can be comparatively easily broken with current computer processing power than ECDSA/ED25519 keys. </span></p><h3 style="text-align: left;"><span class="hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text" data-hs-cos-general-type="meta_field" data-hs-cos-type="rich_text" id="hs_cos_wrapper_post_body">Use Bigger bit size Keys:</span></h3><div style="text-align: left;"><p style="text-align: left;"><span class="hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text" data-hs-cos-general-type="meta_field" data-hs-cos-type="rich_text" id="hs_cos_wrapper_post_body"><span> </span>Higher the Key bit size, more time it will take to break, so always choose bigger bit size when generating the Keys. 4096 if using RSA or ED25519 algorithm and 512 if using ECDSA algorithm.<br /></span></p><h3 style="text-align: left;"><span class="hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text" data-hs-cos-general-type="meta_field" data-hs-cos-type="rich_text" id="hs_cos_wrapper_post_body">Always Use Passphrase:<br /></span></h3><p style="text-align: left;"><span class="hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text" data-hs-cos-general-type="meta_field" data-hs-cos-type="rich_text" id="hs_cos_wrapper_post_body"><span> </span>One of the biggest mistake, Not to have strong passphrase for our Keys, usually we being lazy do not set any passphrase for our SSH keys which means if any one got access on our keys, they can access whatever system we are accessing with these keys. So keep some passphrase, If not Strong than Simple, but it is still better than not having any passphrase. </span></p><h3 style="text-align: left;"><span class="hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text" data-hs-cos-general-type="meta_field" data-hs-cos-type="rich_text" id="hs_cos_wrapper_post_body">User permission of SSH Keys: </span></h3><div style="text-align: left;"><span class="hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text" data-hs-cos-general-type="meta_field" data-hs-cos-type="rich_text" id="hs_cos_wrapper_post_body"><span> Securing file permission of SSH keys are also important, your SSH keys should not be accessed by other users on the system/server/machine. Your ".ssh" directory and private key permission should be only to you (user), not to "user group" and others. </span></span></div><div style="text-align: left;"><span class="hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text" data-hs-cos-general-type="meta_field" data-hs-cos-type="rich_text" id="hs_cos_wrapper_post_body"><span><br /></span></span></div><div style="text-align: left;"><span class="hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text" data-hs-cos-general-type="meta_field" data-hs-cos-type="rich_text" id="hs_cos_wrapper_post_body"><span>Based on above points, Let's generate the SSH Key (provided the passphrase when prompt) - <br /></span></span></div></div><h3 style="text-align: left;"><span class="hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text" data-hs-cos-general-type="meta_field" data-hs-cos-type="rich_text" id="hs_cos_wrapper_post_body"></span></h3><p style="text-align: left;"></p><pre class="code">ssh-keygen -b 521 -t ecdsa -C "your-email@host.com" -f ~/.ssh/id_ecdsa_test <br />chmod 700 ~/.ssh<br />chmod 600 ~/.ssh/id_ecdsa_test</pre><p></p><p style="text-align: left;">
<br />
</p><div class="MsoFootnoteText" style="text-align: left;"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b></span>
<script>
var a=document.createElement('a');
a.href='https://www.buymeacoffee.com/datagenx';
var image = document.getElementById('mydiv').getElementsByTagName('img')[0];
b=a.appendChild(image);
document.getElementById('mydiv').appendChild(a);
block.setAttribute("style", "text-align:center");
</script><br /><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-68673891170530283562023-09-15T11:09:00.008-05:002023-09-15T11:40:52.266-05:00Let's Sign your Git Commit with your SSH keyI was fascinated when I see any git repo where commits shows with "<a href="https://github.com/atulsingh0/oh-my-aliases/commit/4c683fa4e475109a31750d44bcf5b237bcd32326" target="_blank"></a><a href="https://github.com/atulsingh0/oh-my-aliases" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="383" data-original-width="938" height="131" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaMic9-7Pflu6jbc-BuE4M18T1-eonugD2N7MiNzSUWjnx-_4ly7mpQwuF7I8KPyyWnXr4-US8rgTCc3YmDULImTx6R1qD9IHL7rB0IC5sqvD6QxwtLB3XbipoUng5BGH9wgVYo2LFKXu4OmBvoEHbxCi873BZxE9f5Sbc_D6bU-pja8uRBBmn9RNw6nc/s320/image.png" width="320" /></a>Verified" status and curious how and why we need that tiny green "verified" status and idea is pretty straight forwards which to give other people confidence about the origin of a change you have made. If a commit or tag has a GPG, SSH, or S/MIME signature that is cryptographically verifiable, GitHub marks the commit or tag "Verified" or "Partially verified". <div><span> </span></div><div><span> </span>As mentioned, We can also have a verified status on our commits if configured git with GPG, SSH or S/MIME key but it does not make any sense to maintain a GPG key only for commit status. GPG Key maintenance can become a rabbit hole sometime so if you are not using it for Signing or Encryption, don't use it for git commit sign as well. </div><div><br /></div><div>Github Supports SSH key signing and the configuration is also pretty simple, we will go through the steps to achieve the same - <br /><br /><ol style="text-align: left;"><li>Generate the SSH Key Or You can use the any existing key as well.<br /> <pre class="code">ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/id_ed25519_github</pre>It's always a good idea to provide a passphrase to your SSH key but if you are not providing that is also fine. </li><li>Add your SSH key to Agent. <br /><pre class="code" >eval "$(ssh-agent -s)"<br />ssh-add ~/.ssh/id_ed25519_github</pre><br /></li><li>Add Key to Github, Go to <a href="https://github.com/settings/ssh/new" target="_blank">github --> settings --> --> keys --> new</a> , Give a Title name, Key Type will be "Signing Key" and in the Key, paste your public key content (~/.ssh/id_ed25519_github.pub )<br /><br /></li><li>Generate the Signer File<br /><pre class="code" >awk '{ print $3 " " $1 " " $2 }' $HOME/.ssh/id_ed25519_github.pub >> $HOME/.ssh/allowed_signers</pre></li><li>Next, set these git configs (You can remove --global if not want the config for all the git repo)<br /><br /><pre class="code">git config --global user.name <your_githhub_username><br />git config --global user.email "<your_email_id>"<br />git config --global user.signingkey "$(cat $HOME/.ssh/id_ed25519_github.pub)"<br />git config --global gpg.ssh.allowedSignersFile $HOME/.ssh/allowed_signers<br />git config --global gpg.format ssh<br />git config --global commit.gpgSign true<br />git config --global tag.gpgSign true<br />git config --global log.showSignature true</pre><br /></li><li>You are set to sign your commit, make a commit. <br /><pre class="code"> git commi -m "commit msg" </pre></li><li>You can check the sign on commit via below command - <br /><pre class="code">git log --oneline --abbrev-commit -5 --show-signature</pre></li></ol>
There is no problem to use the same key for SSH Auth and Sign or you can use different if want to. You are in control of your key and usage 😁<br />
<br /><br />
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7"></a><div class="separator" style="clear: both; text-align: center;"><a href="http://bit.ly/2rdmcO7"></a></div></b></span><br /></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-34457121895429148762023-09-06T19:56:00.002-05:002023-09-06T19:56:37.707-05:00Let's Record the Shell Terminal<div></div><div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLCkh8ea_HnDhz8HjLC5jUZ1OnoST8KBFo2-m_-w7c1XWxrDPEFagqNhrZCv3EVh5j-tf0slVYB1mS5eFEhAbhevzgZHJ_b-6mEG3xnPE_VZjLP3wXFORVvF4BGRypKeyemrlSIYrlHroUZwsCzGSxMt-UwIdEm76_9Iti_73owRbLQrlidQOKfKKqRFI/s866/asciinema.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="866" data-original-width="866" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLCkh8ea_HnDhz8HjLC5jUZ1OnoST8KBFo2-m_-w7c1XWxrDPEFagqNhrZCv3EVh5j-tf0slVYB1mS5eFEhAbhevzgZHJ_b-6mEG3xnPE_VZjLP3wXFORVvF4BGRypKeyemrlSIYrlHroUZwsCzGSxMt-UwIdEm76_9Iti_73owRbLQrlidQOKfKKqRFI/s320/asciinema.png" width="320" /></a></div>Though there are lot of tools available to record the terminal screen but I 💜 the <a href="https://asciinema.org/" target="_blank">asciinema</a> the most. The Reason, It's <i style="font-weight: bold;">SIMPLICITY. </i> It is easy to install, use, upload and share functionality make this tool unique in the groups. So let's roll and see how the magic is done 😆</div><div><br /></div><h3 style="text-align: left;">Installation:</h3><div>asciinema is available on multiple platforms as offered via pip (python), homebrew, debian, yum and docker environment. If binary is not available for you system, you can build it from scratch as well. </div><div><br /></div><div><b>Debian:</b> <span style="color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit;">sudo apt-get install asciinema</span></div><div><br /></div><div><b>Homebrew ( Mac/Linux):</b> <span style="color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit;">brew install asciinema</span></div><div> </div><div><b>RPM: </b><span style="color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit;">sudo yum install asciinema # or </span><span style="color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit;">sudo dnf install asciinema</span></div><div><br /></div><b>PIP: </b><span style="color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit;">sudo pip3 install asciinema</span><div><div><br /></div><div><b>Docker: </b><span style="color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit;">docker pull ghcr.io/asciinema/asciinema</span></div><div><span style="color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit;"><br /></span></div><div>Many more options are <a href="https://asciinema.org/docs/installation" target="_blank">available here</a>. </div><div><br /></div><div><br /></div><div><h3>Record:</h3></div><div>Once install, you can record the screen/terminal via below command : </div><div><br /></div><div><span style="font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;">asciinema rec [filename.cast]</span></div><div><br /></div><div>This spawns a new shell instance and records all terminal output. When you're ready to finish simply exit the shell either by typing exit or hitting <ctrl-D></div><div><br /></div><div><div><h3>Upload:</h3></div></div><div>You can upload the recording to asciinema.org to do that you have to login on the account which can be done via below command - </div><div><span style="color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit;"><br /></span></div><div><span style="color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit;">asciinema auth</span></div><div><span style="color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit;"><br /></span></div><div><br /></div><div>Now, to share the recording with others or websites are pretty easy as<a href="https://asciinema.org/docs/embedding" target="_blank"> mentioned here</a>. </div><div><br /></div><div><br /></div><div><br /></div><div> =<script async="" id="asciicast-335480" src="https://asciinema.org/a/tCo4kscStWIYzZdH8mradfPpD.js"></script>=
<br />
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br /><br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b></span><script>
var a=document.createElement('a');
a.href='https://www.buymeacoffee.com/datagenx';
var image = document.getElementById('mydiv').getElementsByTagName('img')[0];
b=a.appendChild(image);
document.getElementById('mydiv').appendChild(a);
block.setAttribute("style", "text-align:center");
</script><br />
<br /><div><br /></div><div><br /></div><div><br /></div><div><br /></div></div><br /></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-27635697178050970542023-08-31T22:15:00.008-05:002023-09-01T10:49:14.243-05:00Hashing (CheckSum) in Golang<div><div class="separator" style="clear: both; text-align: center;"><a href="https://raw.githubusercontent.com/atulsingh0/learning-golang/main/14-hashing/hash.go" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="1392" data-original-width="1300" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBhJmt7HSuWq230RKRx4bqSv1kRcp3lx_i_kKzrR43O7lMT5-pV9Ypm1CnyxXXT2V5dRP6nKDpWIQfTOYJ-PRQ1BMDbcAMcM4s31v5g_7yCXtfIP93sCpd-q2QHCXz73D_AZ-0PK2B3lYQ3dlrtwQurqtIcnjqiHYh25Q64Kc_GlqxW0VZeogX2eIDjJg/s320/golang12.png" width="299" /></a></div><br /></div>Hashing function is a function that takes a file, a message, or other input and return a fixed-sized string of bytes. This string is called a <i style="font-weight: bold;">Hash. </i>Hashing is not encryption so it is almost impossible to reverse/decrypt it get the original input. It is usually used in <b><i>Cryptography world</i></b> to provide the <b><i>integrity</i></b> and <b><i>authenticity</i></b> of received data. It ensure that input is not being altered when send. Hashing is one way process, we use it generate the <i style="font-weight: bold;">hash </i>but reverse is not possible. <div><br /></div><div>In Linux/Mac, there are binaries available by default to generate the Hash for the input. </div><div><br /></div><div><div>> <b>echo -n "abra ka dabra"</b> | <b>md5sum</b></div><div>ed17334f4782a78c727ea4cd7a99d1ac -</div><div><br /></div><div>> <b>echo -n "abra ka dabra"</b> | <b>sha256sum</b></div><div>55ecd52ce1955819067a5e44686d223405f0bc3e52617a97d5866ff4967d1166 -</div><div><br /></div><div>> <b>echo -n "abra ka dabra"</b> | <b>sha512sum</b></div><div>6aae7fc3506fb4007e363886ef1df5ffb735bd22c21112ba64d29dd492f20034303a176c2288ed4b49b7d280705f6f47b828243c28da5bee90bffa1e1d7b3501 -</div><div><br /></div><div><b>MD5</b>, <b>SHA256</b> and <b>SHA512 </b>are hashing algorithm, there are many more but these are widely used in the industry. You usually see the checksum/hash when you download the software binaries such as <a href="https://httpd.apache.org/download.cgi" target="_blank">Apache</a>, <a href="https://dev.mysql.com/downloads/repo/yum/" target="_blank">MySQL</a>, <a href="https://www.openssl.org/source/" target="_blank">OpenSSL</a>, <a href="https://www.python.org/downloads/release/python-3115/" target="_blank">Python</a>, <a href="https://go.dev/dl/" target="_blank">Golang</a> and many more. You can see wherever we see a download link on these pages, there is also a MD5, SHA256 or SHA512 hash code is also mentioned. </div><div><br /></div>In Golang, Hashing algorithms are part of standard library <a href="https://pkg.go.dev/crypto/md5" target="_blank">crypto/md5</a>, <a href="https://pkg.go.dev/crypto/sha256" target="_blank">crypto/sha256</a> and <a href="https://pkg.go.dev/crypto/sha256" target="_blank">crypto/sha512</a>. Once again these are not only the algorithms there are few more with Golang library. </div><div><br /></div><div>Let's see how we use these libraries for generate CheckSum: </div><div><br /></div><div><script src="https://atulsingh0.github.io/gist-it/embed-v2.js?target=https%3A%2F%2Fgithub.com%2Fatulsingh0%2Flearning-golang%2Fblob%2Fmain%2F14-hashing%2Fhash.go&style=atom-one-dark&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on&showFullPath=on&showCopy=on"></script></div>In Mac, commands are different but it work like below - <div><script async="" id="asciicast-EXmub6zaTMwOU9CFxPE3GkK8I" src="https://asciinema.org/a/EXmub6zaTMwOU9CFxPE3GkK8I.js"></script><br />
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b></span><script>
var a=document.createElement('a');
a.href='https://www.buymeacoffee.com/datagenx';
var image = document.getElementById('mydiv').getElementsByTagName('img')[0];
b=a.appendChild(image);
document.getElementById('mydiv').appendChild(a);
block.setAttribute("style", "text-align:center");
</script><br /></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-34936293424317521592023-08-30T17:03:00.001-05:002023-08-30T17:03:14.978-05:00Base64 Encoding & Decoding in GoLang<div><br /></div><div><div class="separator" style="clear: both; text-align: right;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYayjbesu7WqEh7th53fE0Gex1nmqKm3NXIZoe6-U_FQ2anSjMxm7QJIjPxvbqOP0NXlxzp56JYOQZkck1PaV9WjFKO7wLm8rVOzjb4_l1ajssvcJplCpxuVlXZqOR5QCH_-qTUd-tkeAzP_LquMpv8ZStOnt797ydmJXYgKE9_uHpW1wACeFR_t-792E/s924/golang7.png" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="636" data-original-width="924" height="220" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYayjbesu7WqEh7th53fE0Gex1nmqKm3NXIZoe6-U_FQ2anSjMxm7QJIjPxvbqOP0NXlxzp56JYOQZkck1PaV9WjFKO7wLm8rVOzjb4_l1ajssvcJplCpxuVlXZqOR5QCH_-qTUd-tkeAzP_LquMpv8ZStOnt797ydmJXYgKE9_uHpW1wACeFR_t-792E/s320/golang7.png" width="320" /></a></div>Encoding and decoding refer to the process of putting a sequence of characters into a specialized format for efficient transmission or storage. In computers, encoding is the process of putting a sequence of characters into a specialized format for efficient transmission or storage [<a href="https://search.brave.com/search?q=encoding+and+decoding&source=desktop" rel="nofollow" target="_blank">google</a>]. Keep in mind that Encoding/Decoding is not encryption/decryption.</div><div><br /></div><div>All <i>Linux/Mac</i> operating system comes with binary "<b><i>base64</i></b>" by default where <i>MS-Windows </i>does not provide the functionality by default in "<i>Command Prompt</i>" but in "<i>Powershell</i>". For using "<b><i>base64</i></b>" command in Command prompt, you have to install either <a href="https://www.di-mgt.com.au/base64-for-windows.html" target="_blank">this utility</a> or "<a href="https://slproweb.com/products/Win32OpenSSL.html" target="_blank">openssl</a>". </div><div><br /></div><div>Golang also provides <a href="https://pkg.go.dev/encoding/base64" target="_blank">encoding/base64</a> package to achieve the same. It implements base64 encoding as specified by <a href="https://rfc-editor.org/rfc/rfc4648.html" target="_blank">RFC 4648</a>. </div><div><br /><script src="https://atulsingh0.github.io/gist-it/embed-v2.js?target=https%3A%2F%2Fgithub.com%2Fatulsingh0%2Flearning-golang%2Fblob%2Fmain%2F13-eccode-decode%2Fencode-decode.go&style=atom-one-dark&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on&showFullPath=on&showCopy=on"></script></div><div><br /><b>Output:</b><script async="" id="asciicast-tCo4kscStWIYzZdH8mradfPpD" src="https://asciinema.org/a/tCo4kscStWIYzZdH8mradfPpD.js"></script></div><div class="separator" style="clear: both; text-align: center;"><br /></div><br /><div><br /></div>
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b></span><script>
var a=document.createElement('a');
a.href='https://www.buymeacoffee.com/datagenx';
var image = document.getElementById('mydiv').getElementsByTagName('img')[0];
b=a.appendChild(image);
document.getElementById('mydiv').appendChild(a);
block.setAttribute("style", "text-align:center");
</script><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-56490167635475078202023-06-01T07:25:00.001-05:002023-06-01T07:25:27.735-05:00Get User details from Github Token<div class="separator"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipZUxxvNZUwhs3vtSA3UfmoU6EF3QQZzYWqlKxy_w084OZJPuosBY8BieQRBDwxWhQAuICWL0QnfSzwNAKcZjFu6YHN78HoimUniUa7QfAAxebFWv82kSNzo7GPy9KkH8ssdGauX6sMpVRaqmK4bdkl6vQEX6HaKgebYzSCwaAYodTdDxKLgBQ8DBX/s1540/git1.png" style="clear: right; float: right; font-family: Georgia, "Times New Roman", serif; font-weight: 700; margin-bottom: 1em; margin-left: 1em; text-align: center;"><img border="0" data-original-height="800" data-original-width="1540" height="166" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipZUxxvNZUwhs3vtSA3UfmoU6EF3QQZzYWqlKxy_w084OZJPuosBY8BieQRBDwxWhQAuICWL0QnfSzwNAKcZjFu6YHN78HoimUniUa7QfAAxebFWv82kSNzo7GPy9KkH8ssdGauX6sMpVRaqmK4bdkl6vQEX6HaKgebYzSCwaAYodTdDxKLgBQ8DBX/s320/git1.png" width="320" /></a></div>While managing my environment, I've stumble-upon few Github tokens (PAT or Personal Access Token) which was mentioned in my scratch book but silly me, I forgot to mention the user name of those tokens. After few google search, I have found few ways to fetch the username of those PATs which I am going to discuss here. <br />
<br /><b>Programmatically:</b><br /> You can write down program to complete the ask but it does not worth the effort until you are in really need it. You can use any programming language to do this magic whether you are using <i><b>Python (<a href="https://github.com/PyGithub/PyGithub" target="_blank">PyGithub</a>), Ruby (<a href="https://octokit.github.io/octokit.rb/" target="_blank">Oktokit</a>) or Go (<a href="https://pkg.go.dev/github.com/google/go-github/github" target="_blank">go-github</a>)</b></i>, it's pretty straight-forward if you get hold on the libraries. <div><br /></div><div><b>Via Script/Curl:</b></div><div><span> </span>But as I said earlier, It is too much to write code if you have to do only this. It can be done pretty easily with simple <i style="font-weight: bold;">curl. </i>Github provides <a href="https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28#get-the-authenticated-user" rel="nofollow" target="_blank">API</a> to fetch the authenticated user details which we can tweak for Github enterprise as well. </div><div><br /></div><div><div><span style="color: #990000; font-family: courier;"><b>curl -L \</b></span></div><div><span style="color: #990000; font-family: courier;"><b> -H "Accept: application/vnd.github+json" \</b></span></div><div><span style="color: #990000; font-family: courier;"><b> -H "Authorization: Bearer <YOUR-TOKEN>"\</b></span></div><div><span style="color: #990000; font-family: courier;"><b> -H "X-GitHub-Api-Version: 2022-11-28" \</b></span></div><div><span style="color: #990000; font-family: courier;"><b> https://api.github.com/user </b></span></div></div><div><br /></div><div>Let's see the complete script - </div><div><script src="https://atulsingh0.github.io/gist-it/embed-v2.js?target=https%3A%2F%2Fgithub.com%2Fatulsingh0%2FDataGenX%2Fblob%2Fmain%2FUtilities%2Ffetch-git-user-from-token.sh&style=github-dark-dimmed&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on&showFullPath=on&showCopy=on"></script></div><div><br /></div><div><b>Demo:</b></div><div><script async id="asciicast-0V1LEJD8MQpSDW1gLm4efbNFV" src="https://asciinema.org/a/0V1LEJD8MQpSDW1gLm4efbNFV.js"></script></div><div><br /><div><br />
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a> </b><a href="http://bit.ly/2rdmcO7" style="font-weight: bold;"></a><div class="separator" style="clear: both; display: inline; text-align: center;"><a href="http://bit.ly/2rdmcO7" style="font-weight: bold; text-align: left;"><b></b></a><b style="text-align: left;"><a href="http://bit.ly/2rdmcO7">Telegram Group</a></b></div><b><br /></b></span><br /></div></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-23232331774615327402023-05-29T09:30:00.009-05:002023-05-29T09:50:02.174-05:00Generating Support Bundle of k8s cluster Now a days I think everyone is working in k8s world directly or indirectly, In day to day life whatever apps/sites you are using they are most probably hosted on k8s cluster and managing these clusters can be hair pulling act sometime if you don't have the direct access on the cluster due to strict security or it is not at all is your cluster but the customer's. <div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNFJV6LwOgqPLEZy5fYy-Ua3fc1mDqSTO6X29vyBRpMBxgXuOnU9_75oKhqqvBQWbFeP-qgswfqmCPfOJ5HJH3fuJRbw7F3_yNZntUsqlF17AnqEplIC1VmEq_MUkqH7O_ZCPX8hbugEq_dY3ORM6Od6GLwD4ulo7DVjtyPNdYX2De7EpFyRE5OTDd/s1629/K8s.png" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="990" data-original-width="1629" height="194" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNFJV6LwOgqPLEZy5fYy-Ua3fc1mDqSTO6X29vyBRpMBxgXuOnU9_75oKhqqvBQWbFeP-qgswfqmCPfOJ5HJH3fuJRbw7F3_yNZntUsqlF17AnqEplIC1VmEq_MUkqH7O_ZCPX8hbugEq_dY3ORM6Od6GLwD4ulo7DVjtyPNdYX2De7EpFyRE5OTDd/s320/K8s.png" width="320" /></a></div><br /></div><div> Today, We are going to take a quick peek into the solution of this problem. <br /></div>
<div><br /></div><a href="https://www.replicated.com/" rel="nofollow" target="_blank">Replicated</a> org have developed a neat kubectl plugin to accommodate the same and it's called <i style="font-weight: bold;">support-bundle. </i>So let's look into more details. <br />
<br /><b>What is it exactly:</b><div><span> </span>A support bundle is an archive that's created in-cluster, by collecting logs, cluster information and executing various commands. After creating a support bundle, the cluster operator will normally deliver it to the application vendor for analysis and remote debugging.<br /><br /><br />
<b>Installation:</b><div><ul style="text-align: left;"><li>Install <a href="https://krew.sigs.k8s.io/docs/user-guide/setup/install/" rel="nofollow" target="_blank">krew</a> (kubectl plugin repository)</li><li>Install preflight and support bundle to your machine.<br /><br /><span style="font-family: courier;">kubectl krew install preflight <br />kubectl krew install support-bundle</span></li></ul><span style="font-family: courier;"><br /></span><b><span style="font-family: inherit;">Usage:</span><br style="font-family: courier;" /></b><span> To use the standard definition for support bundle (definition</span> is <a href="https://raw.githubusercontent.com/replicatedhq/troubleshoot/master/examples/support-bundle/sample-supportbundle.yaml" rel="nofollow" target="_blank">here</a>) you can simply run below command - </div><div><span style="font-family: courier;"><span> <br /></span><span> </span></span><span style="font-family: courier;">kubectl support-bundle https://support-bundle.replicated.com<br /></span>==</div><script async="" id="asciicast-vo0sbboWOIEyG5y1DOMFSAeQa" src="https://asciinema.org/a/vo0sbboWOIEyG5y1DOMFSAeQa.js"></script>
<div><br />==</div><div>If above video is not loading, you can watch the demo <a href=" https://asciinema.org/a/vo0sbboWOIEyG5y1DOMFSAeQa" rel="nofollow" target="_blank">here</a>.</div><div><br /></div><div><i><b>Data in Support Bundle - <br /></b></i></div><div><a data-flickr-embed="true" href="https://www.flickr.com/photos/victimizeit/52934624106/in/dateposted-public/" title="support-bundle"><img alt="support-bundle" height="61" src="https://live.staticflickr.com/65535/52934624106_3dd16d4881_o.png" width="640" /></a></div><div><br /></div><div><br /></div><div>You can also customize the definition as per your need, you can start from <a href="https://troubleshoot.sh/docs/support-bundle/collecting/" rel="nofollow" target="_blank"><i> here.</i></a> An example of custom definition can be <a href="https://raw.githubusercontent.com/CircleCI-Public/server-scripts/main/support/support-bundle.yaml" rel="nofollow" target="_blank">found here created</a> by <b><a href="https://circleci.com/" rel="nofollow" target="_blank">CircleCI</a></b>. <br /><br />So now, if you want to share the logs and specification about your cluster to anyone without giving them access to your cluster, Support bundle plugin is there to help you. Keep watching this space as in the next post I am going to discuss about how you should/can read this bundle like you are directly accessing the cluster. So Keep Watching...Keep Learning.... <br /><br /><br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b>
<br /><br />
<br />
</span>
</div></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-60384206977744707722023-02-25T21:53:00.004-05:002023-02-25T21:56:29.132-05:00Connecting to Oracle DB in Linux Shell Script<div class="separator"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTZpbeq_slHCKrdNu2p6Pyn_fceVNWrpRVYOmKJcXp8MfgzMoa_Ul1Szxd_0FKz7iiaw_vC87dAip_kJci4e1GNYyzvTrw5prFPp3klKw-E36PjJCiYYFWlcIhYpluHzQNqxYqzPc_5Wuii7ha_fOioJu0Cp-8esb3ezyRnYviSZW_CwBUMM76sG90/s323/linux3.jpg" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em; text-align: center;"><img border="0" data-original-height="156" data-original-width="323" height="155" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTZpbeq_slHCKrdNu2p6Pyn_fceVNWrpRVYOmKJcXp8MfgzMoa_Ul1Szxd_0FKz7iiaw_vC87dAip_kJci4e1GNYyzvTrw5prFPp3klKw-E36PjJCiYYFWlcIhYpluHzQNqxYqzPc_5Wuii7ha_fOioJu0Cp-8esb3ezyRnYviSZW_CwBUMM76sG90/s320/linux3.jpg" width="320" /></a></div><br />
In this post, we will see how to connect to Oracle DB in Linux Shell Script. There are some prerequisite for a Linux server to connect to Oracle DB. There should be oracle db driver installed on the Linux server from which you want to connect to Oracle DB. Check whether you can call/connect SQLPLUS from command line.<br />
<span style="color: #351c75; font-family: Courier New, Courier, monospace;">$ sqlplus</span><br />
if you are not able to, check whether oracle path is set in .profile file. Lets assume, Oracle DB driver is installed on Server and Sqlplus path is set.<br />
<br />
Now, there are some basic steps to connect to Oracle DB-<br />
a) Connect to Oracle DB with UserID and Password<br />
b) Execute the SQLs<br />
c) Store the output in a file or send to standard output (terminal)<br />
<br />
<br />
<a name='more'></a><b>A) Connect to Oracle DB and send the SQL output to Standard Output (terminal)</b><br />
========================================================================<br />
<script src="https://gist.github.com/atulsingh0/1dec587cabbf88327b1e.js"></script><br />
========================================================================<br />
<br />
<b>B) Connect to Oracle DB and assign the output a variable for output formatting</b><br />
========================================================================<br />
<script src="https://gist.github.com/atulsingh0/989c36cadef5b5bbac91.js"></script><br />
========================================================================<br />
<br />
<b>C) Connect to Oracle DB and send the Output to a File</b><br />
<div>
========================================================================</div>
<script src="https://gist.github.com/atulsingh0/e9468571548b64abfe8d.js"></script><br />
========================================================================<br /><br />
<br />
<br />
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b>
<br /><br />
<br />
</span><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-71712834962195250842023-01-24T06:59:00.008-05:002023-01-24T07:01:25.966-05:00Enabling your Shell Environment for Enhanced Developer Experience - Part-2To continue the previous post, <b><i><a href="https://www.datagenx.net/2022/11/enabling-your-shell-environment-for.html" target="_blank">Enabling your Shell Environment for Enhanced Developed Experience</a></i></b>, In this chapter we are going to learn few more plugins/tools which will be useful for you, I have already linked the tools site to have a better description for installation on multiple OS and configuration if needed rather than explaining in this post. <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTZpbeq_slHCKrdNu2p6Pyn_fceVNWrpRVYOmKJcXp8MfgzMoa_Ul1Szxd_0FKz7iiaw_vC87dAip_kJci4e1GNYyzvTrw5prFPp3klKw-E36PjJCiYYFWlcIhYpluHzQNqxYqzPc_5Wuii7ha_fOioJu0Cp-8esb3ezyRnYviSZW_CwBUMM76sG90/s323/linux3.jpg" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="156" data-original-width="323" height="155" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTZpbeq_slHCKrdNu2p6Pyn_fceVNWrpRVYOmKJcXp8MfgzMoa_Ul1Szxd_0FKz7iiaw_vC87dAip_kJci4e1GNYyzvTrw5prFPp3klKw-E36PjJCiYYFWlcIhYpluHzQNqxYqzPc_5Wuii7ha_fOioJu0Cp-8esb3ezyRnYviSZW_CwBUMM76sG90/s320/linux3.jpg" width="320" /></a></div><b><div><b><br /></b></div><div><b><br /></b></div><a href="https://stedolan.github.io/jq/" target="_blank">jq - JSON data parser</a></b><br /><div>
<a href="https://stedolan.github.io/jq/" target="_blank">jq is a command line tool </a>which help to prettify and parse the json structure. This tool is a must if you are dealing with json data on daily basis</div><div><br /></div><div><b><a href="https://kislyuk.github.io/yq" target="_blank">yq - YAML data parser</a></b><br /> Along the same path as jq, <a href="https://kislyuk.github.io/yq" target="_blank">yq is a command line tool or a wrapper for jq</a> which parse the YAML data to JSON and passed to jq to process. To make yq work, jq command line must be installed as a prerequisite. </div><div><br /></div><div><b><a href="https://kislyuk.github.io/yq" target="_blank">xq - XML data parser</a></b></div><div><b> </b>xq command line is installed with yq and parse the XML data, It translate the xml data to json which later processed by jq command line. </div><div><br /></div><div><b><a href="https://github.com/sharkdp/bat" target="_blank">bat - yet another cat command</a></b></div><div><span style="background-color: white; font-family: inherit;"> Do you want a nice view of text files, use bat rather than cat command. It supports syntax highlighting for a large number of programming and markup languages. </span></div><div><br /></div><div><span style="background-color: white; font-family: inherit;"><b>Shell Terminal</b></span></div><div><span style="background-color: white; font-family: inherit;"> <span style="font-family: inherit;"> Do you spend most of your time on terminal, If yes, these are the tools which I use to make my life easier. </span></span></div><div><ul style="background-color: white; border: 0px; box-sizing: border-box; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; list-style: circle; margin: 0px 0px 0.75em 2em; padding: 0px; vertical-align: baseline;"><li style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline;"><a href="https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701?hl=en-ca&gl=ca&rtc=1" target="_blank">Windows Terminal </a>for Microsoft Windows</li><li><a href="https://iterm2.com/" target="_blank">iTerm2</a> for MacOS</li><li><span style="font-family: inherit;"><span style="font-family: inherit;"><a href="https://gnome-terminator.org/" target="_blank">Terminator</a>, </span></span><span style="background-color: transparent; font-family: inherit;"><span style="color: #444444;"><a href="https://github.com/alacritty/alacritty" target="_blank">Alacritty</a>, </span> <a href="https://apps.kde.org/yakuake/" target="_blank">yakuake</a>, <a href="https://github.com/lanoxx/tilda" target="_blank">Tilda</a>, <a href="https://github.com/kovidgoyal/kitty" target="_blank">Kitty</a>, <a href="https://tabby.sh/" target="_blank">Tabby</a>, and Putty for Linux</span></li></ul></div><div>Each tool have it's pros and cons and different learning curve so the experience varies from user to user as they have different asks and needs. </div><div><br /></div><div><b>For Linux Geeks</b></div><div><span style="background-color: white; font-family: inherit;"><span> There are many more tools for linux geeks which are very good to explore and find the one which best fit your need. These are few of many - </span></span></div><ul style="background-color: white; border: 0px; box-sizing: border-box; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; list-style: circle; margin: 0px 0px 0.75em 2em; padding: 0px; vertical-align: baseline;"><li style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline;"><span style="font-family: inherit;"><a href="https://github.com/tmux/tmux/wiki" target="_blank">tmux</a> (Terminal multiplexer)</span></li><li style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline;"><span style="font-family: inherit;"><a href="https://github.com/BurntSushi/ripgrep/" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">ripgrep</a>, <a href="https://github.com/ggreer/the_silver_searcher" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">ag</a>, <a href="https://github.com/beyondgrep/ack3" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">ack</a> (grep)</span></li><li style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline;"><span style="font-family: inherit;"><a href="https://github.com/sharkdp/bat" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">bat</a> (cat)</span></li><li style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline;"><span style="font-family: inherit;"><a href="https://github.com/dandavison/delta" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">delta</a> (a pager for git)</span></li><li style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline;"><span style="font-family: inherit;"><a href="https://github.com/sharkdp/fd" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">fd</a> (find)</span></li><li style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline;"><span style="font-family: inherit;"><a href="https://github.com/chmln/sd" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">sd</a> (sed)</span></li><li style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline;"><span style="font-family: inherit;"><a href="https://github.com/rupa/z" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">z</a>, <a href="https://github.com/clvv/fasd" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">fasd</a>, <a href="https://github.com/wting/autojump" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">autojump</a>, <a href="https://github.com/ajeetdsouza/zoxide" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">zoxide</a> (tools to make it easier to find files / change directories)</span></li><li style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline;"><span style="font-family: inherit;"><a href="https://github.com/junegunn/fzf" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">fzf</a>, <a href="https://github.com/peco/peco" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">peco</a> (“fuzzy finder”)</span></li><li style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline;"><span style="font-family: inherit;"><a href="https://github.com/nvbn/thefuck" style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;">fuck</a> (autocorrect command line errors) and <a href="https://jvns.ca/blog/2022/04/12/a-list-of-new-ish--command-line-tools/" target="_blank">many more</a>. </span></li></ul><div><span style="background-color: white; font-family: inherit;"><br /></span></div><div><span style="background-color: white; font-family: inherit;"><b>For Linux Scriptors </b></span></div><div><span style="background-color: white; font-family: inherit;"> If you write linux scrips in your day to day work, I advise to use "<a href="https://github.com/sstephenson/bats" target="_blank"><b>bat</b></a>" (not cat one) which is a Shell Script testing framework and <b><a href="https://www.shellcheck.net/" target="_blank">ShellCheck</a></b> which force you to use best possible way to write. </span></div><div><span style="background-color: white; font-family: inherit;"> </span></div><div><span style="background-color: white; font-family: inherit;"><b>For K8s world</b></span></div><div><span style="font-family: inherit;"><span style="background-color: white;"> </span><span style="background-color: white; font-family: inherit;"> Containerization is contagious in application world and most popular tools to manage containers is <a href="https://kubernetes.io/" target="_blank">k8s</a>. These are few tools which I am sure you have heard of, if not, give these a try -</span></span></div><div><ul style="border: 0px; box-sizing: border-box; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; list-style: circle; margin: 0px 0px 0.75em 2em; padding: 0px; vertical-align: baseline;"><li style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline;"><span style="background-color: white; font-family: inherit;"><a href="https://github.com/ahmetb/kubectx" target="_blank">kubectx and kubens</a> (Quick switch of k8s context and namespace)</span></li><li style="box-sizing: border-box; margin-top: 0.25em;"><span style="background-color: white; font-family: inherit;"><a href="https://github.com/derailed/k9s" style="box-sizing: border-box; text-decoration-line: none;">K9s</a> - provides a terminal UI to interact with your Kubernetes clusters.</span></li><li style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline;"><span style="background-color: white; font-family: inherit;"><a href="https://github.com/jonmosco/kube-ps1" target="_blank">kube-ps1</a> - k8s prompt for bash and zsh shell</span></li><li style="border: 0px; box-sizing: border-box; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline;"><span style="background-color: white; font-family: inherit;"><a href="https://github.com/stern/stern" style="box-sizing: border-box; font-size: 16px; text-decoration-line: none;">stern</a><span style="font-size: 16px;"> </span><span style="font-size: 16px;">- allows you to tail multiple pods on Kubernetes and multiple containers within the pod</span></span></li><li style="box-sizing: border-box; margin-top: 0.25em;"><span style="background-color: white; font-family: inherit;"><a href="https://github.com/rancher/k3s" style="box-sizing: border-box; text-decoration-line: none;">k3s</a> - Lightweight Kubernetes. Easy to install, Kubernetes clusters from the command line and <a href="https://github.com/tomhuang12/awesome-k8s-resources" target="_blank">many-more</a></span></li></ul></div><div><span style="background-color: white; font-family: inherit;"><br /></span></div><div><span style="background-color: white; font-family: inherit;"><b>Explore <a href="https://unix-shell.zeef.com/caleb.xu" target="_blank">Unix-Shell</a></b></span></div><div><span style="background-color: white; font-family: inherit;"><span> This is a collection of different awesome tools/command-lines are available for Nix world. </span></span><span style="background-color: white;">Have a look at your</span><span style="background-color: white;"> </span><span style="background-color: white;">convenience.</span></div><div><span style="background-color: white; font-family: inherit;"><span><br /></span></span></div><div><div><b>Explore <a href="https://github.com/alebcay/awesome-shell#awesome-shell-" target="_blank">Awesome-Shell</a></b></div><div> <span style="background-color: white; font-family: inherit;">This is yet another git repo is a </span><span style="background-color: white; font-family: inherit;">curated list of awesome command-line frameworks, toolkits, guides and gizmos.</span></div></div><div><br /></div><div>Lastly, above mentioned all tools are just a recommendations which might not fit your needs, So explore, explore and explore and find the tools, configurations which makes your life easier. </div><div><br /></div><div>
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b></span><script>
var a=document.createElement('a');
a.href='https://www.buymeacoffee.com/datagenx';
var image = document.getElementById('mydiv').getElementsByTagName('img')[0];
b=a.appendChild(image);
document.getElementById('mydiv').appendChild(a);
block.setAttribute("style", "text-align:center");
</script></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-24739765201721930812022-11-21T16:11:00.004-05:002023-01-24T07:11:58.895-05:00Enabling your Shell Environment for Enhanced Developer ExperienceOla Amigos !! Whether you are a developer or not if you are working on a Shell, you are probably is one of many who doesn't like the look and feel of Shell's environment. It does not matter which OS (Ubuntu, RHEL, Solaris or Windows WSL) you are working on a bland blank and white screen in the era of colors. <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnxWOZ9Ik2Axx0Q9d1zOxV2G0OJSmKEIXE00tZLrUsya1gMnlpvp1xFCo1eF45-U-0-83qX3ySXDoINvyrTBN1Ft16rNE154K37VFAACU6zx-AIoIjjCWK2350eg8NbzPH8nkzgPp3R80OIGYrD7rSOD8FPpI8PMx0jfypXx0WkuWdGuXbhIE2QFh1/s200/24a080de-3ff1-438b-aacb-19e637a162fe_200x200.png" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="200" data-original-width="200" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnxWOZ9Ik2Axx0Q9d1zOxV2G0OJSmKEIXE00tZLrUsya1gMnlpvp1xFCo1eF45-U-0-83qX3ySXDoINvyrTBN1Ft16rNE154K37VFAACU6zx-AIoIjjCWK2350eg8NbzPH8nkzgPp3R80OIGYrD7rSOD8FPpI8PMx0jfypXx0WkuWdGuXbhIE2QFh1/s1600/24a080de-3ff1-438b-aacb-19e637a162fe_200x200.png" width="200" /></a></div><br /><div><span> </span><span> </span>But don't worry, Today, I am going to share what I do whenever I get a new machine, how do I make my shell life colorful. These tips are completely optional or you can jump the steps as you like. So without further a due, let's get start - </div><div><br /></div><div><h3 style="text-align: left;">Step #1 - Installing ZSH</h3><div>Skip if you are using Macbook, as it already comes with ZSH installed. Most of the other Unix like OS comes with Bash so we are going to install ZSH, Though there is nothing wrong with Bash but a lot of tooling available around ZSH which we are going to utilize. </div><div><span> </span>I am assuming you are using Ubuntu hence all the commands are targeting that.<b> <a href="https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH" target="_blank"><i>Follow the link</i></a></b> for the commands for other OSs as well. </div><div><br /></div><div><script src="https://atulsingh0.github.io/gist-it/embed-v2.js?target=https%3A%2F%2Fgithub.com%2Fatulsingh0%2FDataGenX%2Fblob%2Fmaster%2FUtilities%2Fsetup-zsh.sh%23L1-L12&style=base16%2Fdracula&type=code&showBorder=on&showLineNumbers=on&showFullPath=on&showCopy=on"></script></div>-
<br />
<h3>Step #2 - Installing Oh-My-ZSH</h3><div>As I was saying, Oh-My-ZSH is a open source framework written for ZSH to easy customization and configuration. <a href="https://github.com/ohmyzsh/ohmyzsh/blob/master/README.md#basic-installation" target="_blank"><b><i>Follow the link</i></b></a> for other method of installation.</div><div><br /></div><div><script src="https://atulsingh0.github.io/gist-it/embed-v2.js?target=https%3A%2F%2Fgithub.com%2Fatulsingh0%2FDataGenX%2Fblob%2Fmaster%2FUtilities%2Fsetup-zsh.sh%23L14-L15&style=base16%2Fdracula&type=code&showBorder=on&showLineNumbers=on&showFullPath=on&showCopy=on"></script></div>-</div>
<div><br /></div><h3>Step #3 - Setting up Theme </h3><div>You can skip if you have any other theme preference but I love the theme <a href="https://github.com/romkatv/powerlevel10k#oh-my-zsh" target="_blank"><b><i>"powerlevel10k"</i></b></a>, You can install this theme by running the below commands - </div><div><script src="https://atulsingh0.github.io/gist-it/embed-v2.js?target=https%3A%2F%2Fgithub.com%2Fatulsingh0%2FDataGenX%2Fblob%2Fmaster%2FUtilities%2Fsetup-zsh.sh%23L17-L19&style=base16%2Fdracula&type=code&showBorder=on&showLineNumbers=on&showFullPath=on&showCopy=on"></script>- </div><div>Once, you are done with this step, Exit and reopen terminal to start the configuration, there are going to be bunch of questions which you have to opt-in/out based on your likings. If you don't want to use this theme, there are <a href="https://github.com/ohmyzsh/ohmyzsh/wiki/Themes" target="_blank"><b><i>many other themes</i></b></a> which you can explore and play-around.</div><div><br /></div><div><h3>Step #4 - Enabling Plugins</h3><div style="text-align: left;">Oh-my-zsh offers <a href="https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins" target="_blank"><b><i>plethora of plugins</i></b></a> to make your life easy which you can explore. Here, I am going to share which I like the most. But keep in mind that plugins execute at shell startup so it will slow down shell start if you are using too many plugins. So pick and choose as per your need. </div></div><div style="text-align: left;"><br /></div><div style="text-align: left;"><i>a. <a href="https://github.com/zsh-users/zsh-syntax-highlighting">zsh-syntax-highlighting </a><br />b. <a href="https://github.com/zsh-users/zsh-history-substring-search" target="_blank">zsh-history-substring-search </a><br />c. <a href="https://github.com/zsh-users/zsh-autosuggestions" target="_blank">zsh-autosuggestions </a></i><br /><i>d. <a href="https://github.com/zsh-users/zsh-completions" target="_blank">zsh-completions </a><br />e. <a href="https://github.com/z-shell/H-S-MW#oh-my-zsh-omz" target="_blank">history-search-multi-word</a></i></div><div style="text-align: left;"><br /></div><div style="text-align: left;"><script src="https://atulsingh0.github.io/gist-it/embed-v2.js?target=https%3A%2F%2Fgithub.com%2Fatulsingh0%2FDataGenX%2Fblob%2Fmaster%2FUtilities%2Fsetup-zsh.sh%23L21-L45&style=base16%2Fdracula&type=code&showBorder=on&showLineNumbers=on&showFullPath=on&showCopy=on"></script>-</div><div><br /></div><div><h3>Step #5 - Few Tips</h3></div><div>* Use <b><i>take</i></b> command to create and cd into any directory, if the directory exists, it will allow you to cd into it. </div><div><b>i.e</b> - <i><b>take src # </b>which actually execute as --> mkdir -p src && cd src</i></div><div><br /></div><div>* Use <i style="font-weight: bold;">md </i>command which is actually an alias for <b><i>mkdir -p</i></b></div><div><b>i.e</b><i><b> - md src/package/calc # </b>execute as --> mkdir -p src/package/calc</i></div><div><i><br /></i></div><div><i style="font-weight: bold;">* </i>Oh-my-zsh allow automatic <b><i>cd</i></b>, you don't have to use <b><i>cd</i></b> command to switch directories, simply type the directory name and you will be in.</div><div><div><b>i.e</b><i><b> - src/package/calc # </b>execute as --> cd src/package/calc</i></div></div><div><br /></div><div>Explore this <a href="https://github.com/ohmyzsh/ohmyzsh/wiki/Cheatsheet" target="_blank"><i>oh-my-zsh cheat-sheet</i></a> for more handy-dandy commands to speedup your work. This is it for this post, we will discuss few <b><i><a href="https://buff.ly/3Wx4cYj" target="_blank"><span style="font-size: medium;">other tools which make your life easier in next post.</span></a> </i></b></div><div><br /></div><div><br /></div>
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram</a></b><br /></span>
<script>
var a=document.createElement('a');
a.href='https://www.buymeacoffee.com/datagenx';
var image = document.getElementById('mydiv').getElementsByTagName('img')[0];
b=a.appendChild(image);
document.getElementById('mydiv').appendChild(a);
block.setAttribute("style", "text-align:center");
</script><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-35336843143315173892022-10-23T20:28:00.003-05:002022-10-27T16:30:53.987-05:00Docker: Overriding ENTRYPOINT and CMD <a href="https://www.datagenx.net/search/label/Docker" target="_blank">Docker</a> is one of the most used tool among not only developers but almost everyone to either demo some application or playing with it. <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8iDhnD_UQTP3eq23sE6fZMIEqf8l9PkqPBAyfB7688OXevsOclki-6B2hVxlyTSChrc67Tgj0rpo4hel9kUjdL6t1toDOLOYW1-FbS3MWIIyjXbpcDDqpSkCAWiepnIrjAHT6-KbCLwNUqSCv7n_C0t52Va9ZqLeGNUp5cliWhAqAj_y56KpXNjZC/s900/docker2.png" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="506" data-original-width="900" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8iDhnD_UQTP3eq23sE6fZMIEqf8l9PkqPBAyfB7688OXevsOclki-6B2hVxlyTSChrc67Tgj0rpo4hel9kUjdL6t1toDOLOYW1-FbS3MWIIyjXbpcDDqpSkCAWiepnIrjAHT6-KbCLwNUqSCv7n_C0t52Va9ZqLeGNUp5cliWhAqAj_y56KpXNjZC/s320/docker2.png" width="320" /></a></div><div><br /></div>Usually, Dockerfile holds all the instruction to create the docker image including the command which need to run when it spin a container. Those commands are referenced as <b>ENTRYPOINT</b> and <b>CMD </b>and what's the difference is always a big question for new comer. <div><br /></div><div>Rather then going into the technical details of What are those, I will go with simple explanation of these 2 buddies, I hope this will help you to better understand these buggers :) </div><div><br /></div><div><ul style="text-align: left;"><li>Either of them, if used alone, is responsible for executing the command within container</li><ul><li>So either use ENTRYPOINT or CMD both will run the command mentioned in it.</li><li><span class="pl-k" face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; border: 0px; box-sizing: inherit; color: #d73a49; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: pre;">CMD</span><span face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; color: #24292f; font-size: 12px; white-space: pre;"> [</span><span class="pl-s" face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; border: 0px; box-sizing: inherit; color: #032f62; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: pre;">"nginx"</span><span face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; color: #24292f; font-size: 12px; white-space: pre;">, </span><span class="pl-s" face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; border: 0px; box-sizing: inherit; color: #032f62; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: pre;">"-g"</span><span face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; color: #24292f; font-size: 12px; white-space: pre;">, </span><span class="pl-s" face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; border: 0px; box-sizing: inherit; color: #032f62; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: pre;">"daemon off;"</span><span face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; color: #24292f; font-size: 12px; white-space: pre;">] # OR</span></li><li><span face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; font-size: 12px; white-space: pre;"><span style="color: #d73a49;">ENTRYPOINT</span></span><span face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; color: #24292f; font-size: 12px; white-space: pre;"> [</span><span class="pl-s" face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; border: 0px; box-sizing: inherit; color: #032f62; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: pre;">"nginx"</span><span face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; color: #24292f; font-size: 12px; white-space: pre;">, </span><span class="pl-s" face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; border: 0px; box-sizing: inherit; color: #032f62; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: pre;">"-g"</span><span face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; color: #24292f; font-size: 12px; white-space: pre;">, </span><span class="pl-s" face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; border: 0px; box-sizing: inherit; color: #032f62; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: pre;">"daemon off;"</span><span face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; color: #24292f; font-size: 12px; white-space: pre;">]</span></li></ul><li>We can override the <b>CMD</b> command in command</li><ul><li><span face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; color: #24292f; font-size: 12px; white-space: pre;">docker run <image> <span style="color: #d73a49;"><cmd></span></span></li></ul><li>and similarly, we can override the <b>ENTRYPOINT</b> as well </li><ul><li><span face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; color: #24292f; font-size: 12px; white-space: pre;">docker run</span> <span face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="color: #d73a49; font-size: 12px; white-space: pre;">--entrypoint <entrypoint_cmd> </span><span class="pl-s" face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="background-color: white; border: 0px; box-sizing: inherit; color: #032f62; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: pre;"><image><br /></span></li></ul><li>But if we used them together, the behave like below - </li><ul><li><span face="ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace" style="color: #d73a49; font-size: 12px; white-space: pre;"><entrypoint_cmd> <cmd> </span></li></ul></ul>
<div>So if you want your user to override the entry command, use <b>CMD</b>, it is comparatively easy to override in command line than ENTRYPOINT. </div><div><br /></div><br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b><br /><br />
<br />
</span></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-12513592667952680052022-10-06T10:27:00.001-05:002022-10-06T10:27:28.470-05:00Golang - Listing Directory ContentOnce again, another os operation which we usually done via <b>`ls` (*nix) </b>or <b>`dir` (windows) </b>can be done in <i>Golang</i> as well. Golang package <b>"os" </b>offer so many os level operations which we can use to achieve our target. Listing a directory content is pretty obvious step in day to day life and the same can be done via <i style="font-weight: bold;">`os.ReadDir` </i>function, let's explore how to - <div><a data-flickr-embed="true" href="https://www.flickr.com/photos/victimizeit/52349539250/in/album-72157657279999983/" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" title="golang1"><img alt="golang1" height="200" src="https://live.staticflickr.com/65535/52349539250_f4e96aea3b_w.jpg" width="136" /></a><br /></div><script async="" charset="utf-8" src="//embedr.flickr.com/assets/client-code.js"></script><div>-<script src="https://atulsingh0.github.io/gist-it/embed-v2.js?target=https%3A%2F%2Fgithub.com%2Fatulsingh0%2Flearning-golang%2Fblob%2Fmain%2Fusing-os%2Fread-dir.go&style=atom-one-dark&type=code&showFileMeta=on&showFullPath=on&showCopy=on"></script>- <br /><br /><!--StartFragment--><pre><div 12px="" courier="" font-size:="" monospace="" new="" style="background-color: black;"><div><span style="color: #ff6ac1;">❯</span> <span style="color: #62e884;">go</span> run <span style="text-decoration-line: underline;">read-dir.go</span> </div><div>Directory: /tmp </div><div> </div><div>IsDir Name </div><div>------------------------ </div><div>false RandomWords </div><div>false com.adobe.acrobat.rna.RdrCefBrowserLock.DC </div><div>false com.adobe.reader.rna.0.1f5.DC </div><div>false com.adobe.reader.rna.1af6.1f5 </div><div>true com.apple.launchd.kTivor0R2j </div><div>true powerlog </div></div></pre><!--EndFragment--><br />
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b><br /><br />
<br />
</span></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-69555570514978455332022-10-05T13:53:00.005-05:002022-10-05T13:58:09.672-05:00K8s cluster on your local machine via k3dThere are many tools available in marketplace to standing up a k8s cluster on your local machine, few of there are - <a href="https://kind.sigs.k8s.io/docs/user/quick-start/" target="_blank"><i>kind</i></a>, <a href="https://minikube.sigs.k8s.io/docs/start/" target="_blank"><i>minikube</i></a>, <a href="https://github.com/minishift/minishift" target="_blank"><i>minishift</i></a>, <i><a href="https://k3s.io/" target="_blank">k3s</a></i> but I am doing to discuss <b style="font-style: italic;">k3d </b>which is a wrapper on k3s and using docker to build up the cluster with very neat command. I am just loving it as take only few mins (depends on machine) and voila!! your local k8s cluster is ready. Let's see explore the tool together. <div><br /></div><div><b>From k3d site:</b></div><div><i>k3d is a lightweight wrapper to run k3s (Rancher Lab’s minimal Kubernetes distribution) in docker. </i></div><div><i><span> </span>k3d makes it very easy to create single- and multi-node k3s clusters in docker, e.g. for local development on Kubernetes.</i><br /><div><br /></div><b>Prerequisite: <br /></b><div>* <i>Docker</i> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhy4NMIQI-I1jVrNavPHQRzZFLoxj_oWMzL1hJ_ndWJPXi0KhUcO16JoPlz2WAb6EXwf6uPgMib8F9v9d60nJ2X9nrenMn-mH1tlFw9ZauDis5Da2D5uWBOd7VRT_KuYMQKU2LNJZynHchQtFmWSu64TX3a_KR37lpXteafOaXzcdLvW_YZSOesgfsZ/s227/k8s.jpeg" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="222" data-original-width="227" height="222" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhy4NMIQI-I1jVrNavPHQRzZFLoxj_oWMzL1hJ_ndWJPXi0KhUcO16JoPlz2WAb6EXwf6uPgMib8F9v9d60nJ2X9nrenMn-mH1tlFw9ZauDis5Da2D5uWBOd7VRT_KuYMQKU2LNJZynHchQtFmWSu64TX3a_KR37lpXteafOaXzcdLvW_YZSOesgfsZ/s1600/k8s.jpeg" width="227" /></a></div><div><br /></div><div><b>Installation:</b></div><div><div><span style="font-family: courier;"><br /></span></div><div><span style="font-family: verdana;"># To install latest k3d</span></div><div><span style="color: #351c75; font-family: verdana;">curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash</span></div><div><span style="font-family: courier;"><br /></span></div><div><span style="font-family: verdana;"># To install any specific version of k3d</span></div><div><span style="color: #351c75;"><span style="font-family: verdana;">curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | TAG=v5.0.0 bash</span><span style="font-family: courier;"> </span></span></div></div><div><br /></div><div>Once, k3d is installed on your local machine, Check the version - </div><div><br /></div><div><div><div><span style="font-family: verdana;"># version check</span></div><div><span style="color: #351c75;"><span style="font-family: verdana;">k3d --version </span></span></div></div><div><span style="color: #351c75;"><span style="font-family: verdana;"><br /></span></span></div><div><div><div><span style="font-family: verdana;"># Install with 3 worker nodes</span></div><div><span style="color: #351c75;"><span style="font-family: verdana;">k3d cluster create --agents 3 <cluster-name> </span></span></div></div></div><div><span style="color: #351c75;"><span style="font-family: courier;"><br /></span></span></div><div><span style="font-family: inherit;"><b>Uninstallation:</b></span></div><div><span style="color: #351c75;"><span style="font-family: courier;"><br /></span></span></div><div><div><span style="font-family: verdana;"># Install with 3 worker nodes</span></div><div><span style="color: #351c75;"><span style="font-family: verdana;">k3d cluster delete <cluster-name></span><span style="font-family: courier;"> </span></span></div></div><div><br /></div><div><b>Demo:<br /></b>-<script async="" id="asciicast-525884" src="https://asciinema.org/a/525884.js"></script>-<br /><br />
<br />
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b><br /><br />
<br />
</span></div></div></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-90835629197179550112022-10-03T13:50:00.005-05:002022-10-03T14:37:01.732-05:00Random Number Genearion with crypto/rand - GolangGeneration a random number in Golang can be done via 2 packages - <a href="https://pkg.go.dev/math/rand" target="_blank">math/rand</a> and <a href="https://pkg.go.dev/crypto/rand" target="_blank">crypto/rand</a>. We have explored the math/rand <a href="https://www.datagenx.net/2022/09/random-number-generation-golang.html" target="_blank">way in this post</a> where we have to set the seed every-time when we want to generate the number and that might cause issue when you are generating a lot of numbers in given time. Due to seed settings, there are chances that you will get a duplicate random number hence Golang provides an another package crypto/rand to deal with this dilemma. <div><div class="separator" style="clear: both; text-align: center;"><a href="https://raw.githubusercontent.com/atulsingh0/learning-golang/main/freeCodeCamp/37-random.go" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="1000" data-original-width="1000" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_vA2eaJLpnifTcLXspAoNghQ0o2wcko91hGcotqjiAkQL6tXQH3VQ4gbCGd63DtU6iYN0CxUYj8NCl23a0VA7Pw7-NVvMJtGJKSXDOgdElaVpFEMxfikITPJSZ3mLsdAfjoVckALyzQ4-ySCCDIYLMfq8nAx0neMyqGikUA7756fcI5OVCHnqfkRB/w200-h200/golang9.png" width="200" /></a></div> Today's post is simply a crypto/rand implementation to generate random string. <br /></div><div><br /></div><div>-<script src="https://atulsingh0.github.io/gist-it/embed-v2.js?target=https%3A%2F%2Fgithub.com%2Fatulsingh0%2Flearning-golang%2Fblob%2Fmain%2FfreeCodeCamp%2F38-random-string-simplified.go&style=atom-one-dark&type=code&showFileMeta=on&showFullPath=on&showCopy=on"></script>-<br />
<br /><b>Output: </b></div><div><b><br /></b></div><div><!--StartFragment--><pre><div 12px="" courier="" font-size:="" monospace="" new="" style="background-color: black;"><div><span style="color: #ff6ac1;">❯</span> <span style="color: #62e884;">go</span> run <span style="text-decoration-line: underline;">38-random-string-simplified.go</span> </div><div>Random Number 1: zo38MaNsjIOtEtwNYge0NHQfwpSwPmym </div><div>Random Number 2: SYreojBSaHdRCYo2bbDcff8HR7_zbncZ </div><div>Random Number 3: 55tQB_WRe1SMDqM0EypNM9ZwHF-cfsbZ </div><div>Random Number 4: 8?e3oQP4MRlfDEga6x8SOF_o7QbA6pSW </div><div>Random Number 5: w3rQuQVU7KxUGFYRn8pv?Z98L??7UBLv </div></div></pre><!--EndFragment--><br />
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b><br /><br />
<br />
</span></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-41328907794079395242022-10-02T16:38:00.002-05:002022-10-02T16:38:53.394-05:00Few tips for your Docker EnvironmentIf you are playing around docker, there is a time when you have to take care of housekeeping job as well. In today's post, we are going to discuss different options to perform cleanup activities, just keep in mind before executing any command that few of them can destroy your whole week of work. So understand and then execute. <div class="separator" style="clear: both; text-align: center;"><a href="https://www.datagenx.net/search/label/Docker" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="506" data-original-width="900" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbzxlv8tqb1z8CdTmRFWr__dW7VEWn5X4rPzM8duuCy-sjzX8BV-32D4GQ0ELNKc9uUEKVVzGNbsfm7QHjbwjP8cj_HvOMFQziavKvXau6_c1Fsc6FeBCA-G-AQ_VATrz-71nLkLA3DfSbPm-YORDdbzKga6UyzR-QZRKmS97_7PtAOwlJg1BRfSEv/s320/docker2.png" width="320" /></a></div><div> <br /><b>docker system prune</b> </div><div><span> A very nice command to cleanup all the dangling items from your docker environment, by executing this command you are agree to clean below items -</span></div><div><ul style="text-align: left;"><li>all stopped containers</li><li>all dangling images</li><li>all build caches</li><li>all dangling network </li></ul><div><b>Manage docker logs</b></div><div><b> </b>By default there is no limit for your docker container logs, file can be as huge as the host OS system allowed but sometime it can be tricky to go through the logs if you have to debug any issue. We can restrict the max log file size for running containers as follows - <br /></div><div><br /></div><div><span class="fontstyle0"><span style="background-color: black; font-family: courier;"><div style="font-family: monospace; white-space: pre;"><span>❯</span> <span style="color: #060d95;">cat /etc/docker/daemon.json</span></div><div style="font-family: monospace; white-space: pre;"><span style="color: #060d95;">{</span></div><div style="font-family: monospace; white-space: pre;"><span style="color: #060d95;">"log-opts": {"max-size":"10m", "max-file":"3"}</span></div><div style="font-family: monospace; white-space: pre;"><span style="color: #060d95;">} </span><span style="color: #060d95;"> </span> </div><div style="font-family: monospace; white-space: pre;"><span><span>❯</span> </span></div><div style="font-family: monospace; white-space: pre;"><span><span>❯</span> <span style="color: #060d95;"> systemctl reload docker </span></span></div></span></span></div><div><span class="fontstyle0"><span style="font-family: courier;"><br /></span></span></div><div>If you don't want to change systemwide setting, you can use below flags when triggering docker run command to achieve the same.</div><div><br /></div><div><div style="font-family: monospace; white-space: pre;"><span>❯</span><span style="color: #060d95;"> docker run container \</span></div><div style="font-family: monospace; white-space: pre;">--log-opt max-size=10m --log-opt max-file=3 \</div><div style="font-family: monospace; white-space: pre;">....<span></span></div></div>
<div><br /></div><br />
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b><br /><br />
<br />
</span></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-9487645350275907902022-09-29T15:36:00.002-05:002022-09-29T15:36:44.725-05:00Golang - Reading multiline inputSince software inception, we always interact with user to ask their input and pass it along to the software to process. Golang provides multiple ways to read input from standard input, there are packages like <b style="font-style: italic;">bufio, ioutil, fmt</b> and many others which are used to accomplish the same ask. <div><div class="separator" style="clear: both; text-align: center;"><a href="https://raw.githubusercontent.com/atulsingh0/learning-golang/main/freeCodeCamp/36-reading-multiline-user-input.go" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="1154" data-original-width="973" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgro-y9ZmlcezztWj2lKTl9x1Wv6_gGTE4Tz1KEJrgffzsCHJgK8aRPwq9VZY103bKpba2y9d5D2d3DbNLogomakP1wNQl8Cmb0RMTB6DsWpXxymY80cPxF1GoDlnKSiuKg4ns3cSLlfwnj9XbGmWfnMQ_P5cQHjGYTuj1kG3BQuDL0FMB9koXP-jys/s320/golang11.png" width="270" /></a></div><span> </span><span> </span>When working with standard input (usually it's terminal) we often stumble-upon the scenario where we read which includes the new line as well. In happy world, Input ends when user press <i>Enter</i> but not always. In Golang world, by tweaking input reader logic, we can easily achieve that and that's the topic for today to snippet around. </div><div><br /></div><div>-<script src="https://atulsingh0.github.io/gist-it/embed-v2.js?target=https%3A%2F%2Fgithub.com%2Fatulsingh0%2Flearning-golang%2Fblob%2Fmain%2FfreeCodeCamp%2F36-reading-multiline-user-input.go&style=github-dark-dimmed&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on&showFullPath=on&showCopy=on"></script>-</div><div><br /></div><b>Output:</b><div><!--StartFragment--><pre><div 12px="" courier="" font-size:="" monospace="" new="" style="background-color: black;"><div><span style="color: #ff6ac1;">❯</span> <span style="color: #86b42b;">go</span><span style="color: white;"> run <span style="text-decoration-line: underline;">36-reading-multiline-user-input.go</span> </span></div><div><span style="color: white;">Enter Multiline Input: this is line1 </span></div><div><span style="color: white;">> this is line2 </span></div><div><span style="color: white;">> line3 </span></div><div><span style="color: white;">> </span></div><div><span style="color: white;">Input is: [this is line1 this is line2 line3] </span></div><div><span style="color: white;">No of lines in input: </span>3 </div></div></pre><!--EndFragment--><div><div class="separator" style="clear: both; text-align: center;"><br /></div>
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b><br />
</span></div></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-41746073226658316782022-09-29T10:51:00.002-05:002022-09-29T10:51:13.291-05:00Golang - Reading User input from TerminalReading input from terminal is one another common ask in all the programming languages, Golang deals this situation very elegantly and offer multiple solution to achieve the output. <div><div class="separator" style="clear: both; text-align: center;"><a href="https://raw.githubusercontent.com/atulsingh0/learning-golang/main/freeCodeCamp/35-reading-input.go" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="1392" data-original-width="1300" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhrJxQudRfBV6_rDVwgKLY16rTRYwZWFuI2oNhlJoQBzBb53oc4_4alJ2xWp4wME6XQfMMTiIC1poC1xx3cQnMjHALi3elLEGtYIY1mzFgyh11EaaaP1Qs_lMNRUeTGJRuH-2zt9pyLAEUKgQo1hGy-euKxvPd8JZJsVL1X4PBKQqeXHW9Yn4Z5rXf/w187-h200/golang12.png" width="187" /></a></div> For our tutorial, Scenario is somewhat like this - Ask user to enter 2 numbers and return the<a href="https://en.wikibooks.org/wiki/Algorithm_Implementation/Mathematics/Pythagorean_theorem" target="_blank"> Pythagorus output </a>:-), I've<a href="https://en.wikibooks.org/wiki/Algorithm_Implementation/Mathematics/Pythagorean_theorem" target="_blank"> linked the article</a> for a quick revision if forgot the basics. </div><div><br /></div><div>-<script src="https://atulsingh0.github.io/gist-it/embed-v2.js?target=https%3A%2F%2Fgithub.com%2Fatulsingh0%2Flearning-golang%2Fblob%2Fmain%2FfreeCodeCamp%2F35-reading-input.go&style=github-dark-dimmed&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on&showFullPath=on&showCopy=on"></script>-<br />
<br /><br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b><br /><br />
<br />
</span></div><br /><div class="separator" style="clear: both; text-align: center;"><br /></div><br /><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-12437271503682334702022-09-28T14:24:00.002-05:002022-09-28T14:24:49.032-05:00These Toolkits should be known to every developer<div class="separator" style="clear: both; text-align: center;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEheYhTqXlHyWo2PdqcDrTyRldlJS4apwEVMT912m0_Mp_wdt1uLpI6r2aiBKDYnSsFXZ6IhpT7DeuQfcFV6oFN544TlzpJR2OAlVBb6kKfyP9ZDV4NsEgaAygzkIYblw5MnuvC5m1T6GXJAGwdDOSDOo6rT1YKFjrG0nI6-mjWvNiUP1_MhO2dNUfXE" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img data-original-height="1072" data-original-width="1978" height="173" src="https://blogger.googleusercontent.com/img/a/AVvXsEheYhTqXlHyWo2PdqcDrTyRldlJS4apwEVMT912m0_Mp_wdt1uLpI6r2aiBKDYnSsFXZ6IhpT7DeuQfcFV6oFN544TlzpJR2OAlVBb6kKfyP9ZDV4NsEgaAygzkIYblw5MnuvC5m1T6GXJAGwdDOSDOo6rT1YKFjrG0nI6-mjWvNiUP1_MhO2dNUfXE=w320-h173" width="320" /></a></div><br /><div style="text-align: left;">Being in IT world, we use lot of tools in day to day life and it varies from dev to dev based on the work they are doing. These are few toolkits which I find very useful to do my stuff, Feel free to share tool which you find useful - </div><div style="text-align: left;"><br /></div><div style="text-align: left;">-<script src="https://gist.github.com/atulsingh0/ac0b8531bf3427e34ccc773f4d58f819.js"></script>-</div></div><br /><div class="separator" style="clear: both; text-align: center;"><br /></div><br /><br />
<br />
<br />
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b><br /><br />
<br />
</span><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-62129871191919703842022-09-27T22:29:00.005-05:002022-09-27T22:29:33.204-05:00Golang - Fetch file statsWhen working with files, it's very common to fetch the info about files and yet again <i style="font-weight: bold;">os </i>package becomes our saviour. In today's code snippet, We will see how to fetch file name, size, permission or mode, and check if it is a directory or a regular file - <div><div class="separator" style="clear: both; text-align: center;"><a href="https://go.dev/play/p/Knvmf4bq5w0" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="829" data-original-width="892" height="186" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieAaNTS2brB7JVDj9HGOmG80CYyVpcoeWBcPErsP0_T03afudPZ0pdPYKrR5ISvV464U46KmdAGPGRmca9gC74OdI8jdFzNNItyUVPU0ge8h9lItBzhsa9clU5-ECUzeE0wOeORSpGsnrNeYWpqwLC9QRd-a3oezGaIXynKtElVevb0nafKe2KbuZe/w200-h186/golang13.png" width="200" /></a></div><br /></div><div>-<script src="https://gist.github.com/atulsingh0/147dff3d16850600098bb7d552b10598.js?file=fetch-file-stats.go"></script>-<br />
<br />
<br />
<br />
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b><br /><br />
<br />
</span></div><br /><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-66878608416872768922022-09-27T11:10:00.007-05:002022-09-27T22:30:05.325-05:00Golang - Reading File at OnceOla amigos :) Hope, You are doing great. <div><div class="separator" style="clear: both; text-align: center;"><a href="https://go.dev/play/p/Q1aQHlJwwph" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="2000" data-original-width="2000" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR_URzq0ogQW8gqH45GNMOe6AI2pyE2wy3CWy_Lk7JpoWQrErST-QbjwkB_M9MlX91O6h1MKVeWDphTkLsST2Ld6Sr70BsPuDAHsH6CfK8Ugddb_kDd05UFfwxEtiuSqmpcSysima2eaowP-a28xrQLZBzWGeGZSLc8u9OKdANbx8CI6NpYxgyKbf8/w200-h200/golang8.png" width="200" /></a></div>So, Here, I am again with silly scrap which I see is done all the time and that is reading files. Today, we are going to see how to read a file in one go ;-) But before using this method, check if the file size is going to be small enough to fit into system's memory. We know, OS uses RAM (Random access memory) to store all temporary data which it requires frequently, so if you are going to read a file or anything which overshoot the RAM size, it is time to think how you can avoid that. </div><div>Hence, think before implementing any solution blindly cause it may work for any demos but might fail in real-time scenarios. Considering that, let's see how it is done in Golang world - </div><div><br /></div><div>-<script src="https://gist.github.com/atulsingh0/147dff3d16850600098bb7d552b10598.js?file=read-file.go"></script>-<br /><div><br />
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b><br /><br />
<br />
</span></div></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0tag:blogger.com,1999:blog-6073460760340389571.post-67221646561491005802022-09-20T17:56:00.002-05:002022-09-20T18:00:38.608-05:00Random Number Generation - GolangRandom number generation is pretty trivial ask in all the programming language, Python is having the easiest way (In my opinion) to generate the random number where I found little resistance in Golang but it doesn't mean Golang is lacking in someway :) So, let's check it out howz it done Go world - <div class="separator" style="clear: both; text-align: center;"><a href="https://go.dev/play/p/enEBiI2_5hd" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img border="0" data-original-height="480" data-original-width="480" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXtlc7oY32Ik3QPjTTdl4AIQ7pfIEqhM19uEqz7-uAMSPZA73Vgdv7ikFCj7gghnRDT7UyZOENppQxeFHbV0mTbAeyDacDwoC4dukOb0q28NWDBRtood5wmAcFL3zx2J9Vz9qGy6yKSeZXKriIo5DjGFKuyG6JKuUJCFwfNyOiOnhGbE0LuVTVYji5/w200-h200/golang7.png" width="200" /></a></div><br /><div><br /></div><div> <br />
<script src="https://gist.github.com/atulsingh0/e247ca8e8a1918a7abf021051bd07afd.js?file=sorted-random-no-list.go"></script>
<br />
<br />
<span style="font-family: Georgia, Times New Roman, serif;"></span>
<br />
<div class="MsoFootnoteText"></div>
<span style="font-family: Georgia, Times New Roman, serif;">
<b>Like the below page to get the update </b><br />
<b><a href="https://www.facebook.com/DataStage4you" target="_blank">Facebook Page</a>
<a href="https://www.facebook.com/groups/DataStage4you" target="_blank">Facebook Group</a>
<a href="https://twitter.com/datagenx">Twitter Feed</a>
<a href="http://bit.ly/2rdmcO7">Telegram Group</a></b><br /><br />
<br />
</span></div><div class="blogger-post-footer">http://feeds.feedburner.com/Datagenx</div>Atul Singhhttp://www.blogger.com/profile/09643920613196486931noreply@blogger.com0