Blog


What is a TCP Stream?

The TCP protocol is modeled on the concept of a single continuous stream of unlimited length. This is a very important concept to understand, and is the number one cause of confusion that we see. What exactly does this mean, and how does it affect developers? Imagine that you’re trying to send a few messages […]




Rust Gotchas – Copy and Clone

  • July 29, 2021
  • Rust

Rust has two central concepts: Borrowing and ownership. In very simple terms, Borrowing conceptually means access to the data through reference, be it mutable or immutable. This is implemented via & and &mut. For a more exhastive treatment, please refer the docs. Again, in very simple terms, Ownership conceptually means accessing without & (i.e. without […]




Docker notes

To cleanup unused/dnagling docker images: sudo docker image prune To cleanup ununsed volumes: sudo docker volume prune To list current docker images: sudo docker images To remove docker image by image_id: sudo docker rmi <your_image_id1> <your_image_id2> (sometimes, docker rmi command will throw up errors like: Error response from daemon: conflict: unable to delete 78f7412b7923 (must […]




Using Postgres inside docker container

These are my personal notes. Am running postgres docker image on a local linux box. If port 5432 is already in use, run this to see what process is using it: sudo ss -lptn ‘sport = :5432’ the above command will also display the pid using which you can kill the process. For example, if […]




Turbofish in rust

Consider the following code (or run it in rust playground here): fn main() { let a:Vec = vec![1, 2, 3]; let doubled = a.iter().map(|&x| x * 2).collect(); assert_eq!(vec![2, 4, 6], doubled); } If you ran it in the playground linked above, you will see the following compiler error. error[E0282]: type annotations needed –> src/main.rs:4:9 | […]




Rust File Builder pattern for file read writes

  • March 20, 2021
  • Rust

Consider the following test code that creates a file, writes to it and then reads back to confirm what it wrote. #[cfg(test)] mod tests { #[allow(unused_imports)] use super::*; use std::fs::{self, File, OpenOptions}; use std::io::{Read, Seek, SeekFrom, Write}; use tempfile::{tempdir, tempfile, NamedTempFile}; #[test] fn test_file() { let dir = tempdir().unwrap(); let file_path = dir.path().join(“foo.txt”); let mut […]




Temporary files and Temporary directory in Rust

  • March 20, 2021
  • Rust

I was looking for Python style temporary files and temporary directories in Rust. Very handy when writing tests for simulating actual files, or when we need to use files once or cache large amount of data for short time. We then let the operating system delete the files at a later time automatically or by […]




self in use statement in rust

  • March 18, 2021
  • Rust

I was going through some library code in a rust crate and this pattern had my head scratching: std::io::{self,Cursor}; What this is equivalent to is: use std::io; use std::io::Cursor; which means explicitly use std::io::Cursor and also use std::io itself. Thus, Cursor need not be prefixed but you’d still need to do io::BufReader and so on.




Bare bones vimrc (neovim) template for Rust

In preparing for a talk on Rust training for beginners, I thought of creating a very basic setup using vim. Instead of putting a textbook for .vimrc, with all the floatsam and jetsam of my 15 years of vim usage in different stacks, I’ve decided to remove all the fluff and kept the most basic […]




Rust tips: Box, RC, Arc, Cell, RefCell, Mutex

  • February 28, 2021
  • Rust

Difference Between Box, Rc, Arc, Cell (and its various variants.. RefCell, Mutex, RwLock) in Rust: Box is for single ownership. A great use case is to use this when we want to store primitive types (stored on stack) on heap. Rc is for multiple ownership. Arc is for multiple ownership, but threadsafe. RefCell is for […]