<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[The Glitcher - Medium]]></title>
        <description><![CDATA[Everything under the Computer science - Medium]]></description>
        <link>https://medium.com/the-glitcher?source=rss----56671f365349---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>The Glitcher - Medium</title>
            <link>https://medium.com/the-glitcher?source=rss----56671f365349---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 00:39:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/the-glitcher" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Transformer Architecture: A Deep Dive into How LLMs Actually Work]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/the-glitcher/dithe-transformer-architecture-167451e70f7c?source=rss----56671f365349---4"><img src="https://cdn-images-1.medium.com/max/1536/0*mHyCkq2oUA3ygja9" width="1536"></a></p><p class="medium-feed-snippet">Originally published at pranaybathini.com/learn/llmfundamentals/transformer-architecture</p><p class="medium-feed-link"><a href="https://medium.com/the-glitcher/dithe-transformer-architecture-167451e70f7c?source=rss----56671f365349---4">Continue reading on The Glitcher »</a></p></div>]]></description>
            <link>https://medium.com/the-glitcher/dithe-transformer-architecture-167451e70f7c?source=rss----56671f365349---4</link>
            <guid isPermaLink="false">https://medium.com/p/167451e70f7c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Pranay Bathini]]></dc:creator>
            <pubDate>Sat, 27 Dec 2025 18:54:31 GMT</pubDate>
            <atom:updated>2025-12-27T18:56:28.521Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Creating Loot Royale NFT Collection DApp]]></title>
            <link>https://medium.com/the-glitcher/creating-an-loot-royale-nft-collection-dapp-e9b5e43452c6?source=rss----56671f365349---4</link>
            <guid isPermaLink="false">https://medium.com/p/e9b5e43452c6</guid>
            <category><![CDATA[nft]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Pranay Bathini]]></dc:creator>
            <pubDate>Sun, 20 Feb 2022 18:34:58 GMT</pubDate>
            <atom:updated>2022-02-20T18:35:09.051Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*INgAk83zy92JocdW4HLiYw.jpeg" /><figcaption>Loot Royale DApp</figcaption></figure><h3>Introduction</h3><p>In this series of blogs, I am going to show how to create an on chain and off chain NFT collection smart contract and create a DApp to mint NFTs.</p><p>I am also going to show how to create your own DApp which I designed for fun last year and also to learn about NFTs and DApps.</p><h3>Idea</h3><p>The idea to create an NFT DApp is inspired from the loot project but I also want to add my own flavors of creativity to it and understand the working of smart contracts in the process.</p><h3>Learning</h3><p>Before this , I tried out different things like building my <a href="https://www.thecryptoinsight.com/2021/07/how-to-create-your-own-cryptocurrency-on-ethereum.html">own token on Ethereum test network</a> back in July, 2021 when I am new to cryptocurrency space and understanding little things like how <a href="https://www.pranaybathini.com/2021/05/merkle-tree.html">merkle tree</a> is used.</p><p>It is this time when I learned about <a href="https://remix.ethereum.org/">remix IDE</a>, MetaMask wallet, different test networks of Ethereum blockchain, deploying smart contracts through remix IDE. I also learned little things like we can deploy the same contract which deployed on Ethereum blockchain on other blockchains <a href="https://www.thecryptoinsight.com/2021/07/how-to-create-your-own-cryptocurrency-on-binance-smart-chain.html">like Binance Smart Chain</a>.</p><p>I have decided what to build but don’t know how. I began exploring some resources with little knowledge and found this <a href="https://cryptomarketpool.com/getting-started-with-solidity/">solidity tutorial</a> from a reddit post.</p><p>I have gone through the solidity basics to understand code from verified smart contracts and to develop new ones.</p><h3>Smart Contract Development</h3><p>After getting a bit of knowledge on solidity, I began exploring the smart contract of loot project. It didn’t make much sense but after spending some time with it, I understood the working.</p><p>I know ERC-721 standard is used to build NFTs and ERC-20 standard to build our own token on Ethereum block chain but don’t know what functions exactly we need to define in those standards.</p><p>I referred <a href="https://openzeppelin.com/">openzeppelin docs</a> to understand more about the functions in the ERC-721. So, without any further journey lessons, I will jump into smart contract development.</p><p>To develop our own NFT smart contract, we require</p><h4><a href="https://docs.openzeppelin.com/contracts/2.x/api/ownership#Ownable">Ownable</a> Smart contract</h4><ul><li>It is used to manage the ownership of the contract. By default, the owner of a smart contract is the address from which it is deployed.</li><li>It has functions that lets transfer ownership of the contract to other address using[transferOwnership(newOwner)](&lt;https://docs.openzeppelin.com/contracts/2.x/api/ownership#Ownable-transferOwnership-address-&gt;) method.</li><li>It lets you renounce your ownership of the contract with [renounceOwnership()](&lt;https://docs.openzeppelin.com/contracts/2.x/api/ownership#Ownable-renounceOwnership--&gt;)</li><li>It provides [onlyOwner()](&lt;https://docs.openzeppelin.com/contracts/2.x/api/ownership#Ownable-onlyOwner--&gt;) modifier to let some functions get executed by only owner like starting the sale, pausing the contract, Give away NFTs from the contract.</li></ul><h4><a href="https://docs.openzeppelin.com/contracts/4.x/api/token/erc721#ERC721Enumerable">Enumerable721</a> Smart contract</h4><ul><li>It extends <a href="https://docs.openzeppelin.com/contracts/2.x/api/token/erc721">ERC721 standards</a>, so we don’t need our contract to extend ERC721 contract explicitly.</li><li>This provides enumerability of all the token ids in the contract as well as all token ids owned by each account.</li><li>See the functions provided by it the he <a href="https://docs.openzeppelin.com/contracts/4.x/api/token/erc721#ERC721Enumerable">documentation</a>.</li></ul><h4><a href="https://docs.openzeppelin.com/contracts/4.x/api/security#ReentrancyGuard">ReentrancyGuard</a> Smart Contract</h4><ul><li>This module that helps prevent reentrant calls to a function meaning it makes [nonReentrant](&lt;https://docs.openzeppelin.com/contracts/4.x/api/security#ReentrancyGuard-nonReentrant--&gt;)modifier available, which can be applied to functions to make sure there are no nested (reentrant) calls to them.</li><li>Functions marked as nonReentrant may not call one another.</li></ul><h4><a href="https://docs.openzeppelin.com/contracts/4.x/api/security#Pausable">Pausable</a> Smart Contract</h4><ul><li>It is also advisable to extend this one which allows child contracts to implement an emergency stop mechanism that can be triggered by an authorized account.</li><li>This used through inheritance and makes modifiers whenNotPaused and whenPaused available which can be applied to the functions of your contract.</li></ul><p>We can make our main smart contract extend these smart contracts directly by importing these in our code.</p><p>The code is found here for Loot Royale Onchain NFT Smart Contract — <a href="https://gist.github.com/pranaybathini/52f4ff2da4c3518855264febe7d95739">Loot Royale On chain NFT Collection Smart contract code</a>. Please open this in new tab to follow along.</p><p>Let us discuss about the functions inside the main smart contract — <strong>BattleRoyale.sol</strong></p><p>Three functions are important.</p><ol><li>Function to let the users mint NFT Tokens by paying required amount of price for the NFTs they are minting.</li><li>Function to get the token URI of the NFT. This takes in token Id and gives a JSON with the NFT. Here in our case, it is an SVG image generated from the code — On Chain. No external calls required.</li><li>Function to get the amount from the contract address to your own address or any address you want to withdraw. I wrote the function to withdraw to owner address of the smart contract.</li></ol><h3>NFT Design for on chain smart contract</h3><p>Here is one of my NFTs look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*Eqy-dgqGnaDr-ykU6UvFEw.jpeg" /></figure><p>A simple HTML CSS Design inside svg tag with curved border and it also displays the token ID at the top. It took some time for me to realize that we can include html CSS inside svg tag. Initially, I took the HTML CSS code and used <a href="https://www.hiqpdf.com/demo/ConvertHtmlToSvg.aspx">this site</a> to convert to SVG but the output svg size is very heavy.</p><p>Another problem I faced while storing this data for design was that the max size of a smart contract cannot be more than <strong>24576</strong> bytes. So, I moved the code to another smart contract then to library, just so to reuse it in another contract. This is just one line but took some time since I tried optimizing it first before realizing I can do move this to another contract. Learning++.</p><p>Here is the link to <a href="https://gist.github.com/pranaybathini/d3875355c93e726899c5104cb388cb66?short_path=a38f07c">SVG Code for the above NFT.</a></p><p>Also, you can see my data in the code which is different from loot project. You should have guessed it by now where did I get my data from. Now lets see what are on chain vs off chain NFTs.</p><h3>On chain vs Off chain NFTs</h3><p>The difference between on chain and off chain NFTs as the name suggest we will be storing all the data related to NFTs on the blockchain itself for on chain NFTs.</p><p>In case of off chain, I need to provide some external URLs like <a href="https://somedomain.com/">https://</a><a href="http://somedomain.com/">somedomain.com</a> , ipfs://sha256hash/1.png.</p><p>In both cases, I need to return the JSON output file following <a href="https://docs.metaplex.com/token-metadata/Versions/v1.0.0/nft-standard">NFT metadata standard.</a></p><p>A sample IPFS image URL looks like this — ipfs://QmV3yGkzx2Uw3NHPZV9SAMLA58j7LvCFLFYtyfCMBAvstF/2.jpg</p><p>You can open this in brave browser directly — a pin I have drawn on art flow mobile app long time back.</p><p>If we were to create off chain NFTs, how would the code look like?</p><p>Refer <a href="https://gist.github.com/pranaybathini/dbb8c34dfbed1720f33960669342148b">this github gist link for offchain smart contract.</a></p><p>I will set the IPFS or HTTPS BASE URI in the contract when the sale starts or now a days, the developers are revealing the NFTs after all NFTs are minted.</p><p>It is simple to write a function to set URI variable and call it once all NFTs are minted.</p><p>There are two variables</p><ol><li>Base URI — actual URI for NFTs</li><li>Blind URI — Till we reveal the NFTs, this image or video will be same for all the minted NFTs.</li></ol><p>The URI we should set will be like ipfs://QmV3yGkzx2Uw3NHPZV9SAMLA58j7LvCFLFYtyfCMBAvstF/</p><p>When we query, our token Id gets appended to it and Open Sea or any other market place can find and display it.</p><p>Starting steps are to set the contract active, then set the blind URI. Once all NFTs are minted, you can reveal the NFTs minted.</p><p>The tokenURI method output will look like</p><pre>{<br>    &quot;image&quot;: &quot;ipfs://QmV3yGkzx2Uw3NHPZV9SAMLA58j7LvCFLFYtyfCMBAvstF/1.png&quot;,<br>    &quot;name&quot;: &quot;Loot Royale 1&quot;,<br>    &quot;description&quot; : &quot;Some description&quot;<br>}</pre><h3>Compiling and Deploying to blockchain</h3><p>Now we have our contracts, how do we deploy them to the blockchain network. Many blockchains forked Ethereum with added changes to bring DApp development features. You can deploy to any network that supports solidity.</p><p>Let us deploy this on chain NFT smart contract to Ethereum’s Ropsten test network. But before that, we need</p><ol><li>Remix IDE — You can use it online. Simply click <a href="https://remix.ethereum.org/">https://remix.ethereum.org/</a>. In case you want to run it offline, you can refer <a href="https://www.thecryptoinsight.com/2021/07/how-to-create-your-own-cryptocurrency-on-ethereum.html">this blog on how to download it on docker and run it.</a></li><li>Metamask wallet — If you don’t have metamask wallet, follow <a href="https://www.thecryptoinsight.com/2021/06/how-to-create-an-ethereum-wallet-using-metamask.html">this blog to install metamask wallet in the browser of your choice.</a> If you are using brave, it is inbuilt within the browser. You can access it from settings.</li><li>Get some Ropsten testnet ether/ Rinkeby testnet ether/ Polygon testnet Matic to deploy the contract on the ropsten network. Change the network to ropsten on metamask.</li><li><a href="https://faucet.ropsten.be/">https://faucet.ropsten.be/</a> — Ropsten Testnet Faucet</li><li><a href="https://faucet.polygon.technology/">https://faucet.polygon.technology/</a> — Polygon testnet faucet</li><li>If you deploy on Rinkeby testnet or polygon testnet you will be able to see your NFTs on opensea testnetwork. Next steps are same for all the networks.</li></ol><h4>Next steps</h4><ul><li>Copy the contract to your remix IDE. It should look like below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vminuTcdxptozGlUvnR3GA.jpeg" /><figcaption>Remix IDE</figcaption></figure><ul><li>You can select the compiler version to any version above 8.0 But remember this version which you used to compile. This is needed while verifying contract on the block explorer.</li><li>In case you don’t know what is a block explorer, refer <a href="https://www.thecryptoinsight.com/2021/08/block-explorers-how-to-use-a-block-explorer.html">this blog to understand in detail.</a></li><li>Go to compiler tab and click on compile. You should see a green tick mark like below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uYv8bUkVTFY7bwF1ICj5KQ.jpeg" /></figure><ul><li>Go to deploy tab. You should select the contract as BattleRoyale.sol</li><li>By Default, the environment will be Javascript VM. All the transactions will be executed in a sandbox blockchain in the browser. This means nothing will be persisted when you reload the page. The Javascript VM is its own blockchain and on each reload it will start a new blockchain, the old one will not be saved.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J7_slHF7dboh-3XhKRR-LA.jpeg" /></figure><ul><li>You need to select Injected Web3 as environment, which will allow us to inject metamask and deploy to the network selected on metamask. You should be able to see the your metamask account and balance in the accounts section.</li><li>When you click on deploy, you will be prompted twice. First the CardDesign Library is deployed and then our smart contract.</li><li>You will receive two metamask notifications once the contracts deployed. Click on them, you will be redirected to Ropsten block explorer. You can also view the transactions from activity tab in metamask.</li><li>Congrats, now the On chain NFT smart contract — loot royale has been deployed.</li></ul><p>But how do we interact with it. I will explain in detail on how to interact it from our custom react frontend later. Let’s see how to interact with the contract from the block explorer.</p><p>FYI, block explorer is also a DApp.</p><h3>Verifying the contract on blockchain Explorer</h3><p>Now, let us verify the contract on the block chain explorer and interact with it from the explorer itself.</p><ul><li>Open contract addresses of Card Design Library in one tab (We require this address), Open the contract address of the Loot Royale contract in another tab like below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NTCKYgZ04Lr7SVvnfGM7zA.jpeg" /></figure><ul><li>Click on verify and Publish and fill the details as below. I used 8.7 as compiler version while deploying from remix, so I am using the same here. Click on continue.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ef0UTo3lMmSweuG3PVQBw.jpeg" /></figure><ul><li>Copy the code from remix IDE and paste in the code part. Remove the string from constructor part like below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XNnxS7L96cg7GcRY7mUclw.jpeg" /></figure><ul><li>Enter the library address as below and verify you are not a robot and click on Verify and publish.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O8Lex5Co2ygSmU5d4LckhA.jpeg" /></figure><p>Now, our contract is verified. It looks like below image. You should see the functions to read and write to blockchain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CDbPlY_yheZRBQSiY-PYlg.jpeg" /></figure><p>Navigate to write contract section and click on connect to web3, you will be prompted to connect to a provider like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ALKub6RY39QZL25QE14lvQ.jpeg" /></figure><p>Click on Metamask, it will prompt to connect. Click on connect to web3 again and you should be able to connect explorer with Metamask like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1OFqZpijK1Zm6sIGS-u_8g.jpeg" /></figure><p>Now click on mintSingle function, it will an NFT. Enter 0.01 as NFT Price like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tMDeN6MUjWaOd9XTbANjfg.jpeg" /></figure><p>Congratulations. You have successfully minted an NFT. Now, lets view the token URI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oZeuqyE1E9yoMoopx9VEcg.jpeg" /></figure><p>You can go to <a href="https://testnets.opensea.io/">testnets.opensea.io</a>, connect your wallet and you should be able to see your Loot Royale NFTs.</p><h3>Loot Royale NFTs on Open sea Testnet</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ghtHBBThoLjfimA_8D23vw.jpeg" /></figure><p>In the next blog, I will show how to design the frontend for <a href="https://lootroyale.xyz/">lootroyale.xyz</a> to mint the loot royale NFTs since this blog has become lengthy already.</p><p>Any feedback is appreciated. In case of any doubts or issues or any new ideas, DM me on twitter — <a href="https://twitter.com/pranay_bathini">@pranay_bathini</a>. Let us learn together.</p><p>Thanks for reading!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9b5e43452c6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-glitcher/creating-an-loot-royale-nft-collection-dapp-e9b5e43452c6">Creating Loot Royale NFT Collection DApp</a> was originally published in <a href="https://medium.com/the-glitcher">The Glitcher</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solidity for Beginners: Creating Smart Contracts]]></title>
            <link>https://medium.com/the-glitcher/solidity-for-beginners-creating-smart-contracts-7d9932101b36?source=rss----56671f365349---4</link>
            <guid isPermaLink="false">https://medium.com/p/7d9932101b36</guid>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[metamask]]></category>
            <dc:creator><![CDATA[Pranay Bathini]]></dc:creator>
            <pubDate>Sat, 26 Jun 2021 12:34:15 GMT</pubDate>
            <atom:updated>2021-06-26T12:34:27.163Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*01aujYOEhSeWmzHd.png" /></figure><p>Before diving into solidity, let’s understand where solidity originated from and what solidity means, and why it should be used?</p><p>I recommend reading this <a href="https://www.thecryptoinsight.com/2021/05/what-is-ethereum-beginners-guide.html">article</a> to have a theoretical understanding of blockchain and Ethereum before diving in.</p><p>In this article, we are going to learn the following things.</p><ul><li>What is Solidity?</li><li>Running Smart contracts in Solidity using Remix IDE?</li><li>Smart contract creation</li><li>Deployment of Smart contracts to test blockchain.</li><li>Connecting Remix IDE with Metamask</li><li>Deploying the contract to Ropsten test network using Metamask.</li></ul><h3>Solidity</h3><p>Solidity is an <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented</a>, high-level language(Human readable) for implementing smart contracts.</p><h3>But what are smart contracts?</h3><p>Smart contracts are a piece of code uploaded to the blockchain. The code will contain public functions which can be called by anyone connected to the blockchain from their computer.</p><p>The blockchain is distributed in nature. It means there will be more than one server(a network of computers) that will be running your code, verifying each other making sure no one cheats in the network.</p><p>The distributed nature of blockchain makes it decentralized(No single point of control). The control is distributed among the participating nodes. This decentralized nature allows people to develop decentralized applications what are so-called <a href="https://ethereum.org/en/dapps/">DApps<strong>.</strong></a></p><p>There are a lot of advantages and a change in developing tactics these DApps bring in. One of them is the immutability of smart contracts. Once deployed to Ethereum, they cannot be changed. This is to enforce the trust factor that the code is deployed the same way to everyone.</p><p>This also means the developer has to test the code for all corner cases before deploying to the blockchain. This changes the traditional way of shipping buggy code first and improving it later.</p><h3>Solidity Features</h3><ul><li>Statically typed — The type of variable declared is known at compile time.</li><li>Inheritance — Contracts can inherit from other contracts</li><li>Function Modifiers, State Variable Accessors, Fallback Functions, Enums</li></ul><p>are among some which we will discuss in great detail with examples.</p><h3>Using Solidity: The easy way</h3><p>The local installation of Solidity is a long process where we have to install node, npm, ganache-cli or testrpc for our private blockchain, solcjs for compiling our solidity code, and web3js for interaction.</p><p>So, we are going to take the easy way of using remix IDE which is an online IDE and we will use two different kinds of test networks to deploy our code.</p><h3>Installing Remix via docker</h3><p>Don’t worry, this is the only big step which we are going to do.</p><p>If you don’t have docker, install it from <a href="https://docs.docker.com/desktop/">here.</a> Trust me docker will save a lot of valuable time which we are going to lose in the installation process and configuration.</p><p>Once you have installed docker and running it, execute the below command.</p><pre>docker pull remixproject/remix-ide:latest</pre><p>This command will pull the latest version of IDE into your system. Now let’s run it. Execute the below command to run it.</p><pre>docker run -p 8080:80 remixproject/remix-ide:latest</pre><p>Now your IDE is running. Go to <a href="http://localhost:8080/">http://localhost:8080</a> and you can use you Remix instance. You should be able to see a screen like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4FYhax2wLo5kYFF-.png" /></figure><h3>Your First Program in Solidity</h3><p>Let’s create a simple contract that lets you store your name on the blockchain and retrieve it.</p><p>The contract will look like below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b8ed8a19dc382db86b8b1f3c494cec4/href">https://medium.com/media/5b8ed8a19dc382db86b8b1f3c494cec4/href</a></iframe><p>Let’s understand the code line by line.</p><p>The first line specifies which version of the compiler that code should be interpreted in. This is done with the help of the pragma directive.</p><h3>Why we need to specify the version?</h3><p>The only constant in software is change. So, if something new adds up in future versions, the existing code should run without breaking. This is to prevent future issues. This can be specified in two ways.</p><pre>pragma solidity ^0.8.4;</pre><p>This line tells the compiler to use the 0.8.4 version. The ^ symbol prevents the code from being compiled from a higher version.</p><pre>pragma solidity &gt;=0.7.0 &lt;0.9.0</pre><p>This tells only the compiler greater than or equal to 0.7.0 and less than 0.9.0 can compile the code.</p><p>In the next line, the contract is defined by the contract keyword and it is similar to how the classes are defined. A solidity contract is a collection of code(its functions) and data(state variables) and it resides at a specific address on the Ethereum blockchain.</p><p>Inside the contract, we define a state variable to store our name as a string. All the variables are by default storage type which means they will be occupying space inside the contract when deployed on the blockchain.</p><p>Note that Solidity is statically typed which means we need to define the type of variable while writing the contract and it will be resolved at compile time.</p><p>In the next lines, we defined two functions, one for taking the input and storing the name and the other for retrieving the stored name from the blockchain.</p><p>Note that both are defined as scope public which means anyone on the chain can call the functions.</p><p>We will discuss all the language-specific constructs with detailed examples in the next set of articles.</p><p>For now, let’s compile the contract and deploy it.</p><h3>Compiling the contract</h3><p>In the left vertical tab, click on the solidity compiler. You will see the below screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y2R1p4Uwy4c3x2X1.png" /></figure><p>Click on the compile NameStorage.sol. It should show the green tick mark as above.</p><p>Note that the compiler version should be between 0.7.0 and 0.9.0. I have selected 0.8.1 here.</p><p>Once compiled, the compiler would generate a byte code that is machine-understandable like below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b4315b938becf8b2bc637fcac6af75b/href">https://medium.com/media/7b4315b938becf8b2bc637fcac6af75b/href</a></iframe><p>Now, let’s deploy it to the blockchain.</p><h3>Deploying the contract</h3><p>Next, head to the deploy and run transactions tab. You should be able to see the below screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gZZK1z8Ujbi1LWel.png" /></figure><p>The menu can be overwhelming but let’s focus on what we need to do. There will be a lot of test account with 100 (fake/test) Ether.</p><p>Click on deploy and the contract will be deployed to the blockchain and a contract address will be returned as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Nmi334YZm57bBWo4.png" /></figure><p>Our contract is deployed at address 0xa131AD247055FD2e2aA8b156A11bdEc81b9eAD95.</p><p>Now, if you observe our balance will be 99.999 something.</p><p>For deploying on the blockchain, some Ether has to be spent which is known as gas.</p><h3>Storing Our Name</h3><p>In the left bottom, type your name in the textbox and click on store. This would store our name on the blockchain and it would cost us some gas as well as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5TB4ZTn5BdpRONBw.png" /></figure><p>Now click on the retrieve, to get the name stored on the contract. If you observe this properly, this operation does not cost us any gas.</p><p>Only write operations cost us gas as the same should be replicated to thousands of servers.</p><p>Remember, our functions are defined as public, so anyone on the blockchain can call them.</p><p>You can select a different account from the accounts at the left top corner and call retrieve.</p><p>It would give you output as ‘pranay’. As we discussed, this operation would not cost us any gas. It would be 100 ether.</p><p>Now, store another name from the same account and retrieve it like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PwJwxd7fw6kWguVI.png" /></figure><p>If you observe, our old name doesn’t exist anymore. It was over-written by new value and it can be done by anyone.</p><p>In the next articles, we will see how to restrict writing to contracts.</p><h3>Connecting Metamask with Remix IDE</h3><p>Install Metamask chrome extension from <a href="https://metamask.io/">here</a>. Once installed, create a password, store the passphrase in a safe location. Do not share it with anyone.</p><p>Once you get to the main screen, select Ropsten test network. You can also deploy to Ethereum mainnet but it will cost you actual money in ether.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/0*trfnAbaYN7cgfGL5.png" /></figure><p>The ether in my account is test (fake) Ether. You can send test Ether to your account from <a href="https://faucet.metamask.io/">metamask faucet</a>.</p><h3>Deploying on Ropsten Test environment</h3><p>Come back to Remix IDE and go to deploy and run the transactions tab and select Injected Web3 as Environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/0*_q3zH6dIw51Zc_Vn.png" /></figure><p>Once you selected injected web3, remix IDE will try to connect with Metamask wallet like above.</p><p>Click Next and Connect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/0*vPUe_rRzKNKnCicJ.png" /></figure><p>You should be able to see your Metamask account in the deploy tab and also your test ether in your account.</p><p>Now Click on deploy since it is already compiled. You will see a notification from Metamask like below for confirmation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/0*DS3V73bwSxAkbVXw.png" /></figure><p>Click confirm and the contract will be deployed to the test blockchain Ropsten network.</p><p>On the terminal in ‘Deploy and Run Transactions’ tab, you will see the transaction details like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VBr2qcAQ9C8AsepW.png" /></figure><p>Once you click on the URL of Ropsten displayed, it will display more information about the transaction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/0*SLH39k59n73vqR9D.png" /></figure><p>You can verify on Metamask too about the transaction and can see gas used on contract deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/0*O-K4WfLuRBa6tatk.png" /></figure><p>Now, you can go back to Remix IDE and store your name in the contract and retrieve it as we did earlier.</p><p>If you like the post, consider supporting us by sending some ERC20 tokens to the below address.</p><pre>0xdd2f4D03E817f4Fbaf233cAd8Ea829229fA6d592</pre><blockquote>Keep <strong>Experimenting</strong> 🔎.</blockquote><blockquote>Keep <strong>Learning</strong> 🚀</blockquote><p>This blog was originally published on the <a href="https://www.thecryptoinsight.com/">https://www.thecryptoinsight.com</a> .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d9932101b36" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-glitcher/solidity-for-beginners-creating-smart-contracts-7d9932101b36">Solidity for Beginners: Creating Smart Contracts</a> was originally published in <a href="https://medium.com/the-glitcher">The Glitcher</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean code Principles and Software Engineering Principles]]></title>
            <link>https://medium.com/the-glitcher/clean-code-principles-and-software-engineering-principles-651cdcd67fcd?source=rss----56671f365349---4</link>
            <guid isPermaLink="false">https://medium.com/p/651cdcd67fcd</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Pranay Bathini]]></dc:creator>
            <pubDate>Fri, 25 Jun 2021 08:24:07 GMT</pubDate>
            <atom:updated>2021-06-25T08:24:33.389Z</atom:updated>
            <content:encoded><![CDATA[<p>A road to great habits</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A56XEhfV9pFF2KbfBY4IUw.png" /></figure><h3>What is clean code?</h3><p>Code which is readable, maintainable, testable and elegant.</p><h3>Why we should care?</h3><p>Because there is no such thing as write only once code. Over the time, software is like to change. There will be bug fixes, new features, new requirements and business changes.</p><h3>Why we should strive for clean code?</h3><ul><li>Well Structured Code is easy to understand.</li><li>Better use of one’s time — for author and fellow developers</li><li>Saves Costs by Saving time — It is compound effect.</li><li>Easier Onboarding of new members.</li><li>Easier Debugging and efficient maintenance.</li><li>It feels good and confident.</li></ul><blockquote><strong>Of course bad code can be cleaned up. But it’s very expensive</strong></blockquote><blockquote><strong>Any fool can write code that a computer can understand. Good programmers write code that humans can understand.</strong></blockquote><h3>Naming</h3><ul><li>Use complete , descriptive, understandable names for methods and variables.</li><li>Use CamelCase — naming convention</li><li>Use names according to the context</li><li>Eg. <strong>public String addComment()</strong> instead of <strong>public String addcmt()</strong></li><li>Eg. <strong>for(String name : names) </strong>instead of <strong>for(String x : xd)</strong></li><li>Names should be understandable. Write names as you speak it.</li><li>Eg. <strong>public fileAgeInDays;</strong> instead of <strong>int age;</strong> or <strong>int a;</strong></li><li><strong>Be Consistent — </strong>don’t use <strong>get()</strong> in one place and <strong>fetch()</strong> in other.</li><li>Use Nouns for variables, parameters. Use Verbs for Methods.</li></ul><blockquote><strong>You should name a variable using the same care with which you name a first-born child.</strong></blockquote><h3>Comments</h3><ul><li>Comments are hard to maintain and they are almost out of date.</li><li>The code is the best documentation. The code should read like a prose.</li><li>Don’t be redundant</li><li>Avoid unnecessary comments.</li><li>Use comments only as a clarification.</li><li>Don’t comment code. Delete it. If needed retrieve from VCS.</li><li>If you are required to comment the code, consider refactoring it.</li></ul><h3>Comments Rules</h3><ul><li>Most of the time — comments lie</li><li>Code is updated or moved, but not the comments</li><li>Comments do not make up for bad code. If code is unclear, rewrite the code.</li></ul><h4>Good Comments</h4><ul><li>Can be used for TODOs but should only be temporary</li><li>Can be used for clarification like input format or clarification</li><li>Can also be used for warnings or consequences</li></ul><h3>Bad Comments</h3><ul><li>Noise comments — about what code already speaks</li><li>Do not journal in comments. Use commit messages.</li></ul><h3>Functions</h3><ul><li>Functions length — The ideal length of functions should not be greater than 15. Sometimes it can be more but should be clean to understand.</li><li>Function Arguments — Three or less. If more than three, consider refactoring it into a class.</li><li>Proper Indentation is must. It makes the code easier to read. Always format the code in IDE after writing.</li><li>Keep lines Short. Don’t scroll horizontally.</li><li>Functions should do exactly one task. If a function does multiple tasks, split the tasks one per each function.</li><li>Do not return null. Always return optional or empty collections.</li><li>Fail fast and return</li><li>Example — Use public void validate() and public void save() instead of public void validateAndSave()</li></ul><h3>Classes</h3><ul><li>Same applicate to class as well. Each class should have single responsibility.</li><li>All methods must be written in scope of the thing class is About. Example — User class, all methods must be about user. It should not contain methods about other class.</li><li>Keep Utility methods and variables private except in some cases.</li><li>Expose only necessary variables through getters and setters.</li><li>Use access levels properly — public , protected and private</li><li>Objects expose behavior and hide data. Conversely, data structures expose data and lacks of (significant) behavior.</li><li>Don’t create unnecessary Objects. Use singleton pattern wherever applicable.</li></ul><h3>Constants</h3><ul><li>Consistent Naming conventions with upper case letters separated by underscore for Constants like API_KEY instead of APIKEY</li><li>Don’t hard code. Define constant variables instead of hardcode them. It will also be easier to change if used in multiple places.</li><li>Use named constants instead of magic numbers.</li><li>If you want to have restricted set of values, use enums instead.</li></ul><p><strong>Eg. </strong>Instead of</p><p>If (7 == weekDay){ // some code}</p><p><strong>Use</strong></p><p>const int SUNDAY = 7;</p><p>if(SUNDAY == weekDay){//some code}</p><h3>Logging</h3><ul><li>Anyone who has ever laid their hands onto production code for debugging has yearned for more logs at some point in time.</li><li>The importance of logs can not be over-emphasized in development in general and maintenance in particular.</li><li>Avoid excessive logging, log only what might need in troubleshooting.</li><li>A good practice is to log at every branching and choose log levels wisely.</li><li>Use external tools for tracing, aggregation and filtering of log messages for faster analytics.</li></ul><h3>Refactoring</h3><ul><li>If you don’t have unit tests, you don’t know what your code does.</li><li>Refactoring rules</li><li>Bring the code under test.</li><li>Then safely and confidently update your code.</li><li>Be consistent. Follow conventions. If you do something in a certain way, do all similar things in the same way</li></ul><h3>TDD Development cycle</h3><p>1.Add a test from requirements gathered from use cases and user stories before writing code.</p><p>2.Run all tests. The new test should fail indicating new code is needed for the desired feature</p><p>3.Write the simplest code that passes the new test. No code should be added beyond the tested functionality.</p><p>4.All tests should now pass. If any fail, revise till it pass.</p><p>5.Refactor as needed, using tests after each refactor to ensure that functionality is preserved</p><p>6.Repeat for each new piece of functionality.</p><h3>Tests</h3><ul><li>Fast: Unit tests should be fast and being executed in a short time.</li><li>Independent: Tests should not depend on each other.</li><li>Repeatable: Tests should be reproducible in any environment.</li><li>One assert per test.</li><li>If you have the code covered by tests, you will not be afraid to modify it and break it.</li><li>Build your software using tests that guide your development. TDD encourages simple designs and inspires confidence</li></ul><h3>Clean coder rule</h3><blockquote><strong>Always leave the code cleaner than you found it.</strong></blockquote><h3>General Design Rules</h3><ul><li>Declare local variables as close as you can to their usage.</li><li>Declare instance variables at the top of the class</li><li>Constants should be declared at the top of the class or in a Constants class by example.</li><li>Use dependency injection</li><li>If you use third-party libraries, wrap them, so if they change, only your wrapper implementation needs to change</li><li>Place methods in a top-down direction.</li><li>Program to interface not implementation.</li><li>Prefer polymorphism to if/else or switch/case.</li><li>Separate multi-threading code</li><li>Follow Law of Demeter. A class should know only its direct dependencies.</li><li>Keep configurable data at high levels.</li><li>Be consistent. If you do something a certain way, do all similar things in the same way.</li></ul><h3>Code smells</h3><p>1.Rigidity. The software is difficult to change. A small change causes a cascade of subsequent changes.</p><p>2.Fragility. The software breaks in many places due to a single change.</p><p>3.Immobility. You cannot reuse parts of the code in other projects because of involved risks and high effort.</p><p>4.Needless Complexity.</p><p>5.Needless Repetition.</p><p>6.Opacity. The code is hard to understand.</p><h3>Some general software engineering principles</h3><ul><li>DRY — Don’t Repeat Yourself. Opposite is WET.</li><li>KISS — Keep It Simple Stupid.</li><li>YAGNI — You Aren’t Gonna Need It</li><li>SOLID</li></ul><h3>DRY — Don’t Repeat yourself</h3><ul><li>A piece of code should not be repeated across the software.</li><li>Reduce duplicate and increase reusability .</li><li>Reusability means less code which leads to better maintainability.</li><li>But remember, some reusability can actually increase readability and maintainability.</li><li>Opposite of DRY is WET — Write Everything Twice, Waste Everyone’s time , We Enjoy Typing. This applies when you over repeat.</li><li>General rule — when you write something thrice, it is time to refactor the logic to a function and reuse.</li></ul><h3>KISS — Keep It Simple Stupid</h3><ul><li>Keep Code as Simple as possible.</li><li>Engineers like to complicate things. Unnecessary complexity should be avoided.</li><li>It makes it easy to understand and maintain.</li><li>How to keep code simple?</li><li>Follow the suggestions from previous slides to keep the classes and methods simple and concise.</li><li>Break down the problem into small steps and write minimal code to implement them.</li><li>Also, always ask yourself and the reviewer — can this be written in simpler way?</li></ul><h3>YAGNI — You aren’t gonna need it</h3><ul><li>Part of Extreme programming methodology, which states that some capability we presume our software needs in the future should not be built now because “you aren’t gonna need it”.</li><li>Also, you should not optimize and increase complexity thinking about future.</li><li>It improves software quality and increases responsiveness.</li><li>Sometimes it may be good but think, it may come in your way in future where you will encounter the cost of building the software wrong and leads to waste of effort and time.</li><li>It should be used with continuous refactoring, unit testing and integration.</li><li>It syncs with KISS on avoiding complexity.</li></ul><h3>SOLID Principles</h3><h3>Brief Explanation</h3><ul><li><strong>Single Responsibility Principle</strong> — interface, class or method ideally should do one thing and do that well</li><li><strong>Open-Closed Principle — </strong>Open for extension and closed for modification. You class should have everything — closed for modification but is open for extension through inheritance or composition.</li><li><strong>Liskov Substitution Principle — </strong>Every subclass should be substitutable for their parent class. This helps in reducing coupling.</li><li><strong>Interface segregation Principle</strong> — Every class must implement the methods of the interface it implements. This principle states that classes should not require to implement methods which they do not require. It helps in creating more smaller &amp; focused interfaces.</li><li><strong>Dependency Inversion Principle — </strong>Classes should depend only on their abstractions, not on their implementations. The classes should not instantiating their dependencies but they should be injected into the class.</li></ul><p><strong>Single Responsibility Principle(SRP)</strong></p><ul><li>Every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class</li><li>A method or class must not do anything less or more. There should be a single reason to change it.</li><li>For example, a class has methods for sign up and login functionality. If there is change in login mechanism or sign up, we need to change the class for both the reasons.</li><li>Break into two classes and we will have only one reason to change the respective class.</li></ul><h3>Open-closed Principle</h3><p>The principle means open for extension but closed for modification.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/998aafe68baf32d140f035d994c1942c/href">https://medium.com/media/998aafe68baf32d140f035d994c1942c/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a9caf428c45cd5262cec27c958119aa/href">https://medium.com/media/0a9caf428c45cd5262cec27c958119aa/href</a></iframe><h3>Liskov Substitution Principle(LSP)</h3><p>Every subclass should be substitutable for their parent class. The Objects in your sub class should work in same way as the super class</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37f5d31be4dd5900635d352867698395/href">https://medium.com/media/37f5d31be4dd5900635d352867698395/href</a></iframe><h3>Interface Segregation Principle</h3><ul><li>This principle states that classes should not require to implement methods which they do not require.</li><li>Clients should not be forced upon interfaces that they do not use.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1cc1c518c4e20eb9cb51396b07bc94c/href">https://medium.com/media/c1cc1c518c4e20eb9cb51396b07bc94c/href</a></iframe><p><strong>Solution</strong></p><p>Break our interface into multiple interfaces like TerrestialAnimals and FlyingAnimals. Animals interface can contain function eat()</p><h3>Dependency Inversion Principle</h3><p>DIP states that</p><ul><li>High level modules should not depend on low level modules. Both should depend on abstractions.</li><li>Abstractions should not depend on details. Details should depend on abstractions.</li></ul><p>Refer <a href="https://www.tutorialsteacher.com/ioc/dependency-inversion-principle">this example</a> for better understanding.</p><h3>Tell, Don’t Ask Principle</h3><ul><li>Tell-Don’t-Ask is a principle that helps people remember that object-orientation is about bundling data with the functions that operate on that data.</li><li>It reminds us that rather than asking an object for data and acting on that data, we should instead tell an object what to do.</li><li>This encourages to move behaviour into an object to go with the data</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/0*cjODBRJfaQLotmNr.png" /></figure><p>Refer <a href="https://martinfowler.com/bliki/TellDontAsk.html">martin fowler blog on this principle</a> for detailed explanation.</p><h3>Favor Composition Over Inheritance</h3><ul><li>Composition — HAS –A relationship</li><li>Inheritance — IS –A relationship</li><li>Both provide polymorphic behavior . Explain how?</li></ul><h4>But why favor composition?</h4><ul><li>With composition, it’s easy to change behaviour on the fly with Dependency Injection .</li><li>Inheritance is more rigid as most languages do not allow you to derive from more than one type.</li><li>Inheritance exposes subclass details of parent class therefore it may break encapsulation.</li><li>Tight coupling — implementation of subclass may be bound to parent class implementation.</li><li>Excessive reuse of code by subclasses can make stack go deeper and more confusing.</li></ul><h3>Last points</h3><ul><li>Code against interfaces — loose coupling</li><li>Never inject concrete implementations — tight coupling</li><li>Encapsulate what changes — Factory design pattern which encapsulates object creation code. It provides flexibility to introduce changes without any impact on existing code.</li><li>Don’t do all stuff by yourself, delegate wherever applicable. Example is hashcode() and equals() method to compare two objects equality.</li></ul><blockquote><strong><em>You cannot swim without getting wet</em></strong></blockquote><p>Incorporate these principles into your development and make it a habit to use these principles to be a better programmer.</p><h3>More Reading</h3><ul><li><a href="https://martinfowler.com/">https://martinfowler.com/</a></li><li><a href="https://blog.cleancoder.com/">https://blog.cleancoder.com/</a></li><li><a href="https://www.elegantobjects.org/">https://www.elegantobjects.org/</a></li><li><a href="https://www.yegor256.com/">https://www.yegor256.com/</a></li><li><a href="https://refactoring.com/">https://refactoring.com/</a></li></ul><h3>Keep <strong>Experimenting</strong> 🔎 Keep <strong>Learning</strong> 🚀</h3><p><strong>Note</strong> : This article was originally published at <a href="http://www.pranaybathini.com/">www.pranaybathini.com</a> .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=651cdcd67fcd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-glitcher/clean-code-principles-and-software-engineering-principles-651cdcd67fcd">Clean code Principles and Software Engineering Principles</a> was originally published in <a href="https://medium.com/the-glitcher">The Glitcher</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apache Flink]]></title>
            <link>https://medium.com/the-glitcher/apache-flink-498073afa2c0?source=rss----56671f365349---4</link>
            <guid isPermaLink="false">https://medium.com/p/498073afa2c0</guid>
            <category><![CDATA[apache-flink]]></category>
            <category><![CDATA[presentations]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[stream-processing]]></category>
            <category><![CDATA[apache]]></category>
            <dc:creator><![CDATA[Pranay Bathini]]></dc:creator>
            <pubDate>Sat, 05 Dec 2020 10:55:36 GMT</pubDate>
            <atom:updated>2021-01-01T11:37:09.247Z</atom:updated>
            <content:encoded><![CDATA[<p>The distributed stream processing engine</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*uFavSM6YDZxAmG2Tk6r9JQ.png" /></figure><h3>What is Apache Flink ?</h3><p>Apache Flink is a framework and distributed processing engine for stateful computations over unbounded and bounded data streams. Flink has been designed to run in all common cluster environments, perform computations at in-memory speed and at any scale.</p><h3><strong>More info</strong></h3><p>Below article gives a gist on streaming engine concepts and choices available.</p><p><a href="https://medium.com/@anuprawka/selecting-the-right-streaming-engine-for-your-data-pipeline-e87d76c9dfca">Selecting the Right streaming Engine for your Data Pipeline</a></p><p>Below is an article which compares all these frameworks in great detail.</p><p><a href="https://medium.com/@chandanbaranwal/spark-streaming-vs-flink-vs-storm-vs-kafka-streams-vs-samza-choose-your-stream-processing-91ea3f04675b">Spark Streaming vs Flink vs Storm vs Kafka Streams vs Samza : Choose Your Stream Processing…</a></p><h3>Slideshow</h3><p>The below slides discuss in detail from big data to emergence of big data frameworks such as spark and Flink. The example using Datastream API and Dataset API. Explains the windowing in flink and ends with use-cases.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.slideshare.net%2Fslideshow%2Fembed_code%2Fkey%2FnZmOsneRAyLoo3&amp;display_name=SlideShare&amp;url=https%3A%2F%2Fwww.slideshare.net%2Fpranaykumar82%2Fapache-flink-239766010&amp;image=https%3A%2F%2Fcdn.slidesharecdn.com%2Fss_thumbnails%2Forx6cex8rqctbrw2vcyp-signature-c74a96e5586aec4c522e22dd3e45ab1d78ba15044fdb7432e1a3bc72491eca87-poli-201204171744-thumbnail-4.jpg%3Fcb%3D1607102358&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=slideshare" width="600" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/799bb9cc6a0b41acbd12f31d47b3dd1b/href">https://medium.com/media/799bb9cc6a0b41acbd12f31d47b3dd1b/href</a></iframe><h3>Resources</h3><ol><li>The Offical Documentation — <a href="https://ci.apache.org/projects/flink/flink-docs-release-1.11/">https://ci.apache.org/projects/flink/flink-docs-release-1.11/</a></li><li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.11/dev/datastream_api.html">DataStream API- https://ci.apache.org/projects/flink/flink-docs-release-1.11/dev/datastream_api.html</a></li><li>Slides — <a href="https://www.slideshare.net/pranaykumar82/apache-flink-239766010">https://www.slideshare.net/pranaykumar82/apache-flink-239766010</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=498073afa2c0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-glitcher/apache-flink-498073afa2c0">Apache Flink</a> was originally published in <a href="https://medium.com/the-glitcher">The Glitcher</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bitcoin Halving]]></title>
            <link>https://medium.com/the-glitcher/bitcoin-halving-45c527a05e70?source=rss----56671f365349---4</link>
            <guid isPermaLink="false">https://medium.com/p/45c527a05e70</guid>
            <category><![CDATA[bitcoin-news]]></category>
            <category><![CDATA[bitcoin-mining]]></category>
            <category><![CDATA[bitcoin-halving]]></category>
            <category><![CDATA[bitcoin-terms]]></category>
            <category><![CDATA[bitcoin]]></category>
            <dc:creator><![CDATA[Pranay Bathini]]></dc:creator>
            <pubDate>Fri, 15 May 2020 18:06:16 GMT</pubDate>
            <atom:updated>2020-05-15T18:11:01.069Z</atom:updated>
            <content:encoded><![CDATA[<p>Understanding the terminology</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Br83YzFMUxFhlsH6.jpg" /><figcaption>Image from Alpha coders</figcaption></figure><p>Everyone familiar with Bitcoin knows Bitcoin is created by a process known as bitcoin mining. Miners solve the difficult cryptographic puzzles to create a new block in the blockchain. This involves the usage of high computational power which needs a large amount of electricity.</p><h4>Fact: The amount of electricity used to mine bitcoin is nearly 50Twh which can power 7 mn households in the US.</h4><p>Let’s continue. . .</p><p>For every new block added to the blockchain, one will be awarded a block reward. This is the only way bitcoin is created.</p><p>As per bitcoin’s code, for every 210,000 blocks, the block reward to miners will get halved until they reach zero in two decades. This will limit the total number of Bitcoins that ever exist to 21 million.</p><p>This is known as <strong>Bitcoin Halving. </strong>Recently, third bitcoin halving happened since its creation which is in 2009. This third halving reduced the block reward for miners from 12.5 BTC to 6.25 BTC.</p><p>The first halving happened in 2012, second in 2016. This halving code is written into the cryptocurrency by its creator Satoshi Nakamoto. The 630,000th block which was mined halved the bitcoin reward.</p><h4>The right questions?</h4><p>What is the impact of this Halving?</p><p>The miner&#39;s revenue will be reduced and also the number of bitcoins mined. This might lead to a bullish market and leads to an increase in price. This is, in fact, true according to previous halvings. On the 12th of May, the price is 8700 USD. In 3 days it surged to 9500 USD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iswYv6P2qF2-6duT.png" /><figcaption>Image from Coin metrics</figcaption></figure><p>The average Transaction fee rewards are as follows in the past 1 year.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*Ncu-oj4x9kJ4VuhVrQWSvA.png" /><figcaption>Source: blockchain.com</figcaption></figure><p>For more information about Bitcoin refer <a href="https://www.thecryptoinsight.com/2020/05/the-next-bitcoin-halving-is-going-to.html">here</a>. <a href="https://www.thecryptoinsight.com/">Here</a> you can find information about how to create a Bitcoin wallet, the best ways to buy/ sell bitcoins, Airdrops, and everything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/0*G_teL-VTnCoNuhPm.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45c527a05e70" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-glitcher/bitcoin-halving-45c527a05e70">Bitcoin Halving</a> was originally published in <a href="https://medium.com/the-glitcher">The Glitcher</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fish shell]]></title>
            <link>https://medium.com/the-glitcher/fish-shell-3ec1a6cc6128?source=rss----56671f365349---4</link>
            <guid isPermaLink="false">https://medium.com/p/3ec1a6cc6128</guid>
            <category><![CDATA[oh-my-zsh]]></category>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[fish]]></category>
            <category><![CDATA[fishshell]]></category>
            <category><![CDATA[oh-my-fish]]></category>
            <dc:creator><![CDATA[Pranay Bathini]]></dc:creator>
            <pubDate>Mon, 04 May 2020 16:07:18 GMT</pubDate>
            <atom:updated>2023-01-01T13:10:41.146Z</atom:updated>
            <content:encoded><![CDATA[<p>The super-productive shell</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MHAXM-9ZrMAF-Y9AASyGag.png" /></figure><p>The original article is published on <a href="https://www.pranaybathini.com/2021/01/fish-shell.html">my website</a>.</p><p>Previously, I used bash and zsh. After moving to the fish shell, a lot of things have changed and I am using it for nearly 2 years now. The user experience is extremely comfortable and enjoyable compared to other shells. I am not planning to go back and I suggest everyone should try it.</p><p>In this article, I am going to write everything about the fish shell.</p><h3>What is the fish shell?</h3><p>Fish is a <strong>smart</strong> and <strong>user-friendly</strong> command-line shell for Linux, macOS, and the rest of the family. Notice the bold words. Let’s define the words now by delving into the features directly.</p><h3>Features</h3><ul><li>Inline auto-suggestions based on history</li><li>Tab completion using man-page data</li><li>Syntax highlighting.</li><li>Intuitive wildcard support.</li><li>Web-based configuration</li><li>Sane scripting</li></ul><p>You can try the following without installing the fish shell. Try <a href="https://rootnroll.com/d/fish-shell/">in-browser fish shell here</a>.</p><p>You can install fish in Ubuntu by running the following commands.</p><pre>sudo apt-add-repository ppa:fish-shell/release-3<br>sudo apt-get update<br>sudo apt-get install fish</pre><p>For other systems, refer <a href="https://github.com/fish-shell/fish-shell">here</a>.</p><h3>Let’s break them down</h3><h4>Inline auto-suggestions based on history</h4><p>Smart auto-suggestions are rarely seen. Fish auto-suggestions are out of the box. This insanely awesome feature is very smooth and I feel it is better than zsh auto-suggestions. Actually, this is one of the primary reasons for shifting to the fish shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tLnh1LRtU5eJ2rDMPi1OIg.png" /></figure><p>Using your history, fish suggests the next possibilities of completing the commands. You can complete them with <em>right-arrow</em> key</p><h4>Syntax highlighting</h4><p>You can see, if something either a command or folder or file name doesn’t exist or invalid, it will highlight in red. If it exists, it will be in blue.</p><p>But, more importantly, while you type the prompt auto-suggests your previous commands (by recent and most used). This is far quicker than ctrl+r and usually shows the command you want 80% of the time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UBB-QBBKcYAUYQqgLGRxTg.png" /></figure><p>So, no more ctrl+R, just type what you remember about the command you want to use and use top and bottom arrow keys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N1D_DjCZ2Z7gKrz9nhr5Yg.png" /></figure><p>Using the <em>top-arrow</em> key, my output is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x9Ux60xP8uhsEZbIdW3crQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ox6Me5PKEvzHgp8ueva-Yw.png" /></figure><h4>Tab completion using man-page data</h4><p>Fish parses CLI tool manpages, which makes it easy to provide auto-completions for most of the commands.</p><p>You can use <strong>tab</strong> to get all the options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CRFHLJhSY1aH3LxQbSSV-g.png" /></figure><h4>Intuitive wildcard support</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tkOwMEkkMP_uO_k3GmCBtA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*E5gLv459Vl8qtJDn_nYKvA.png" /></figure><p>This is what I like most about fish. So, Intuitive. Try the same in bash and zsh and let me know in comments if it works.</p><h4>Web-based configuration</h4><p>You can set your colors and view functions, variables, and history all from a web page running on a local webserver. This is pretty much the only shell that offers this. How cool. You just need to launch the following command.</p><p>fish__config</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1hWEJB8JSfCDtlVgxktBzg.png" /></figure><h4>Sane Scripting</h4><p>fish is fully scriptable, and its syntax is simple, clean, and consistent. You’ll never use do and done in a loop anymore. Clearly, it is different from bash.</p><pre>for i in (seq 5)                   <br>    echo $i<br>end</pre><p>Very clean indeed. For more reference <a href="https://fishshell.com/docs/current/tutorial.html">here</a>.</p><h3>Adding more customization</h3><p>You can install themes for the fish shell too. Yes, if you have used zsh, you might have used the great oh-my zsh package manager. O<em>h my fish </em>is the fish shell package manager.</p><h4>O<em>h my fish</em></h4><p>Oh My Fish allows you to install packages that extend or modify the look of your shell. It’s fast, extensible, and easy to use.</p><h4>Installation</h4><p>You can get started right away with the default setup by running this in your terminal:</p><pre>curl -L https://get.oh-my.fish | fish</pre><p>This will download the installer script and start the installation. Alternatively, you can download the installer and customize your install:</p><pre>curl -L https://get.oh-my.fish &gt; install<br>fish install --path=~/.local/share/omf --config=~/.config/omf</pre><p>For usage refer <a href="https://github.com/oh-my-fish/oh-my-fish">here</a>.</p><p>I have installed agnoster theme. So, far it is the best theme according to me.</p><h4><strong>Agnoster theme characteristics</strong></h4><ul><li>Displays the status of the previous command, if failed</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vIGnXKO1hMfnb8Eo4Mi6EA.png" /></figure><ul><li>Displays the working branch</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*s_wSEtxJfQ4t4av29vBoSg.png" /></figure><ul><li>Displays uncommitted changes</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*0fcz5wxNFSUGwHJnr1ZlvA.png" /></figure><ul><li>It doesn’t clutter the terminal</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*s_wSEtxJfQ4t4av29vBoSg.png" /></figure><p>One more thing to add. Sometimes, we wonder at what time, we executed a specific command. Add below function to fish. Most of the time, it comes with the theme, if not use this function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fVhecs1yskrI-c6UgT-xjA.png" /></figure><pre>function fish_right_prompt --description &#39;Right side prompt message&#39;<br> # A dark grey<br>    set --local dark_grey 555<br>    set_color $dark_grey<br>    echo -en (date +%H:%M:%S)</pre><pre>set_color normal<br>end</pre><p>You can find many more customization related settings for fish <a href="https://github.com/jorgebucaran/awesome-fish">here</a>.</p><p>There aren’t many disadvantages faced by me. It works fine with almost all the tools I use except for some bash related commands.</p><p>Refer this <a href="https://stackoverflow.com/questions/48732986/why-how-fish-does-not-support-posix">stack overflow</a> and <a href="https://news.ycombinator.com/item?id=5723235">hacker news</a> for the discussion on fish not being a POSIX standard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/0*-Ye89-4_eRrNde4G.png" /></figure><h4>Resources:</h4><ol><li><a href="https://fishshell.com/">https://fishshell.com/</a></li><li><a href="https://www.pranaybathini.com/2021/01/fish-shell.html">https://www.pranaybathini.com/2021/01/fish-shell.html</a></li><li><a href="https://github.com/fish-shell/fish-shell">https://github.com/fish-shell/fish-shell</a></li><li><a href="https://fishshell.com/docs/current/index.html#completion">https://fishshell.com/docs/current/index.html#completion</a></li><li><a href="https://github.com/jorgebucaran/awesome-fish">https://github.com/jorgebucaran/awesome-fish</a></li><li><a href="https://github.com/oh-my-fish/oh-my-fish">https://github.com/oh-my-fish/oh-my-fish</a></li><li><a href="https://news.ycombinator.com/item?id=5723235">https://news.ycombinator.com/item?id=5723235</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ec1a6cc6128" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-glitcher/fish-shell-3ec1a6cc6128">Fish shell</a> was originally published in <a href="https://medium.com/the-glitcher">The Glitcher</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MongoDB sharding]]></title>
            <link>https://medium.com/the-glitcher/mongodb-sharding-9c5357a95ec1?source=rss----56671f365349---4</link>
            <guid isPermaLink="false">https://medium.com/p/9c5357a95ec1</guid>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[mongodb-sharding]]></category>
            <category><![CDATA[mongodb-tutorial]]></category>
            <category><![CDATA[mongod]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Pranay Bathini]]></dc:creator>
            <pubDate>Mon, 04 May 2020 11:00:29 GMT</pubDate>
            <atom:updated>2021-05-05T17:04:35.899Z</atom:updated>
            <content:encoded><![CDATA[<p>A practical guide</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0jhfCcLUIeJqXVGz.jpg" /></figure><p>For starters, MongoDB is a document-oriented NoSQL database used for high volume data storage. In the traditional relational databases, we use tables and rows. In contrast, MongoDB makes use of collections and documents. Documents consist of key-value pairs which are the basic unit of data in MongoDB.</p><p>Without any further delay, we jump into what is Sharding, its requirement, sharding cluster architecture in MongoDB, and a practical example with Docker.</p><h3><strong>Sharding</strong></h3><p><a href="https://docs.mongodb.com/manual/reference/glossary/#term-sharding">Sharding</a> is a method for distributing data across multiple machines. MongoDB uses sharding to support deployments with very large data sets and high throughput operations.</p><h3><strong>Why Sharding?</strong></h3><p>Database systems with large data sets or high throughput applications can challenge the capacity of a single server. For example, high query rates can exhaust the CPU capacity of the server. Working set sizes larger than the system’s RAM stress the I/O capacity of disk drives.</p><p>For addressing system growth, we have 2 methods :</p><ol><li>Vertical Scaling.</li><li>Horizontal Scaling.</li></ol><h3><strong>Vertical Scaling</strong></h3><p><em>Vertical scaling</em> is increasing the capacity of a single server by using a more powerful CPU, adding more RAM, and increasing the amount of storage space. But there are practical limits to vertical scaling like the hardware limits and the load a single server can handle.</p><h3>Horizontal Scaling</h3><p><em>Horizontal Scaling</em> involves dividing the system dataset and load over multiple servers, adding additional servers to increase capacity as required. While the overall speed or capacity of a single machine may not be high, each machine handles a subset of the overall workload, potentially providing better efficiency than a single high-speed high-capacity server.</p><p>MongoDB supports <strong><em>horizontal scaling</em></strong> through sharding.</p><h3>Sharding cluster</h3><p>Before going further, we need to understand the components in the sharding cluster.</p><ol><li><strong>Shard</strong>: Each shard contains a subset of the sharded data. Each shard can be deployed as a <a href="https://docs.mongodb.com/manual/reference/glossary/#term-replica-set">replica set</a> to provide redundancy and high availability. Together, the cluster’s shards hold the entire data set for the cluster.</li><li><strong>Mongos: </strong>The mongos acts as a query router, providing an interface between client applications and the sharded cluster.</li><li><strong>Config Servers: </strong>Config servers store metadata and configuration settings for the cluster. They are also deployed as a replica set.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*DjZDfrie1kDFFdrQ1cy_Yw.png" /><figcaption>Sharded cluster</figcaption></figure><h3>Shard Keys</h3><p>MongoDB uses the <a href="https://docs.mongodb.com/manual/reference/glossary/#term-shard-key">shard key</a> to distribute the collection’s documents across shards. The <a href="https://docs.mongodb.com/manual/reference/glossary/#term-shard-key">shard key</a> consists of a field or fields that exist in every document in the target collection.</p><p>You choose the shard key when sharding a collection. The choice of shard key cannot be changed after sharding. A sharded collection can have only <em>one</em> shard key.</p><p>To shard a non-empty collection, the collection must have an <a href="https://docs.mongodb.com/manual/reference/glossary/#term-index">index</a> that starts with the shard key. For empty collections, MongoDB creates the index if the collection does not already have an appropriate index for the specified shard key. See <a href="https://docs.mongodb.com/manual/core/sharding-shard-key/#sharding-shard-key-indexes">Shard Key Indexes</a>.</p><p><em>Note</em>: <em>The choice of shard key affects the performance, efficiency, and scalability of a sharded cluster. A cluster with the best possible hardware and infrastructure can be bottlenecked by the choice of the shard key.</em></p><h3>Chunks</h3><p>MongoDB partitions sharded data into <a href="https://docs.mongodb.com/manual/reference/glossary/#term-chunk">chunks</a>. Each chunk has an inclusive lower and exclusive upper range based on the <a href="https://docs.mongodb.com/manual/reference/glossary/#term-shard-key">shard key</a>. MongoDB migrates chunks across the shards in the sharded<a href="https://docs.mongodb.com/manual/reference/glossary/#term-sharded-cluster"> </a>cluster using the sharded cluster balancer. The balancer attempts to achieve an even balance of chunks across all shards in the cluster.</p><h3>Balancer and Even Chunk Distribution</h3><p>In an attempt to achieve an even distribution of chunks across all shards in the cluster, a <a href="https://docs.mongodb.com/manual/core/sharding-balancer-administration/">balancer</a> runs in the background to migrate <a href="https://docs.mongodb.com/manual/reference/glossary/#term-chunk">chunks</a> across the <a href="https://docs.mongodb.com/manual/reference/glossary/#term-shard">shards</a></p><h3>Advantages of Sharding</h3><ol><li><strong>Reads/Writes:</strong> MongoDB distributes the read and write workload across the shards in the sharded cluster, allowing each shard to process a subset of cluster operations. Both read and write workloads can be scaled horizontally across the cluster by adding more shards.</li><li><strong>Storage Capacity: </strong>Sharding distributes data across the shards in the cluster, allowing each shard to contain a subset of the total cluster data. As the data set grows, additional shards increase the storage capacity of the cluster.</li><li><strong>High Availability: </strong>A sharded cluster can continue to perform partial read/write operations even if one or more shards are unavailable. While the subset of data on the unavailable shards cannot be accessed during the downtime, reads or writes directed at the available shards can still succeed.</li></ol><p><em>In production environments, individual shards should be deployed as replica sets, providing increased redundancy and availability.</em></p><h3>Sharded and Non-Sharded Collections</h3><p>A database can have a mixture of sharded and unsharded collections. Sharded collections are partitioned and distributed across the shards in the cluster. Unsharded collections are stored on a primary shard. Each database has its own primary shard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*w41n3ZOdSqM7NBTv2swqFw.png" /><figcaption>Sharded and Unsharded collections</figcaption></figure><h3>Connecting to a Sharded Cluster</h3><p>You must connect to a <a href="https://docs.mongodb.com/manual/reference/glossary/#term-mongos">mongos</a> router to interact with any collection in the <a href="https://docs.mongodb.com/manual/reference/glossary/#term-sharded-cluster">sharded cluster</a>. This includes sharded <em>and</em> unsharded collections. Clients should <em>never</em> connect to a single shard in order to perform read or write operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*aw1eVsPrmRXxasmKyJL3tQ.png" /></figure><p>You can connect to a<a href="https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos">mongos</a>the same way you connect to a<a href="https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod">mongod</a>, such as via the<a href="https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo">mongo</a>shell or a MongoDB driver.</p><h3><strong>Shard cluster Set Up</strong></h3><p>Now, we are beginning to build a cluster that consists of two shards that are a replica set (three nodes), config servers (three nodes replica set), and two mongos config-router nodes. In total, we will have eleven Docker containers running for our MongoDB sharded cluster. Of course, we can expand our cluster according to our needs.</p><p>Let’s define our first shard replica set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-IU4KBmH9m4qhyuK5z-qqg.png" /></figure><p>As you see, we defined our shard nodes by running them with the shardsvr parameter. Also, we mapped the default MongoDB data folder (<em>/data/db</em>) of the container, as you see.</p><p>Our second shard replica set is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mKzY4kjxnsinL0ICNnNEtQ.png" /></figure><p>Let’s define our config servers with configsvr parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WqNhpppPhAyRutxyKzVpnA.png" /></figure><p>Finally, we are going to define our mongos (router) instances:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zy1YS0L_QSqNTYw8AtqfZQ.png" /></figure><p>These mongos are dependent on our config servers. They take the configdb parameter to obtain metadata and configuration settings.</p><p>After building our docker-compose.yaml file, if we compose it up, we will see eleven running docker containers: Two shards(with 3 node replica set) ,3 config servers, 2 mongos routers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*70hp8MCm1y1Cw3GfiPxBYA.png" /></figure><p>Now, our sharding cluster needed to be configured. We will run some commands, which will build our cluster on related nodes.</p><p>First, we will configure our config servers replica set:</p><pre>docker exec -it mongocfg1 bash -c “echo ‘rs.initiate({_id: \”mongors1conf\”,configsvr: true, members: [{ _id : 0, host : \”mongocfg1\” },{ _id : 1, host : \”mongocfg2\” }, { _id : 2, host : \”mongocfg3\” }]})’ | mongo”</pre><p>After running the above command, we can check the status by running the following command on our first config server.</p><pre>docker exec -it mongocfg1 bash -c &quot;echo &#39;rs.status()&#39; | mongo&quot;</pre><p>Next, we will build our shard replica set.</p><pre>docker exec -it mongors1n1 bash -c &quot;echo &#39;rs.initiate({_id : \&quot;mongors1\&quot;, members: [{ _id : 0, host : \&quot;mongors1n1\&quot; },{ _id : 1, host : \&quot;mongors1n2\&quot; },{ _id : 2, host : \&quot;mongors1n3\&quot; }]})&#39; | mongo&quot;</pre><p>Now, our shard nodes know each other. One of them is primary and two are secondary. We can check the replica set status by running the status check command on the first shard node:</p><p>Do this for the second shard too.</p><pre>docker exec -it mongors1n1 bash -c &quot;echo &#39;rs.status()&#39; | mongo&quot;</pre><p>The output will be similar to this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ofIeS2HcX3g276JqYBMs7A.png" /></figure><p>Finally, we will introduce our shard to the routers:</p><pre>docker exec -it mongos1 bash -c &quot;echo &#39;sh.addShard(\&quot;mongors1/mongors1n1\&quot;)&#39; | mongo &quot;</pre><p>Now our routers, which are the interfaces of our cluster to the clients, have the knowledge about our shard. We can check the shard status by running the command below on the first router node:</p><pre>docker exec -it mongos1 bash -c &quot;echo &#39;sh.status()&#39; | mongo &quot;</pre><p>Now, you will see this output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a5VTu6vQSdBQszCk54TrvQ.png" /></figure><p>Now, our sharded cluster configuration is complete. We don’t have any databases yet. We will create a database and will enable sharding.</p><pre>docker exec -it mongors1n1 bash -c &quot;echo &#39;use someDb&#39; | mongo&quot;</pre><p>we should enable sharding on our newly created database.</p><pre>docker exec -it mongos1 bash -c &quot;echo &#39;sh.enableSharding(\&quot;someDb\&quot;)&#39; | mongo &quot;</pre><p>Now, we have a sharding-enabled database on our sharded cluster! It’s time to create a collection on our sharded database.</p><pre>docker exec -it mongors1n1 bash -c &quot;echo &#39;db.createCollection(\&quot;someDb.someCollection\&quot;)&#39; | mongo &quot;</pre><p>The collection is not sharded yet. We will shard it on a field named <em>someField</em>.</p><pre>docker exec -it mongos1 bash -c &quot;echo &#39;sh.shardCollection(\&quot;someDb.someCollection\&quot;, {\&quot;someField\&quot; : \&quot;hashed\&quot;})&#39; | mongo &quot;</pre><p>The sharding key must be chosen very carefully because it is for distributing the documents throughout the cluster.</p><p>You can find the docker-compose.yaml and same set up without docker <a href="https://github.com/pranaykumargoud/mongodb-sharding">here</a>.</p><p>Github link: <a href="https://github.com/pranaykumargoud/mongodb-sharding">MongoDB sharding</a></p><blockquote>I have stopped writing on medium and started writing on my blog <a href="https://www.pranaybathini.com/">www.pranaybathini.com</a> . Please visit to checkout the latest tech content.</blockquote><h4>References and additional resources:</h4><ol><li><a href="https://docs.mongodb.com/manual/core/sharding-shard-key/">https://docs.mongodb.com/manual/core/sharding-shard-key/</a></li><li><a href="https://www.mongodb.com/lp/white-paper/usage/ops-best-practices">https://www.mongodb.com/lp/white-paper/usage/ops-best-practices</a></li><li><a href="https://www.mongodb.com/presentations/webinar-sharding-methods-mongodb?jmp=docs">https://www.mongodb.com/presentations/webinar-sharding-methods-mongodb?jmp=docs</a></li><li><a href="https://dzone.com/articles/composing-a-sharded-mongodb-on-docker">https://dzone.com/articles/composing-a-sharded-mongodb-on-docker</a></li><li><a href="https://www.mongodb.com/presentations/webinar-everything-you-need-know-about-sharding?jmp=docs">https://www.mongodb.com/presentations/webinar-everything-you-need-know-about-sharding?jmp=docs</a></li><li><a href="https://docs.mongodb.com/manual/sharding/">https://docs.mongodb.com/manual/sharding/</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/0*ABvvpWMcVB5hGOYQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c5357a95ec1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-glitcher/mongodb-sharding-9c5357a95ec1">MongoDB sharding</a> was originally published in <a href="https://medium.com/the-glitcher">The Glitcher</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HashMap Internal working]]></title>
            <link>https://medium.com/the-glitcher/hashmap-internal-working-8679d058d244?source=rss----56671f365349---4</link>
            <guid isPermaLink="false">https://medium.com/p/8679d058d244</guid>
            <category><![CDATA[hashmap]]></category>
            <category><![CDATA[details]]></category>
            <category><![CDATA[java-hashmap]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[internal-working]]></category>
            <dc:creator><![CDATA[Pranay Bathini]]></dc:creator>
            <pubDate>Mon, 04 May 2020 10:59:19 GMT</pubDate>
            <atom:updated>2021-05-05T17:03:40.325Z</atom:updated>
            <content:encoded><![CDATA[<p>The detailed guide</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*v-oJXd1--zHg3wXX.png" /></figure><p>HashMap is used widely in programming to store values in pairs(key, value) and also for its near-constant complexity for its get and put methods. To access the value we need a key. But have you ever wondered, how it functions internally? How the keys and values are stored? What are the things that decide on its performance?</p><p>In this article, we are going to discuss various things about the working of HashMap and the things involved in it.</p><p>If someone asks “<strong>How HashMap works?</strong>”, the straight forward answer will be “<strong>On the principle of Hashing</strong>”.</p><p>But <strong>what is Hashing?</strong></p><p>Hashing is simply assigning a unique value to an object based on some formula/algorithm.</p><p>“Hash function should return the same hash code each and every time when the function is applied on the same or equal objects. In other words, two equal objects must produce the same hash code consistently.”</p><p>The hashcode is generated by the hashcode() method defined in Object class. This function produces hash code by typically converting the internal address of the object into an integer. Thus it produces different hash codes for different objects.</p><p>If we need equal hash codes for equal objects, refer <a href="https://howtodoinjava.com/java/basics/java-hashcode-equals-methods/">here</a>. This is achieved by overriding equals() method of Object class.</p><p>Now, we know about Hashing. But still, we don’t know how the key and values are stored in HashMap.</p><h4><strong>The internal structure</strong></h4><p>The structure of a Single Entry will be like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*Br8fLzrPSyLxAovQq0RHgg.png" /><figcaption>Structure of a single HashMap entry</figcaption></figure><p>HashMap maintains an array of such nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*fLrVSHXRDQn__xoWUve3Fw.png" /></figure><p>Now we know how the hashMap looks internally. It is basically an array of nodes where each node is a LinkedList which contains a key, value, hash value, and the link to the next node in case of collision.</p><p>We will get to the collision soon. Now we will see how the put and get methods work?</p><h4>How put(K key, V value) works?</h4><p>First of all, the key object is checked for null. If the key is null, the value is stored in table[0] position. Because hashcode for null is always 0.</p><p>Then on the next step, a hash value is calculated using the key’s hash code by calling its hashCode() method. This hash value is used to calculate the index in the array for storing Node object.</p><h4>Now comes the main part</h4><p>We know that two unequal objects can have the same hash code value, how two different objects will be stored in the same array location called bucket.</p><p>You already know the answer. The answer is LinkedList.</p><p>If an object is already stored at an index, its next is called. If it is null, the current object becomes the next node of the LinkedList. If not, the same is repeated until we encounter the null. I mean we traverse till the end.</p><h4>Then, how the update works?</h4><p>I know you start to wonder, what if I want to update the value of an existing key?</p><p>Here, the hash will be the same for the same keys and it will give the index of where the object is stored. While iterating the LinkedList of that specific hash, we call equals() method on key for equality check, and thus, it will update the value of the same key.</p><p>The get(K key) methods work the same way like put. First, it will find the index the key is located and calls equals for fetching the value of the Key while iterating the linkedList.</p><h4>Performance improvement from Java 8</h4><p>As part of the work for <a href="https://openjdk.java.net/jeps/180">JEP 180</a>, there is a performance improvement for HashMap objects where there are lots of collisions in the keys by using balanced trees rather than linked lists to store map entries. The principal idea is that once the number of items in a hash bucket grows beyond a certain threshold(Current TREEIFY_THRESHOLD = 8), that bucket will switch from using a linked list of entries to a balanced tree. In the case of high hash collisions, this will improve worst-case performance from O(n) to O(log n).</p><p>This is surely a good improvement, but what happens when again if we remove elements and the value decreases below the current treeify threshold? <strong>A</strong>. It will be converted back to LinkedList(currently: UNTREEIFY_THRESHOLD = 6))</p><p><em>Note: In usages with well-distributed user hashCodes, tree bins are rarely used.</em></p><h4>Example :</h4><pre>Let’s assume the hashmap size if 5. The hashcode function is ASCII value of first character of key. Index function be hashcode is (first character of key) &amp;&amp; (n-1).</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*MRlFhBgr8vrqz5kEG5X9Uw.png" /></figure><p>You can see, the first character is ‘f’ in both entries. According to the hashcode function and index function, they go into the same bin.</p><h4>Performance</h4><p>Two factors that affect the performance of hashmap are: 1. initial capacity 2. load factor.</p><p>The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created. The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the hash table is rehashed (that is, internal data structures are rebuilt) so that the hash table has approximately twice the number of buckets.</p><p>As a general rule, the default load factor (.75) offers a good tradeoff between time and space costs. Higher values decrease the space overhead but increase the lookup cost (reflected in most of the operations of the HashMap class, including get and put). The expected number of entries in the map and its load factor should be taken into account when setting its initial capacity, so as to minimize the number of rehash operations. If the initial capacity is greater than the maximum number of entries divided by the load factor, no rehash operations will ever occur.</p><p>The default initial capacity of the HashMap takes is 16 and the load factor is 0.75f (i.e 75% of current map size). This represents that after storing the 12th key-value pair into the HashMap , its capacity becomes 32.</p><h3>Note</h3><blockquote>I have stopped writing on medium and started writing on my blog <a href="https://www.pranaybathini.com/">www.pranaybathini.com</a> . Please visit to checkout the latest tech content.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/0*T9sZzO_YmPBw_RvF.png" /></figure><h4>References</h4><ol><li><a href="https://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html">https://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html</a></li><li><a href="https://javarevisited.blogspot.com/2011/02/how-hashmap-works-in-java.html">https://javarevisited.blogspot.com/2011/02/how-hashmap-works-in-java.html</a></li><li><a href="https://openjdk.java.net/jeps/180">https://openjdk.java.net/jeps/180</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8679d058d244" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-glitcher/hashmap-internal-working-8679d058d244">HashMap Internal working</a> was originally published in <a href="https://medium.com/the-glitcher">The Glitcher</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>