Skip to content

Instantly share code, notes, and snippets.

View de-sh's full-sized avatar

Devdutt Shenoi de-sh

View GitHub Profile
@de-sh
de-sh / rust_from_python.md
Last active September 4, 2019 09:58
Lets rust your python :D

Backstory

I have been learning rust for quite some time now and its structuring as a language is pretty funny. The promises are themselves a huge undertaking for the project. But for me, I have been interested, because of one simple reason, its fool-proofness.

"Fool proof?" you might ask, well yes! The language is practically an interesting take on the challenge to build a systems-level/C-type alternative to... well, C(C++ also kinda makes it into that category, but that debate is for another day). I have been into rust officially, for around 3 months now and it is interesting how easy it is to get tired and kick yourself out of learning it.

I think that is exactly why I am writing this log, because I want to share an interesting find I had while learning for myself. To take you back into the reasoning behind this post, I have been understanding the basics of this language with help from exercism, a language learning platform, akin to duolingo, but for pr

@de-sh
de-sh / RustyBeginnings.md
Created March 17, 2020 11:25
Rust ELI5?

Rusty Beginnings

Hey there, so you wanna become a rustacean? I see you are interested in rust-lang and want to understand the madness behind the magic that makes it a safe, speedy and concurrent language to write software in. So it's always safe to understand why you should learn it in the first place, lemme give you a quick pitch!

Why learn rust?

Rust is the language of the next 40 years, don't take my word for it, check out the talk! It is built to alleviate a problem that ~99% of all software developers face when writiing low-level and performant code. But it is also being developed to scratch common itches and unsafe programming practices, such as building in a Garbage Collector to manage memory, which languages such as Python and Golang do!

Rust-lang on the other hand manages memory by making use of a complex borrow-checker mechanism that does it by following your commands as given in the program. This is also done at compile time, so you do

@de-sh
de-sh / control_flow_rs.md
Created March 18, 2020 12:09
Introducing the basic control-flow syntax of Rust

Control Flow

In the last one we wrote and ran our first rust program from scratch, today let's add some code to make much more...

Control flow?

Yes, rust like every other computer program controls the flow or processing of data by using special schemes. Ever heard about the if-else, while or for statements? They are the basics of what most programming languages are trying to achieve, but rust has more!

if this { return that; } else { return what; } ?

Yeah, so that's valid rust, considering this is a boolean(either true or false) value as well as that and what are variables with the same type as the function is supposed to return.

@de-sh
de-sh / match_rs.md
Last active June 13, 2020 07:01
Rewriting if-else conditionals as match statements

It is common in computing, to come across a conditional statement that contains a lot of ANDs, ORs and more. With rust-lang's powerful match statement, a programmer can easily convey the message, let's see how.

match statements takes pattern matching to another level. Using the simple syntax, one can also achieve what nested/ladder if-else blocks could. Here is a sample if-else code block.

if year%4 == 0 {
  if year%100 != 0 || year%400 == 0 { 
    println!("Leap Year"); 
  } else { 
    println!("Not a Leap Year"); 
  } 
@de-sh
de-sh / fib_rs.md
Last active April 29, 2020 18:44
A program to print the Fibonacci sequence upto n numbers

Another use of the match statement could be to handle termination conditions, this expands on what we discussed on day 1!

Here is a C function that prints the nth term of the fibonacci sequence.

int fibonacci(int n)
{
    if(n==0 || n==1) return 1;
    else return fibonacci(n - 1) + fibonacci(n - 2);
}
@de-sh
de-sh / fiboops_rs.md
Last active May 1, 2020 13:30
Memoization of Fibonacci series program to find nth term and using the OOPs concepts in rust to not recompute the sequence.

Today, while discussing how to lower demand on computing resources while generating the Fibonacci sequence, especially when it is to be queried a lot of times within a program, we came to experiment with memoization. In a simple program by @shanavas786, he implemented memoization with HashMaps, but to make it simpler, and since the concepts are almost the same, I would like to use Vec instead.

The struct in rust are sort of like classes, they can hold data and associated methods. Let's see how we can arrange the data.

struct Fib {
    cache: Vec<u64>
}

Yes, that's it! The objects of Fib will hold a Vec cache. But there's more, while we could simply make an object with let seq = Fib { cache: vec![0] };, that won't help us achieve our goal, we need constructors and methods. To define methods for a struct we impl, as we do below.

@de-sh
de-sh / macro_rs.md
Last active May 2, 2020 21:20
Writing macros because we all are such lazy coders :p

So, I had recently contributed to the malluscript esoteric programming language. It was a quick fix to what I thought was broken, or more aptly, shabbily written piece of code. But even with my edits, it seemed to be smelling foul. So let's experiment with something new to see if it helps!

Here's the code we have at the offset

...
#[derive(Clone, Debug)]
pub struct Keywords {
 pub list: HashMap,
@de-sh
de-sh / tikv_intro.md
Last active May 7, 2020 09:35
A short introduction to TiKV and my work on making it a cloud native application

This is an introduction to TiKV, a Key Value Datastore that I have been selected to work on for Google Summer of Code 2020. I am supposed to be making it a cloud native product that espouses the properties of cloud nativity as defined by the Cloud Native Computing Foundation which is the organization I am to work under.

A KV datastore is a much more distributed and scalable version of the Python dictonary or JSON model of key->value data storage. It provides a user with the option to GET or PUT data from/into a database that is semi structured and contains a mapping between the keys and their associated values.

@de-sh
de-sh / cloud_native.md
Last active July 29, 2020 05:28
This documentation of my understanding of Cloud Nativity

I shall be documenting my understanding of the cloud native paradigm of application development as I progree through the learning journey on my way to building a cloud native KV datastore with the TiKV project.

A Cloud Native service espouses the properties of replicability(can be replaced/replicated), disaster recovery and most importantly scalability. A product in this realm is supposed to provide it's users with the ability to create applications that aren't heavily impacted by issues that might come from each service, truly abstracting them from the background details.

According to the CNCF the following definition is valid:

Cloud native technologies empower organizations to build and run scalable applications in modern, dynamic environments such as public, private, and hybrid clouds. Containers, service meshes, microservices, immutable infrastructure, and declarative APIs exemplify this approach. These techniques enable loosely coupled systems that are resilient, manageable, and observable. Combined

@de-sh
de-sh / week_one.md
Last active June 14, 2020 16:07
A report of work done in week one of the Google Summer of Code 2020 program

I started the coding phase of GSoC with a very simple understanding of the task at hand and have been trying to materialise and better understand the exact implementation details of the project over the past 20 days, ever since @little-wallace provided me with the proposal document. I would like to document the process in a few concise notes that shall later be collected into a memoir/blog.

May 30th - June 6th: Work on coding the EBS integration into TiKV begins with research into rusoto_ec2, a crate that allows for AWS EC2 instance interaction from within rust programs. rusoto_ec2::EbsBlockDevice is a struct within the mentioned crate of particular importance to the project and it provides an interface for the program with EC2/EBS volumes. Creating a new