<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged using</title>
<link>https://coderlegion.com/tag/using</link>
<description>Powered by Question2Answer</description>
<item>
<title>How does SSH work and how can it be set up?</title>
<link>https://coderlegion.com/16119/how-does-ssh-work-and-how-can-it-be-set-up</link>
<description>
&lt;p&gt;Hello, I'm Ganesh. I'm building &lt;em&gt;git-lrc&lt;/em&gt;, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Star Us&lt;/a&gt; to help devs discover the project. Do give it a try and share your feedback for improving the product.&lt;/p&gt;

&lt;p&gt;Secure Shell (SSH) is a cryptographic network protocol that allows you to operate network services securely over an unsecured network.&lt;/p&gt;

&lt;p&gt;It is most commonly used for logging into a remote terminal and executing commands.&lt;/p&gt;

&lt;h2&gt;
  
  
  How SSH Works
&lt;/h2&gt;

&lt;p&gt;SSH uses a &lt;strong&gt;client-server model&lt;/strong&gt; and relies on a suite of encryption technologies to ensure that data remains confidential and untampered.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The Handshake
&lt;/h3&gt;

&lt;p&gt;When we connect to a server, the two machines exchange supported encryption protocols and settle on a mutually compatible version. &lt;/p&gt;

&lt;p&gt;They also establish a session key using a process like the Diffie-Hellman algorithm, which allows them to create a shared secret without actually sending the key across the network.&lt;/p&gt;

&lt;p&gt;Here is the video explaining this process:&lt;br&gt;
&lt;a href=&quot;https://youtu.be/aoag03mSuXQ?t=729&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Link&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Authentication
&lt;/h3&gt;

&lt;p&gt;Once the encrypted channel is established, the server needs to verify who you are. This usually happens in one of two ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Password Authentication:&lt;/strong&gt; You send your password through the encrypted tunnel.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key-based Authentication:&lt;/strong&gt; The most secure method, using a &lt;strong&gt;Public Key&lt;/strong&gt; (stored on the server) and a &lt;strong&gt;Private Key&lt;/strong&gt; (stored on your machine).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  3. Encryption Layers
&lt;/h3&gt;

&lt;p&gt;SSH utilizes three different types of encryption:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Symmetrical Encryption:&lt;/strong&gt; Uses one key for both encryption and decryption of the entire session.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Asymmetrical Encryption:&lt;/strong&gt; Uses a public/private key pair (used primarily during the handshake and for authentication).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hashing:&lt;/strong&gt; Uses algorithms (like HMAC) to ensure data integrity, proving that the packets haven't been altered during transit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For let's setup simple RSA key pair for ubuntu server.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to Setup SSH
&lt;/h2&gt;

&lt;p&gt;Since we are using ubuntu server, we need to install the SSH server on the server.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1: Install the SSH Server
&lt;/h3&gt;

&lt;p&gt;Assuming you are in cloud console want to setup ssh on ubuntu.&lt;/p&gt;

&lt;p&gt;On the server, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt update
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;openssh-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check if it&amp;rsquo;s running:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;systemctl status ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Generate SSH Keys (Recommended)
&lt;/h3&gt;

&lt;p&gt;On your &lt;strong&gt;local machine&lt;/strong&gt;, generate a key pair. This is much safer than using a password.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;ssh-keygen &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; PEM &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; rsa &lt;span class=&quot;nt&quot;&gt;-b&lt;/span&gt; 4096 &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; ~/.ssh/private_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Press Enter to save it in the default location. &lt;/p&gt;

&lt;p&gt;You can add a passphrase for extra security.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;gk@jarvis:~&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ssh-keygen &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; PEM &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; rsa &lt;span class=&quot;nt&quot;&gt;-b&lt;/span&gt; 4096 &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; ~/.ssh/private_key
Generating public/private rsa key pair.
Enter passphrase &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;empty &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;no passphrase&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;: 
Enter same passphrase again: 
Your identification has been saved &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; /home/gk/.ssh/private_key
Your public key has been saved &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; /home/gk/.ssh/private_key.pub
The key fingerprint is:
SHA256:i3qqpQpyRkjDAdnbe++rN+ZCzak/4Ryzsn5vGJYEsVg gk@jarvis
The key&lt;span class=&quot;s1&quot;&gt;'s randomart image is:
+---[RSA 4096]----+
|o+    E.         |
|o o  o..         |
| + o. ..         |
|..o .   .        |
|. .  . +So       |
| .  . o.@.       |
|o o .o.*.B       |
|oo o .= % .      |
|..o.o++%=*.      |
+----[SHA256]-----+
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above output, we have generated a private key and public key.&lt;/p&gt;

&lt;p&gt;we can copy public key and save it in server&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Copy the Key to the Server
&lt;/h3&gt;

&lt;p&gt;Copy public key from local machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; ~/.ssh/private_key.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you are inside server either in temperary console or using password.&lt;/p&gt;

&lt;p&gt;Change directory to .ssh&lt;/p&gt;

&lt;p&gt;Add public key to authorized_keys file.&lt;/p&gt;

&lt;p&gt;This way server will trust your public key and you can login without a password.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Connect
&lt;/h3&gt;

&lt;p&gt;Now you can log in without a password:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;ssh username@remote_host_ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We understood how ssh works and how to setup ssh on server.&lt;/p&gt;

&lt;p&gt;I hope this article helps you to understand ssh and how to setup ssh on server.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabn6nl3iehrohehnxgje.png&quot; alt=&quot;git-lrc&quot; width=&quot;800&quot; height=&quot;373&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any feedback or contributors are welcome! It&amp;rsquo;s online, source-available, and ready for anyone to use. &lt;br&gt;
&amp;#11088; Star it on GitHub: &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://github.com/HexmosTech/git-lrc&lt;/a&gt;&lt;/p&gt;


</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/16119/how-does-ssh-work-and-how-can-it-be-set-up</guid>
<pubDate>Wed, 29 Apr 2026 05:42:27 +0000</pubDate>
</item>
<item>
<title>How to Connect a DHT11 to a NodeMCU v2 board?</title>
<link>https://coderlegion.com/14074/how-to-connect-a-dht11-to-a-nodemcu-v2-board</link>
<description>
&lt;p&gt;Hello, I'm Ganesh. I'm building &lt;em&gt;git-lrc&lt;/em&gt;, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Star Us&lt;/a&gt; to help devs discover the project. Do give it a try and share your feedback for improving the product.&lt;/p&gt;

&lt;p&gt;In this article, we will see how to work with DHT11 sensor with NodeMCU v2 using PlatformIO.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hardware Check
&lt;/h2&gt;

&lt;p&gt;We should always check datasheets before working with any hardware.&lt;/p&gt;

&lt;p&gt;So, by checking the datasheet of DHT11 and NodeMCU v2, we can determine how connection should be done and how to create firmware for it.&lt;/p&gt;

&lt;p&gt;You can check datasheets here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DHT11: &lt;a href=&quot;https://www.mouser.com/datasheet/2/758/DHT11-Technical-Data-Sheet-Translated-Version-1143054.pdf&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://www.mouser.com/datasheet/2/758/DHT11-Technical-Data-Sheet-Translated-Version-1143054.pdf&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;NodeMCU v2: &lt;a href=&quot;https://asset.conrad.com/media10/add/160267/c1/-/en/001408527DS01/datablad-1408527-seeed-studio-nodemcu-v2-lua-based-esp8266-development-kit-developmentboard.pdf&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://asset.conrad.com/media10/add/160267/c1/-/en/001408527DS01/datablad-1408527-seeed-studio-nodemcu-v2-lua-based-esp8266-development-kit-developmentboard.pdf&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Power Compatibility
&lt;/h3&gt;

&lt;p&gt;As per the datasheet of DHT11, it can operate on a supply range of &lt;strong&gt;3V to 5.5V DC&lt;/strong&gt;. &lt;br&gt;
Since the NodeMCU v2 runs on &lt;strong&gt;3.3V&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;You can power the sensor directly from the NodeMCU's &lt;strong&gt;3V3&lt;/strong&gt; pin. This keeps your build simple and safe without needing extra voltage regulators.&lt;/p&gt;

&lt;p&gt;Also they recommend to use a pull-up resistor of &lt;strong&gt;4.7K to 10K&lt;/strong&gt; between VDD and DATA pins.To make sure data is read properly.&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffuhyxk2uio7akhdi28pf.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffuhyxk2uio7akhdi28pf.png&quot; alt=&quot;&quot; width=&quot;715&quot; height=&quot;682&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Hardware Identification
&lt;/h3&gt;

&lt;p&gt;Check which version of the DHT11 you have. This changes how many pins you&amp;rsquo;ll be dealing with.&lt;/p&gt;

&lt;div class=&quot;table-wrapper-paragraph&quot;&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Bare DHT11 Sensor&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;DHT11 Module&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Appearance&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Blue plastic square with 4 metal pins.&lt;/td&gt;
&lt;td&gt;Sensor soldered onto a small PCB.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Pin Count&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;4 Pins.&lt;/td&gt;
&lt;td&gt;3 Pins.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Resistor&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Required.&lt;/strong&gt; You must add your own 4.7K to 10K resistor.&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Built-in.&lt;/strong&gt; Usually pre-soldered on the board.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Step-by-Step Wiring Guide
&lt;/h3&gt;
&lt;h4&gt;
  
  
  For the 4-Pin Bare Sensor
&lt;/h4&gt;

&lt;p&gt;If you are using the bare sensor, follow this pinout based on the official datasheet:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Pin 1 (VDD):&lt;/strong&gt; Connect to the &lt;strong&gt;3V3&lt;/strong&gt; pin on the NodeMCU.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Pin 2 (DATA):&lt;/strong&gt; Connect to a digital pin like &lt;strong&gt;D1&lt;/strong&gt; or &lt;strong&gt;D2&lt;/strong&gt;.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Crucial Step:&lt;/strong&gt; Place a &lt;strong&gt;4.7K to 10K pull-up resistor&lt;/strong&gt; between Pin 1 (VDD) and Pin 2 (DATA). This prevents the signal from &quot;floating&quot; and ensures stable data readings.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Pin 3 (NULL):&lt;/strong&gt; Leave this disconnected. It serves no electrical purpose.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Pin 4 (GND):&lt;/strong&gt; Connect to any &lt;strong&gt;GND&lt;/strong&gt; pin on the NodeMCU.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  For the 3-Pin Module
&lt;/h4&gt;

&lt;p&gt;If you have the module, life is even easier. The board is usually labeled:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;VCC (+):&lt;/strong&gt; Connect to &lt;strong&gt;3V3&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DATA (out):&lt;/strong&gt; Connect to &lt;strong&gt;D1&lt;/strong&gt; or &lt;strong&gt;D2&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GND (-):&lt;/strong&gt; Connect to &lt;strong&gt;GND&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Why the Pull-up Resistor Matters?
&lt;/h3&gt;

&lt;p&gt;Without a pull-up resistor, the DATA line doesn't have a clear &quot;High&quot; or &quot;Low&quot; state when the sensor isn't talking, which leads to erratic readings or &quot;Sensor not found&quot; errors.&lt;/p&gt;

&lt;p&gt;If you're using the bare sensor, don't skip the &lt;strong&gt;4.7K to 10K resistor&lt;/strong&gt; (though anything from 4.7K to 10K usually works in a pinch!).&lt;/p&gt;
&lt;h2&gt;
  
  
  Coding Your DHT11 with PlatformIO
&lt;/h2&gt;

&lt;p&gt;Now that the hardware is ready.&lt;/p&gt;

&lt;p&gt;Since we are using &lt;strong&gt;PlatformIO&lt;/strong&gt;, we&amp;rsquo;ll need to configure our project environment and use the industry-standard Adafruit library.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Configure &lt;code&gt;platformio.ini&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;First, we need to tell PlatformIO which board we are using and which library to download. Open your &lt;code&gt;platformio.ini&lt;/code&gt; file and ensure it looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight ini&quot;&gt;&lt;code&gt;&lt;span class=&quot;nn&quot;&gt;[env:nodemcuv2]&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;platform&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;espressif8266&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;board&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;nodemcuv2&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;framework&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;arduino&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;monitor_speed&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;115200&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;lib_deps&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; 
    &lt;span class=&quot;s&quot;&gt;adafruit/DHT sensor library @ ^1.4.6&lt;/span&gt;
    &lt;span class=&quot;err&quot;&gt;adafruit/Adafruit&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;Unified&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;Sensor&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;^1.1.14&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The &lt;code&gt;Adafruit Unified Sensor&lt;/code&gt; library is a hidden dependency that the DHT library needs to function correctly.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  2. The Main Code (&lt;code&gt;src/main.cpp&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;In your project&amp;rsquo;s &lt;code&gt;src&lt;/code&gt; folder, open &lt;code&gt;main.cpp&lt;/code&gt;. We&amp;rsquo;ll use a modified version of your snippet specifically tuned for the &lt;strong&gt;DHT11&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;Arduino.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&quot;DHT.h&quot;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Define the NodeMCU pin connected to the DHT11 data pin&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Using D2 (GPIO 4) as per our wiring guide&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#define DHTPIN D2     
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Since we are using the DHT11, we specify it here&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#define DHTTYPE DHT11   
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Initialize the DHT sensor&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;DHT&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DHTPIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DHTTYPE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Start serial communication at the speed defined in platformio.ini&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;begin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;115200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;F&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DHT11 Sensor Initializing...&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Start the sensor&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;begin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Wait 2 seconds between measurements. &lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// DHT11 is slower than modern sensors; don't rush it!&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Reading temperature or humidity takes about 250 milliseconds!&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readHumidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readTemperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Celsius&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readTemperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Fahrenheit&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Check if any reads failed&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isnan&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isnan&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isnan&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;F&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Failed to read from DHT sensor! Check your wiring.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Compute heat index (how it actually feels)&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hic&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;computeHeatIndex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Print results to the Serial Monitor&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;F&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Humidity: &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;F&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%  |  Temp: &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;F&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;deg;C  |  Heat Index: &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;F&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;deg;C&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight plaintext&quot;&gt;&lt;code&gt;DHT11 Sensor Initializing...
Humidity: 45.00 %  |  Temp: 25.00&amp;deg;C  |  Heat Index: 25.00&amp;deg;C
Humidity: 46.00 %  |  Temp: 25.12&amp;deg;C  |  Heat Index: 25.12&amp;deg;C
Humidity: 45.00 %  |  Temp: 25.25&amp;deg;C  |  Heat Index: 25.25&amp;deg;C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Key Adjustments for the DHT11
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DHTTYPE:&lt;/strong&gt; Ensure this is set to &lt;code&gt;DHT11&lt;/code&gt;. While the code for a DHT22 is almost identical, the timing and data conversion logic inside the library are different for these two models.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sampling Rate:&lt;/strong&gt; The DHT11 has a sampling rate of about &lt;strong&gt;1Hz&lt;/strong&gt; (one reading per second). Using a &lt;code&gt;delay(2000)&lt;/code&gt; (2 seconds) is a &quot;safe bet&quot; to ensure you don't get stale data or errors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accuracy Note:&lt;/strong&gt; Don't be surprised if the readings are slightly different from your home thermostat. The DHT11 is an entry-level sensor with an accuracy of &lt;strong&gt;&amp;plusmn;2&amp;deg;C&lt;/strong&gt; for temperature and &lt;strong&gt;&amp;plusmn;5%&lt;/strong&gt; for humidity.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We could able to connect DHT11 sensor with NodeMCU v2 using PlatformIO and read temperature and humidity values.&lt;/p&gt;

&lt;p&gt;In next article we will learn different sensor.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabn6nl3iehrohehnxgje.png&quot; alt=&quot;git-lrc&quot; width=&quot;800&quot; height=&quot;373&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any feedback or contributors are welcome! It&amp;rsquo;s online, source-available, and ready for anyone to use. &lt;br&gt;
&amp;#11088; Star it on GitHub: &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://github.com/HexmosTech/git-lrc&lt;/a&gt;&lt;/p&gt;


</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/14074/how-to-connect-a-dht11-to-a-nodemcu-v2-board</guid>
<pubDate>Tue, 14 Apr 2026 20:49:32 +0000</pubDate>
</item>
<item>
<title>Introduction to Go generics?</title>
<link>https://coderlegion.com/13377/introduction-to-go-generics</link>
<description>
&lt;p&gt;&lt;em&gt;Hello, I'm Ganesh Kumar. I'm working on &lt;a href=&quot;https://hexmos.com/livereview/git-lrc/&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;git-lrc&lt;/a&gt;: a Git hook for Checking AI generated code.AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In my previous post, I explained how to work with an interface.&lt;/p&gt;

&lt;p&gt;Now let's understand go generics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is Go Generics needed?
&lt;/h2&gt;

&lt;p&gt;Before I start explaining go generics, let me give an example of a simple code without using go generics.&lt;/p&gt;

&lt;p&gt;Let's have a simple function for finding the index of the element.&lt;br&gt;
We can see that both internal workings are the same, but the parameters and return variable types are different&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight go&quot;&gt;&lt;code&gt;


&lt;span class=&quot;k&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;



&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IndexInt&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;range&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; 
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IndexString&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;range&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; 
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;integer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;45&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IndexInt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;integer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; 

    &lt;span class=&quot;n&quot;&gt;strings&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;hello&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;world&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IndexString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;example&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; 
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As we can see, both are working in the same way.&lt;br&gt;
Output:&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;gk@jarvis:~/exp/code/rd/go-exmaple&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;go run main.go 
3
&lt;span class=&quot;nt&quot;&gt;-1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So, why can't we have a single function that does the same task with passing different types? This is how go generics play a major role in this.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Go Generics?
&lt;/h2&gt;

&lt;p&gt;It is a feature that allows developers to write reusable, type-safe code that works with multiple types.&lt;/p&gt;

&lt;p&gt;That means we can use Go generics to solve our problem.&lt;/p&gt;

&lt;p&gt;In the example below, we will solve the above problem. &lt;/p&gt;
&lt;h2&gt;
  
  
  Using Go Generics
&lt;/h2&gt;

&lt;p&gt;There are many constraints to using go generics.&lt;/p&gt;

&lt;p&gt;For our case let's just use a &lt;code&gt;comparable&lt;/code&gt; constraint.&lt;/p&gt;

&lt;p&gt;let't create function &lt;code&gt;Index&lt;/code&gt; with &lt;code&gt;[T comparable]&lt;/code&gt; with using T as type.&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight go&quot;&gt;&lt;code&gt;
&lt;span class=&quot;k&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;



&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;comparable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;range&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; 
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;integer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;45&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;integer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; 

    &lt;span class=&quot;n&quot;&gt;strings&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;hello&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;world&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;example&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; 
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As we expected, we got the same results with one function.&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;gk@jarvis:~/exp/code/rd/go-exmaple&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;go run main.go 
3
&lt;span class=&quot;nt&quot;&gt;-1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Go Generics was introduced recently we might be using it in a few cases where it is necessary.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://hexmos.com/livereview/git-lrc/&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fifqf83t1qjl4u0g6aj4l.png&quot; alt=&quot;git-lrc&quot; width=&quot;800&quot; height=&quot;381&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; Check out: &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;git-lrc&lt;/a&gt;&lt;br&gt;
Any feedback or contributors are welcome! It&amp;rsquo;s online, open-source, and ready for anyone to use.&lt;br&gt;
&amp;#11088; Star it on GitHub:&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;ltag-github-readme-tag&quot;&gt;
  &lt;div class=&quot;readme-overview&quot;&gt;
    &lt;h2&gt;
      &lt;img src=&quot;https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg&quot; alt=&quot;GitHub logo&quot;&gt;
      &lt;a href=&quot;https://github.com/HexmosTech&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;
        HexmosTech
      &lt;/a&gt; / &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;
        git-lrc
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Free, Unlimited AI Code Reviews That Run on Commit
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class=&quot;ltag-github-body&quot;&gt;
    
&lt;div id=&quot;readme&quot; class=&quot;md&quot;&gt;
&lt;div&gt;
&lt;a rel=&quot;noopener noreferrer nofollow&quot; href=&quot;https://camo.githubusercontent.com/948c8f2d5cf41b48985cd364d48c3a2dc9bfbfd42eab3e0a9a1b3e61f5f17ce3/68747470733a2f2f6865786d6f732e636f6d2f66726565646576746f6f6c732f7075626c69632f6c725f6c6f676f2e737667&quot;&gt;&lt;img width=&quot;60&quot; alt=&quot;git-lrc logo&quot; src=&quot;https://camo.githubusercontent.com/948c8f2d5cf41b48985cd364d48c3a2dc9bfbfd42eab3e0a9a1b3e61f5f17ce3/68747470733a2f2f6865786d6f732e636f6d2f66726565646576746f6f6c732f7075626c69632f6c725f6c6f676f2e737667&quot;&gt;&lt;/a&gt;
&lt;p&gt;&lt;strong&gt;git-lrc&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Free, Unlimited AI Code Reviews That Run on Commit&lt;/strong&gt;&lt;/p&gt;
&lt;br&gt;
&lt;/div&gt;



&lt;div&gt;
&lt;a href=&quot;https://www.producthunt.com/products/git-lrc?embed=true&amp;amp;utm_source=badge-top-post-badge&amp;amp;utm_medium=badge&amp;amp;utm_campaign=badge-git-lrc&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;&lt;img alt=&quot;git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt&quot; width=&quot;250&quot; height=&quot;54&quot; src=&quot;https://camo.githubusercontent.com/87bf2d4283c1e0aa99e254bd17fefb1c67c0c0d39300043a243a4aa633b6cecc/68747470733a2f2f6170692e70726f6475637468756e742e636f6d2f776964676574732f656d6265642d696d6167652f76312f746f702d706f73742d62616467652e7376673f706f73745f69643d31303739323632267468656d653d6c6967687426706572696f643d6461696c7926743d31373731373439313730383638&quot;&gt;&lt;/a&gt;
&lt;/div&gt;




&lt;p&gt;AI agents write code fast. They also &lt;em&gt;silently remove logic&lt;/em&gt;, change behavior, and introduce bugs -- without telling you. You often find out in production.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;git-lrc&lt;/code&gt; fixes this.&lt;/strong&gt; It hooks into &lt;code&gt;git commit&lt;/code&gt; and reviews every diff &lt;em&gt;before&lt;/em&gt; it lands. 60-second setup. Completely free.&lt;/p&gt;

&lt;div class=&quot;markdown-heading&quot;&gt;
&lt;h2 class=&quot;heading-element&quot;&gt;See It In Action&lt;/h2&gt;
&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;See git-lrc catch serious security issues such as leaked credentials, expensive cloud
operations, and sensitive material in log statements&lt;/p&gt;
&lt;/blockquote&gt;


  
    

    &lt;span class=&quot;m-1&quot;&gt;git-lrc-intro-60s.mp4&lt;/span&gt;
  

  

  


&lt;div class=&quot;markdown-heading&quot;&gt;
&lt;h2 class=&quot;heading-element&quot;&gt;Why&lt;/h2&gt;

&lt;/div&gt;


&lt;ul&gt;

&lt;li&gt; &lt;strong&gt;AI agents silently break things.&lt;/strong&gt; Code removed. Logic changed. Edge cases gone. You won't notice until production.&lt;/li&gt;

&lt;li&gt; &lt;strong&gt;Catch it before it ships.&lt;/strong&gt; AI-powered inline comments show you &lt;em&gt;exactly&lt;/em&gt; what changed and what looks wrong.&lt;/li&gt;

&lt;li&gt; &lt;strong&gt;Build a habit, ship better code.&lt;/strong&gt; Regular review &amp;rarr; fewer bugs &amp;rarr; more robust code &amp;rarr; better results in your team.&lt;/li&gt;

&lt;li&gt; &lt;strong&gt;Why git?&lt;/strong&gt; Git is universal. Every editor, every IDE, every AI&amp;hellip;&lt;/li&gt;

&lt;/ul&gt;
&lt;/div&gt;
&lt;br&gt;
  &lt;/div&gt;
&lt;br&gt;
  &lt;div class=&quot;gh-btn-container&quot;&gt;&lt;a class=&quot;gh-btn&quot; href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;



</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/13377/introduction-to-go-generics</guid>
<pubDate>Mon, 30 Mar 2026 21:36:35 +0000</pubDate>
</item>
<item>
<title>Using the Internet Securely</title>
<link>https://coderlegion.com/1552/using-the-internet-securely</link>
<description>
&lt;p&gt;The internet is a powerful tool, but it comes with risks. Securing your online presence is essential to protect your data, privacy, and communications. One of the most effective tools for encryption and authentication is &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://gnupg.org/&quot;&gt;GNU Privacy Guard (GnuPG)&lt;/a&gt;&lt;/strong&gt;, which implements the &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://en.wikipedia.org/wiki/Pretty_Good_Privacy&quot;&gt;Pretty Good Privacy (PGP) - Wikipedia&lt;/a&gt;&lt;/strong&gt; standard. This guide covers the basics of GPG/PGP keys and general security practices for safer internet usage.&lt;/p&gt;
&lt;h2&gt;Understanding GPG/PGP Keys&lt;/h2&gt;
&lt;p&gt;PGP and GPG use public-key cryptography to encrypt and sign data. Each user has a &lt;strong&gt;key pair&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Public Key&lt;/strong&gt;: Shared with others to encrypt messages for you.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Private Key&lt;/strong&gt;: Kept secret and used to decrypt messages and sign data.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;By using GPG, you can send encrypted emails, verify software integrity, and authenticate communications.&lt;/p&gt;
&lt;h2&gt;Generating a GPG Key&lt;/h2&gt;
&lt;p&gt;To create a new GPG key:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Install GPG:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Linux/macOS: Check installation with &lt;code&gt;gpg --version&lt;/code&gt;. If not installed, install it using:
&lt;ul&gt;
&lt;li&gt;macOS: &lt;code&gt;brew install gnupg&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Linux (Debian-based): &lt;code&gt;sudo apt install gnupg&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Windows: Use &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.gpg4win.org/&quot;&gt;Gpg4win&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Generate a key:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;gpg --full-generate-key
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Follow the prompts to select key type, size, and expiration.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Export your public key:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;gpg --export --armor your@email.com &amp;gt; publickey.asc
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Share the public key so others can encrypt messages for you. You can upload it to a keyserver like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://keyserver.ubuntu.com/&quot;&gt;keyserver.ubuntu.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://keys.openpgp.org/&quot;&gt;keys.openpgp.org&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Encrypting and Signing Messages&lt;/h2&gt;
&lt;p&gt;To &lt;strong&gt;encrypt&lt;/strong&gt; a message:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;echo &quot;Confidential message&quot; | gpg --encrypt --armor -r recipient@email.com
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To &lt;strong&gt;sign&lt;/strong&gt; a message:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;echo &quot;Important document&quot; | gpg --clearsign
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To &lt;strong&gt;verify&lt;/strong&gt; a signed message:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;gpg --verify message.asc
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For more details, refer to the &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.gnupg.org/documentation/manuals/gnupg.pdf&quot;&gt;GPG Command Line Guide&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;General Internet Security Practices&lt;/h2&gt;
&lt;h3&gt;Use Strong, Unique Passwords&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Avoid reusing passwords across different sites.&lt;/li&gt;
&lt;li&gt;Use a password manager to store and generate strong passwords.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Recommended Password Manager&lt;/strong&gt;: &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.passwordstore.org/&quot;&gt;GNU Pass&lt;/a&gt;&lt;/strong&gt; (A simple command-line password manager using GPG encryption).&lt;/li&gt;
&lt;li&gt;Alternative: &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://keepassxc.org/&quot;&gt;KeePassXC&lt;/a&gt;&lt;/strong&gt; (A libre, cross-platform password manager).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Secure Your Email and Communications&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Use end-to-end encrypted email services like &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://proton.me/&quot;&gt;ProtonMail&lt;/a&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Consider self-hosted email solutions for full privacy, such as &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://snappymail.eu/&quot;&gt;SnappyMail&lt;/a&gt;&lt;/strong&gt; (a lightweight, privacy-focused webmail client).&lt;/li&gt;
&lt;li&gt;Prefer encrypted messaging apps like &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://element.io/&quot;&gt;Element&lt;/a&gt;&lt;/strong&gt; (Matrix-based).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Keep Software Updated&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Regularly update your &lt;strong&gt;operating system&lt;/strong&gt;, &lt;strong&gt;browser&lt;/strong&gt;, and &lt;strong&gt;software&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Avoid using outdated plugins and extensions that may introduce vulnerabilities.&lt;/li&gt;
&lt;li&gt;Enable &lt;strong&gt;automatic updates&lt;/strong&gt; wherever possible.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Browse the Web Safely&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Always use &lt;strong&gt;HTTPS&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Avoid clicking on suspicious links or downloading unknown attachments.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use a &lt;strong&gt;privacy-focused browser&lt;/strong&gt; like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://librewolf.net/&quot;&gt;LibreWolf&lt;/a&gt;&lt;/strong&gt; (A hardened fork of Firefox with enhanced privacy settings).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.torproject.org/&quot;&gt;Tor Browser&lt;/a&gt;&lt;/strong&gt; (For anonymous browsing via the Tor network).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.mozilla.org/en-US/firefox/&quot;&gt;Firefox&lt;/a&gt;&lt;/strong&gt; (Configure it for privacy).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Consider using a &lt;strong&gt;libre VPN&lt;/strong&gt; like &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://mullvad.net/&quot;&gt;Mullvad&lt;/a&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://riseup.net/en/vpn&quot;&gt;Riseup VPN&lt;/a&gt;&lt;/strong&gt; to hide your IP address and encrypt traffic.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Verify Software Integrity&lt;/h3&gt;
&lt;p&gt;When downloading software, always check its authenticity by verifying its GPG signature:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;gpg --verify software.sig software.tar.gz
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Most open-source projects provide GPG signatures for their releases, which can be verified against their &lt;strong&gt;public keys&lt;/strong&gt;. Check the project's official website for details.&lt;/p&gt;
&lt;p&gt;For example, verifying a &lt;strong&gt;Arch Linux ISO&lt;/strong&gt; download:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Download the public key:&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;gpg --recv-keys 3E80CA1A8B89F69CBA57D98A76A5EF9054449A5C
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Verify the signature:&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;gpg --verify archlinux-2025.03.01-x86_64.iso.sig archlinux-2025.03.01-x86_64.iso
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Online security is an ongoing effort. By using &lt;strong&gt;GPG for encryption and authentication&lt;/strong&gt;, along with adopting &lt;strong&gt;strong security habits&lt;/strong&gt;, you can significantly reduce your risk of data theft and surveillance. Stay informed, keep your software updated, and be cautious when sharing information online.&lt;/p&gt;
&lt;p&gt;For further learning:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.gnupg.org/documentation/manuals/gnupg.pdf&quot;&gt;GPG Manual&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.privacyguides.org/&quot;&gt;Privacy Guides - Free and Open-Source Privacy Resources&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/1552/using-the-internet-securely</guid>
<pubDate>Tue, 18 Mar 2025 21:50:36 +0000</pubDate>
</item>
</channel>
</rss>