giff

read
git diff terminal visualizer

giff

giff visualizes the differences between the current HEAD and a specified branch in a git repository using a formatted table output in your terminal. The differences are displayed with color-coded additions and deletions for better readability.

Features

  • Branch Comparison: Compare changes between the current HEAD and a specified branch.
  • Color-coded Output: Additions are displayed in green and deletions in red.
  • Table Formatting: Uses comfy_table to format the output.

Requirements

  • Rust (latest stable version)
  • Git
  • A terminal supporting ANSI escape codes for color output

Dependencies

This project uses the following Rust crates:

  • clap: For command-line argument parsing.
  • comfy_table: For creating and formatting tables.
  • crossterm: For terminal manipulation.
  • regex: For parsing git diff output.

Installation

cargo install giff

From source

git clone https://github.com/bahdotsh/giff.git
cd giff
cargo install --path .

Usage

giff -b branch //by default, the branch will be main

Termgpt

read
A programming and system administration assistant, powered by chatGPT!

Install

Cargo

cargo install termgpt
termgpt --help

From source

git clone git@github.com:bahdotsh/termgpt.git
cd termgpt
cargo install --path .

Usage

For the first time you have to to enter your OpenAI API key.

termgpt --api <your api-key>

This key will then be saved to:

// Linux:   /home/alice/.config/termgpt
// Windows: C:\Users\Alice\AppData\Roaming\Foo Corp\termgpt
// macOS:   /Users/Alice/Library/Application Support/termgpt

To be reused later

Questions

For now you can ask ChatGPT anything related to managing your operating system or writing code. Eventually you'll be able to ask any question to ChatGPT (couple more prompts to go) with termgpt (P.S try to avoid using '?' at the end of your questions for now).

termgpt <any question>

Executing commands

You can ask to execute the generated command using --exec argument.

termgpt --exec list all the files in this folder

Help message

termgpt --help

A cli tool to interact with ChatGPT

Usage: termgpt [OPTIONS] [CHAT]...

Arguments:
  [CHAT]...

Options:
      --api <API>  Your API key for OpenAPI
  -e, --exec       Execute the commands generated
  -h, --help       Print help
  -V, --version    Print version

Example questions

termgpt How do I list all files in the current directory
termgpt How can I find the number of lines in a file
termgpt How do I create a new directory
termgpt How can I check the available disk space
termgpt How do I delete a file
termgpt How can I search for a specific string in a file
termgpt How do I copy a file to a different location
termgpt How can I see the contents of a file
termgpt How do I move a file to a different location
termgpt How can I change the permissions of a file or directory

Inspirations

Why I built zp!

read
Talks about the process behind building zp!

For those of you who don't know, (which is going to be most of you), I recently published my very first crate; zp. zp is just a simple tool to copy contents from a file. I built zp so that I can learn rust properly. And by properly, I mean learning something and understanding it in a way I can use it to build cool/useful things in the future. The process was relatively simple than I expected and as everyone says, the toughest thing was deciding what to build. Thankfully, I didn't overthink it this time and decided to build something not complex at all. My problem statement was simple, "I need a tool to copy things from inside a file to the clipboard from my terminal". Since the problem statement was so clear, I was able to break it down into smaller parts and publish it in a day!

I was really excited when the development reached the final stages as it was working exactly how I wanted it to work. I don't know if you know, but the following are the steps to publish your crate to crates.io :

  • Add a license to your project.
  • Put up a proper README.md file.
  • Set your package information like version, description, license, etc. in the Cargo.toml file.
  • Build your project, cargo build --release
  • And finally, publish your project with cargo publish (you need to first create an account in crates.io and generate an API key to log in to your account from the terminal).

Yup, that's it! You have now published your crate. And what that means is that people will see your project and may even use it! That reality hit me a little late. I was really proud of my accomplishment and posted it everywhere I could think of.

This is when the reality of other people using my project hit kind of hard. A couple of developers used it and as it turns out, my project doesn't work at all in Linux and Windows! I should've checked it, but I didn't. My embarrassment has never reached highs like this before and was kind of hard to deal with.

Followed by this, an interesting phenomenon started to happen, people started giving me suggestions to improve my project. It was so refreshing and humbling to see really cool people giving me some really cool feedback!

What that means is that I will get to learn rust a little bit more in-depth, and of course, improve my project in the process. The first obvious feedback I'm going to work on is to make my project cross-platform compatible, and will soon be dropping a blog on that later.

Also since you have read this much, do check out my blog!

Zp

read
A cli tool to copy things!

zp

zp is a cli command to copy the contents of the source file or of the std output buffer to the clipboard. To use the zp, simply open your terminal or command prompt (well install it first) and type zp followed by the name of the source file. For example:

zp my_file.txt

To get the first n words of the file :

zp -s n my_file.txt

To get the lines between a range, i.e., to get lines from n till m of the file:

zp -s n -e m my_file.txt

Also you can use zp to copy from the std output buffer :

cat sample_file.txt | zp

This copies the entire output of the file.

You can use get a range of lines and the first n words also from the std output buffer :

cat sample_file.txt | zp -s 2

cat sample_file.txt | zp -s 2 -e 5

This gets the first 2 words and lines from 2 to 5 of the sample_file.txt respectively

This will copy the contents of "myFile.txt" to the clipboard.

Logs and History

Every copied content is saved to a history file, allowing you to revisit previously copied entries. To view the copy history, use:

zp --logs

The "zp" command is particularly useful for quickly copying text or data from one file to another without having to manually select and copy the text. This can save time and effort, especially when working with large or complex files.

Install

It's best to use rustup to get setup with a Rust toolchain, then you can run:

cargo install zp

From source

git clone https://github.com/bahdotsh/zp.git
cd zp
cargo install --path .

Art, Time and Life

read
An essay on art, time and life.

He drew in haste. He had deadlines to meet. It was ridiculous. This is not how it was supposed to be. You can never rush art. But he had to. He was bringing art to the realm of time. And he knew that it would bounce. He had no choice. The world is moving fast and he had to keep up with it. You can never complete a work of art on time. Art never belonged to that dimension. The concept of time is foreign to Art. And in a way, it’s the gateway out of it. You can submerge yourself in art and let time fly by. And since art doesn’t belong to the dimension of time, you can never define art with time. The equations would seem completely ridiculous. Art is concentrated patience. It demands patience, to create, and to enjoy.

The moment you realize that patience creates art, why not make your life an art? Be patient and be prepared. Remember, art is really powerful, as it can change not only you but also the people around you. Immerse yourself in your art, whatever it is, and witness the magic that would unfold. And if you’re waiting till you find something that you’re good at, don’t forget that the one thing you can be good at is living your life and that one thing is all that matters.

Are your thoughts really yours?

read
Are your thoughts really yours?

Are your thoughts really yours? You may be wondering why I’m asking such a bizarre question again and again. Of course, my thoughts are mine, you may say. But, are they? That may take some time. So, let’s just focus on “the how” part for now. How do you think? Well, all of us think in some kind of a language. Most probably our mother tongue. If you are someone whose mother tongue is English, then most probably you would be thinking in English, you just have 26 letters to form the words for your thoughts. Why are there only 26 letters in the English alphabet? In my mother tongue, which is Malayalam, I have 52 letters to form the words for my thoughts. Does that mean I have the potential to think more(double) than what an English speaking folk can?

Now as we have messed up the ‘how’ part let’s move back to the ‘what’ part. Whatever your mother tongue is, it was taught to you by the people around you. Not only your mother tongue, whatever language you learn, somebody taught it to you. They taught you that language not to make you a poet or a writer, but to exchange their opinions and believes onto you.

What does this mean? Your thoughts are not yours. Your thoughts are the byproduct of your interactions with an “educated” environment. You are getting influenced everyday. You are totally blind to what you are learning. You are only thinking what you are supposed to think. The reason you can’t think beyond the 26 letters of the English alphabets is only because you don’t have to. Everybody around you thinks with those 26 letters. You’re just thinking whatever you’re thinking only because you want to co-exist with the people around you.

If our thoughts are not really ours, then what do we have?

Let me end with something one of my professors said

“Whatever you have learnt was taught to you. And whatever taught to you were somebody else’s opinions”

I don’t think this thought is mine. And I can’t be right, can I?

How does the blockchain work? Part 2

read
How does the blockchain work? Part 2

Before looking at Merkle trees, let’s see what a tree actually is when it comes to programming. In simple terms, trees are nothing but representations of how data is stored in the memory.

Trees

               P (Root)
              /      \
            Q          R
           / \        /  \
         A   B      C    D
                    |
                    M
                   / \
                  H   I (Leaf nodes)
                 (Leaf nodes)
           L (Parent)
         /  |  \
        E   F   G (Children)

When you look at the above picture you’ll see some of the terms we use while defining trees. P is the root node. Root node is the node which is present at the topmost part of the tree. Keys are the values stored inside each of the nodes. Edges are the connection between one node and the other. Parent nodes(R is the parent of C and D)are nodes which have a branch from one node to the another and the child nodes(A and B are the child nodes of Q) are the nodes connected to the parent nodes. The children of the same parent node are called sibling nodes(E, F, G and A, B and C, D and H, I and Q, R are all siblings respectively). And the nodes with no children are called leaf nodes(H, I, D, and B are all leaf nodes). Now the number of edges between a node and the root node is called the depth of the node. For example, let’s take the node ‘A’. A is connected to Q and Q is connected to P(root node). There are two edges between A and P. Therefore the depth of A is 2. Note that the depth of the root node is 0. Level of a node is nothing but depth of the node + 1. Which means the level of A is 3.

Whew, that was a lot of definitions. The good news is you don’t have to try hard and remember any of those. Once you have compared the definitions to the picture of the tree above, you can easily understand what they mean. And then the next time you see a tree, you can easily understand them in a glance.

So after knowing the terms used in building trees, we can say that a tree is nothing but a collection of nodes.

Merkle Trees

Ok, as you are now familiar with trees let’s get to business. What are these Merkle trees? Merkle trees are a fundamental part of blockchain technology. One of the main reasons why blockchain is super famous is because of the security and efficient storage of data. Merkle trees are used to achieve this. It helps in efficient and secure verification of content in a large body of data.

If you forgot what hashing means, quickly go to my previous previous article and read up on it and come back. It’ll only take you a few minutes and will help you understand what I’m going to tell you next better.

In a Merkle tree, each leaf node is a hash of a block of data, and each parent node is a hash of its children. Yeah, that’s it. It’s that simple. Also to make things more simpler, Merkle trees usually have a branching factor of 2. Don’t frown, my friend, it just means that each node has children. Merkle trees are created by repeatedly hashing pairs of nodes until there is only one hash left (this hash is called the Root Hash, or the Merkle Root). They are constructed from the bottom up, from hashes of individual transactions. The Merkle Root summarizes all of the data in the related transactions and is stored in the block header (a block header is the unique identity of a particular block on a blockchain and is hashed by miners for rewards). It maintains the integrity of the data. If a single detail in any of the transactions or the order of the transactions changes, so does the Merkle Root. Using a Merkle tree allows for a quick and simple test of whether a specific transaction is included in the set or not.

Merkle trees are powerful and indispensable tools for miners and users on the blockchain. They are extremely robust and are at the heart of several peer-to-peer networks such as BitTorrent, Git, Bitcoin, and Ethereum.

How does the blockchain work? Part 1

read
How does the blockchain work? Part 1

Blockchain is a combination of several different technologies. For making it easier for you, I have broken it down into simpler parts. This is the first part of this series and it’s all about one of the most important technologies used in blockchain; cryptography What is cryptography? The prefix “crypt” means “hidden” and the suffix “graphy” means “writing.” Since that is out of the way, let’s see what it is. But before that let’s do something fun. Let’s create a secret code. Exciting, isn’t it? Let’s say that we have to subtract ‘1’ from each of the letters in our code to find the original letter. Cool. Since we have created a code and both of us know how to read it, if I write “BQQMF” both of us can easily understand what that means. But if you show it to your friend who has no clue about our secret code, it’d just be a senseless word for him.

This is what cryptography is. It’s a technique to secure information and communications through codes which only the sender and receiver can understand. When I changed “APPLE” to “BQQMF” what I did was encryption. And when you cracked the code, what you did is called decryption

When you learn about a particular technique you’ll have to remember some terms associated with it. Like encryption and decryption, there are a bunch of other simple words associated with cryptography. Let’s see what they mean.

Let’s take our example. In the world of cryptography, the word APPLE which we encrypted is called plain text, and the code BQQMF is called ciphertext. You won’t be able to read BQQMF as APPLE if I didn’t tell you how to read it, that is, to subtract 1 from each letter. So ‘-1’ is what we call the key of our cryptographic algorithm. Without which we won’t be able to understand what each of us is saying.

Now let’s see some of the types of cryptography.

Symmetric Key Cryptography

In this system both the sender and receiver use a single key for encryption and decryption. Our cryptographic algorithm is an example of Symmetric key cryptography.

Asymmetric Key Cryptography

You can easily guess what this would mean from the previous definitions. Yes, you’re correct, in this cryptographic system, there are two types of keys, a public key and a private key. The public key is used for encryption and the private key is used for decryption. Both the keys would be different. Even if the public key is known to everyone, only the intended receiver can decode it because he alone knows the private key.

Asymmetric encryption can be likened to a mailbox on the street. The mailbox is completely public — anyone who knows its location could go to it and drop in a letter. However, only the owner of the mailbox has a key which allows him to access it and read the letters. The location of the mailbox is the public key, something that is known to the public. The private key is with the owner of the mailbox, which is used to access the mailbox.

Hash Functions

In this algorithm, there is no key. These functions change the entire plain text to a new encrypted form, called the hash value. The hash value will be of the same length for whatever plain text fed into it. Since there is no key it is nearly impossible for the contents of the plain text to be recovered.

Public key cryptography and hash functions are used throughout blockchain. There is also another interesting cryptographic technique used inside blockchain called Merkle Trees. A Merkle tree (or hash tree) is a tree that utilizes cryptographic hash functions to store hash outputs instead of raw data in each node. We’ll see what they mean in-depth in the coming articles.

The Blockchain Dictionary

read
Get familiar with some of the terms we may repeatedly come in close contact with; every time we talk blockchain.

Bitcoin prices blew up in 2017, reaching a peak of a whopping $20,000. After that, the entire planet was talking about this new technology called blockchain. We saw in our previous article what this blockchain actually is. Now let’s get familiar with some of the terms we may repeatedly come in close contact with; every time we talk blockchain.

Cryptocoin or cryptocurrency

Cryptocurrency is a fancy word. But its meaning is boringly simple. It’s just money. The only difference is that this money is completely digital. Which means, it doesn’t exist out of your computer. And you can use it just as how you’d use the conventional money; to buy things.

Bitcoin

Bitcoin is one of the reasons why blockchain became a common term. Bitcoin is a cryptocurrency implemented using blockchain technology. It is the world’s first decentralized cryptocurrency. It was invented in 2008 by an unknown person or a group of people using the name Satoshi Nakamoto. There’s no central bank or any single intermediary administrator to control the issue and supply of bitcoins. This is one of the reasons why bitcoin became very famous.

Mining and Miners

For a transaction to occur inside the blockchain network it should be validated by a group of members inside the network. This group of people who validate each transactions are called Miners. And this process of validation is called Mining.

Smart Contract

A contract is an agreement between two or more parties to do something. A smart contract is the digital version of this contract. Smart contracts help you to exchange anything of value in a transparent, conflict-free way while avoiding the services of a middleman. It is a self-executing or self-enforcing agreement. Which means that, if the rules of the agreement are met, the agreement is automatically enforced.

Ethereum

Launched in 2015, Ethereum is an open-source, blockchain-based, decentralized software platform used for its own cryptocurrency, ether. It enables Smart Contracts and Distributed Applications (DApps) to be built and run without any downtime, fraud, control, or interference from a third party.

Hyperledger Hyperledger is a blockchain framework to develop blockchain-based applications, mainly for enterprises.

Tokens

Tokens are digital assets in a blockchain network. Ok, don’t scratch your head. You have been to a gaming arcade, right? So what did you do there? You gave some money in the counter and got a card in which you can swipe on the gaming consoles of the games you wanted to play. That card acts like money in that particular arcade and you got to enjoy the games without any hassle and worry of payment. But if you take that card to Starbucks and demanded a caramel frappuccino the only thing you’d get would be a disappointment. This is exactly how a token works. They can act as a stand-in for money in a particular blockchain network. And outside that network, the tokens are basically worthless.

Blockchain: A short sneak peek

read
A short sneak peek about blockchain

Blockchain is revolutionizing the Internet as we speak. From cryptographer David Chaum to Satoshi Nakamoto, a new door to fundamentally change the way Internet transactions can be implemented was opened. So, what is this blockchain and what is this revolution everybody is talking about? To get an idea about all this first let’s understand how the “current Internet” shares information. We know that ,“the internet is a collection of computers that share information”. All the data shared in this network is centralized. This means that if we take an instance of data sharing inside this network, there will be only two participants. No computer acts as an observer or as a validator when two other computers are sharing data.

Blockchain on the other hand is de-centralized. Which means that the exchange of information must be observed and validated (approved) by everyone on the network. If the validation doesn’t happen, then, the transactions(exchange of information) will be invalid.

This change is the revolution. This brings transparency, authenticity and immutability to the network ; everything which was missing from “the internet”.

Now let’s see what a blockchain is. “Blockchain is a distributed, de-centralized, public ledger”. Nope, it’s not that difficult as this definition. Blockchain is literally just a chain of blocks. The blocks contains information about the various data transactions in the network and they are connected with each other through cryptographic chains.

That was easier to understand, right? But then what kind of information does the block hold? We know that blockchain is all about transactions and the blocks are a way to register these transactions. Suppose both of us are inside a blockchain network and we engage in a transaction. The block that records our transaction will have the date and time of the transaction, both our names (our names recorded in the block won’t be our actual names but would be our corresponding “digital singnatures”). It will also have information about what the transaction was all about. This block will be validated by other members present in the network and if they approve, it will be added to the rest of the blocks already inside the network. So in simple terms a block is an instance of a transaction.

As you can visualize the block now, imagine hashing the contents of the block using a hashing algorithm (SHA-256). But what the hell is this hashing? Don’t sweat your brows, hashing simply means that we are taking an input string of any length and giving out an output of a fixed length. The SHA-256 is an algorithm to achieve this. This is how the block exists in the network.

We have just discussed about a single transaction. But in reality a block can hold upto 1 MB of data. This means that a single block can house a few thousand transactions(depending on the size of each transactions).

This is just a basic introduction about blockchain. Let’s look into the working of blockchain and all it’s intricasies in the coming articles.

While reading about this revolution you may come face to face with some interesting words. Bitcoin, Ethereum, Hyperledger, smart contracts etc. I will explain what some of these means in the articles which will drop soon.

Random rant about silence

read
Rant about silence!

Can you hear it, the sound the sunlight make when it first hits the ground? Or the sound the raindrops make, when they gently kiss your forehead? Can’t you hear it, the sound darkness make, as it gently floods the dusk? Yes, you can! All you have to do is listen. Close your eyes and listen. And as you listen, notice that your heart is surprisingly in rhythm with this beautiful music of silence. Intoxicating, isn’t? Now go ahead and set the tempo. Dance around and smile. Don’t be afraid, of falling out of rhythm, because you are the one who sets it.

The Jump

read
Jump!

His heart started beating faster as he climbed.

Every new step pumped an ounce more adrenaline to his veins.

He was breathing faster.

The wind soothed him.

But at this moment peace terrorised him. The walk to the edge was the toughest.

It was as if he forgot how to walk.

Trembling on every step, he reached the edge.

He knew he wasn’t brave enough to be there.

Yet there he was.

He didn’t have the courage to look down.

The wind rustled beneath his feet and played with his hair.

The silence and calmness up there contrasted with the busy street below.

Far below.

The sky seemed conquerable from here.

He would soon do that anyway.

He loved the view.

He felt like God.

The wind beckoned him.

He looked up to the sky,

It looked like an ocean beside a desert.

Soon he would be swimming in that ocean.

He just had to let go of his fears.

He took two more steps.

Now, there’s nothing in-front of him.

Nothing solid.

He had to arch a bit backwards so as to counter the pull of the wind.

Gravity seemed to get stronger with every second.

Gravity was the one thing that he longed to defeat, his greatest enemy.

He was sure though, that he would be the one who wins tonight,

Not gravity.

He took a deep breath and then held it.

His heartbeat made him deaf.

He raised both his hands to his shoulders.

Straightened up.

And dove.

Weightless.

He was flying.

His heart was beating so fast, he couldn’t hear it anymore.

Adrenaline replaced blood.

He won!

The world was getting closer.

He was laughing.

He closed his eyes.

He loved it.

Everything stopped.

He was numb.

The sky seemed so far right now.

He was suddenly so sleepy.

He fought to keep his eyes open.

He tried to raise his hand.

Nope. He was so tired.

He was afraid that he won’t be able to open his eyes if he closed them.

He had to.

He did.

Life

read
Life!

Smoke, Heavy head, Lights.

Cough, breathe, repeat!

Blurry vision and weightless body.

Seeing life as if in a Cinema.

Echoing sounds and blurry vision. Focused and unfocused at the same time,

He ran, not really. But he did anyway.

Where to? He didn’t knew.

Why? Because he could.

Mind couldn’t catch up with his thoughts.

Cough,breathe, repeat!

Animated life.

Life!

“What does it mean?” He asked.

“Does it matter?”

Nope, it doesn’t!

Run, fly, walk, breathe!

Forget about life and focus on living.

The answer

read
The answer!

“And they lived happily ever after”

The story ended.

The thought didn’t.

“Happily ever after”! The thought echoed.

Did the author had a typo?

Did he forget to put a question mark at the end?

Does happiness last for ever?

Maybe happiness is for royalty.

How can a hungry stomach be happy?

How can a thirsty mouth smile?

Hunger made him hate food and

Thirst made him hate water.

There was no happiness in his world.

Hate defined his life.

His wandering mind was suddenly at peace

his hungry stomached stopped growling at him,

his thirsty mouth sealed shut,

his tired eyes stopped blinking.

And as he saw her smile

He knew

Love was the answer.

Beyond actual hues

read
bah

green? red? yellow?

no! no!

yellow? orange? white

no! no!

black. pitch black!

what was it? a dream!?

a story!?

a poem!?

no! no!

it was life!

was it colorful?

yeah it was. i saw all the colors. you did too!

it was beautiful,wasn’t it?!

as beautiful as the colorful dark sky without the moon in the darkest night.

well of course,

black is the most colorful color.

when you go beyond all the actual hues.

The night

read
Night time!

Night.

The moon, the stars.

The wind kissed the trees.

Owls shrieked.

Wolves howled. A lively night.

A beautiful night.

A scream.

A girl.

Two men.

No! no! Two animals.

Blood.

Night.

The moon, the stars.

The wind kissed the trees.

Owls shrieked.

Wolves howled.

A lively night.

A beautiful night?

Death

read
From the perspective of Death

“Breathe! Breathe!”

she couldn’t

she forgot

“Come on beth, open your eyes!”

she couldn’t

she forgot “Say something!”

she couldn’t

she forgot

“Where am I?”

she doesn’t know

her eyes won’t open

or was it really dark?

she couldn’t tell

“Just breathe”

she couldn’t

it was easy

she knew

but couldn’t

“Help me!”

she screamed

she couldn’t hear herself

“Is this a dream!?”

she never knew

“You’re dying!”

“No,I’m not!”

Wait who was that?

Who said that?

Is somebody there with her

“Who is this?”

No answer

“You’re going to die”

The voice came again

“Who’s this? Answer me!”

No reply

She was angry

She started smiling

Suddenly she cried

She laughed

She screamed

She saw darkness

She felt at ease

“No, no I can’t give in”

“I won’t die”

“I simply won’t”

Death smiled

He never lose.

The Moth

read
The moth's perspective!

Nobody knows why,

why I follow the light

People think I crave it

They think I’m afraid of the darkness

And that I will die without it But no,

I love darkness

It never hurts you

Nothing’s as peaceful as darkness,

as silent as it is,

And nobody as great a listener.

Wait, let’s stick to the actual question.

Why I go to the light when I love darkness so much

Well, haven’t you noticed?

The light’s always alone.

It’s always angry.

Screaming its anger at the world.

And every time I kiss the light,

it screams a little less.

It calms down.

And one day I’m sure

I will save it

From all it’s miseries

I will take away the pain from the light

And make it happy

Like how darkness always is