How to update feature branch in Git

git

When working on a source code that has multiple contributors, it can be so that the feature branch that you are currently working on is behind by a few commits. This can happen when someone else on the team merges their commits to the main branch while you are working on the feature branch. To bring in the latest commits to your feature branch, you will need to either rebase to the main branch or merge the local main branch to your feature branch after pulling in the latest commits from the remote main branch.

Receive Messages from AWS SQS using Go

development golang aws sqs

In order to work with AWS SQS using Go, we will use github.com/aws/aws-sdk-go-v2. In this gist, we will use the aws-sdk-go-v2 package to receive messages from a queue in AWS SQS. The complete source code for the snippet is available here https://github.com/abvarun226/blog-source-code/tree/master/receive-messages-from-aws-sqs-using-go

Send Messages to AWS SQS using Go

development golang aws sqs

In order to work with AWS SQS using Go, we will use github.com/aws/aws-sdk-go-v2. In this gist, we will use the aws-sdk-go-v2 package to send messages to a queue in AWS SQS. The complete source code for the snippet is available here https://github.com/abvarun226/blog-source-code/tree/master/send-messages-to-aws-sqs-using-go

Delete Queues in AWS SQS using Go

development golang aws sqs

In order to work with AWS SQS using Go, we will use github.com/aws/aws-sdk-go-v2. In this gist, we will use the aws-sdk-go-v2 package to delete queues in AWS SQS. The complete source code for the snippet is available here https://github.com/abvarun226/blog-source-code/tree/master/delete-queues-in-aws-sqs-using-go

List Queues in AWS SQS using Go

development golang aws sqs

In order to work with AWS SQS using Go, we will use github.com/aws/aws-sdk-go-v2. In this gist, we will use the aws-sdk-go-v2 package to list queues in AWS SQS. The complete source code for the snippet is available here https://github.com/abvarun226/blog-source-code/tree/master/list-queues-in-aws-sqs-using-go

Create Queues in AWS SQS using Go

development golang aws sqs

In order to work with AWS SQS using Go, we will use github.com/aws/aws-sdk-go-v2. In this gist, we will use the aws-sdk-go-v2 package to create queues in AWS SQS. The complete source code for the snippet is available here https://github.com/abvarun226/blog-source-code/tree/master/create-queues-in-aws-sqs-using-go

Search operation in Go

development golang search generics

Searching for an item in a collection or container is a common operation in programming. In Go, there are a few different ways that this can be done. In this snippet, let us explore the ways in which an item, be it a number or string, can be searched in a slice.

Strings Concatention In Go

development golang

In today’s snippet, let’s look at how to use string builder and bytes buffer to concatenate a list of strings. You can always use the + operator to concatenate strings, but it is memory inefficient just like in so many other languages. Each time + is used to concatenate a string, it allocates a new string in memory. This is because, like in most languages, strings in Go is immutable. To avoid this inefficiency, we can use Go’s strings.Builder and bytes.Buffer type. Let’s look at how we can use these types to concatenate strings.

Checksum Validation In Go

md5 sha256 checksum golang

In today’s snippet, let’s look at how to generate checksum of a string or a file in Go. A checksum is a cryptographic signature of a file or a string. It is usually used to check if a file or stream of bits has been tampered or modified. If the file is modified, the checksum for the file changes. There are various cryptographic algorithms available to generate the checksum of a file or string, the popular algorithms are md5 and sha256. Let’s look at how we can generate these checksums in Go.

Ordered Printing With Goroutines In Go

development golang

In today’s snippet, let’s look at how we can use synchronization techniques in Go to print natural numbers in order from two different goroutines. In our example here, we have two goroutines; one goroutine will print even numbers while the other goroutine will print odd numbers, but the output has to be in increasing order. To implement this, we will use a channel to synchronize the printing in the two goroutines. We will also use sync.WaitGroup to wait for the goroutines to finish before exiting the code. Note that we will need an unbuffered channel so that one goroutine is blocked while the other is printing the number. The even goroutine will use the done variable to indicate to the odd goroutine that it is done with the printing and there is nothing listening to the syncChannel. Without this, you will see a deadlock at the end of the printing.

Implement a queue using two stacks in Python

algorithms python

A queue is a First-In-First-Out linear data structure, i.e., the element that is first inserted into the queue is the element that comes out first. The operation that involves inserting an element into the queue is called enqueue. The operation that involves removing an element from the queue is called dequeue. Normally, a queue is implemented using an array and two pointers; front and rear. This makes the time complexity of enqueue and dequeue operations O(1).

In this snippet, we will instead look at implementing a queue using a stack. This may increase the time complexity of the enqueue or dequeue operations, but the idea here is to see how such an implementation will look like. A stack is a Last-In-First-Out linear data structure. Here the last element inserted into the stack is the first element that comes out of the stack. It has push and pop operations where push inserts the element into the stack and pop removes the last inserted element from the stack.

Context Cancellation in Go

development golang context

In Go, we can use context to send cancellation signals to goroutines that is doing some work. The Done method in context returns a channel that acts as a cancellation signal to goroutines using the given context. When the channel is closed, it indicates to the goroutines that they should stop the work they are doing. We can use WithCancel context function to obtain a new context along with the cancel function that can be used to close the channel.

Delete Files From AWS S3 using Go

development golang aws

In order to work with AWS S3 using Go, we will use github.com/aws/aws-sdk-go/aws. In this gist, we will use the aws-sdk-go package to delete all files under a given directory in a given bucket. The complete source code for the snippet is available here https://github.com/abvarun226/blog-source-code/tree/master/delete-files-in-aws-s3-using-go

In order to test the snippet, we will use localstack to run s3 emulator in a docker container on the laptop. The container exposes s3 endpoint on port 4566. The snippet will then create a new bucket work-with-s3 in s3. The snippet will then delete all files from blog directory under work-with-s3 bucket.

Listing Files in AWS S3 using Go

development golang aws

In order to work with AWS S3 using Go, we will use github.com/aws/aws-sdk-go/aws. In this gist, we will use the aws-sdk-go package to list files under a given directory in a given bucket. The complete source code for the snippet is available here https://github.com/abvarun226/blog-source-code/tree/master/listing-files-in-aws-s3-using-go

In order to test the snippet, we will use localstack to run s3 emulator in a docker container on the laptop. The container exposes s3 endpoint on port 4566. The snippet will then create a new bucket work-with-s3 in s3. The snippet will then list all files in blog directory under work-with-s3 bucket.

Uploading Files to AWS S3 using Go

development golang aws

In order to work with AWS S3 using Go, we will use github.com/aws/aws-sdk-go/aws. In this gist, we will use the aws-sdk-go package to upload files under a given directory. The complete source code for the snippet is available here https://github.com/abvarun226/blog-source-code/tree/master/uploading-files-to-aws-s3-using-go

In order to test the snippet, we will use localstack to run s3 emulator in a docker container on the laptop. The container exposes s3 endpoint on port 4566. The snippet will then create a new bucket work-with-s3 in s3. The snippet will then upload couple of files to blog directory under work-with-s3 bucket.

About

Bharghava Varun Ayada is a Staff Software Engineer at Walmart Labs, living in Bangalore, India. This blog is about software engineering, system design, distributed systems and DevOps.


Github / Twitter / LinkedIn / Dev.to / Stackoverflow


Recommended Books
Designing Data-Intensive Applications / Staff Engineer / Building Microservices / Site Reliability Engineering

Get new posts by email