Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 PROGRAMMING


  Mock Solutions for GoLang Unit Test

In Go development, Unit Test is inevitable. And it is essential to use Mock when writing Unit Tests.Mock can help test isolate the business logic it depends on, enabling it to compile, link, and run independently.Mock needs Stub. Stub function replaces the real business logic function, returns the required result, and assists the test.I involved the related test code for Controllers while writing Kubernetes Operator recently, and there would be mocks for GRPC and HTTP requests. I did it in an old fashion way, but I believe there is a better and more graceful way to han...

12,187 0       UNIT TEST GOMOCK GOSTUB TESTIFY


  Generate signed certificate from CSR in Java

In our previous tutorial, we have explained how to generate CSR which can be sent to CA for generating a signed certificate. In this tutorial, we will explain how to generate the signed certificate from CSR in Java. We will not use an actual CA but a self-signed certificate to act as a CA certificate.Since the CSR contains the subject information where a certificate needs to be generated and signed for. The key here is to extract the subject information from the CSR and then set it as the subject of the newly generated certificate.The source code can be found below which has a complete example...

7,072 10       SIGN CERTIFICATE CSR JAVA


  Understand more about Go basics with one interview question

First, let's take a look at below Go interview question:package mainconst s = "Go101.org"// len(s) == 9// 1 << 9 == 512// 512 / 128 == 4var a byte = 1 << len(s) / 128var b byte = 1 << len(s[:]) / 128func main() { println(a, b)}What would be the output in your mind? The output would be 4 0. Surprising?Before getting to the output values, some concepts in Go need to be introduced and explained in more detail.len() len() is a built-in function in Go to get the length of array, slice or string. There is one important statement about len() in Go specification.For some argume...

3,833 0       LEN() SHIFT OPERATION CONSTANT GOLANG


  One good way to use optional parameter in function

In GoLang, it doesn't support method overloading like in Java, hence sometimes it would be a headache to create functions to construct new structs with different parameters. Normally, we would construct the new function as below when want to let others create a new struct instance with explicit function call.type Queue struct { Name string}func NewQueue(name string) *Queue { return &Queue{name}}But with the scope and complexity of the struct increases, there might be more properties added to Queue.type Queue struct { Name string MaxLimit int}How to enhance the NewQueue() to accomo...

9,811 0       OPTIONAL PARAMETER VARIADIC FUNCTION OPTION PATTERN


  Gaussian Blur Algorithm

Usually, image processing software will provide blur filter to make images blur.There are many algorithms to implement blur, one of them is called Gaussian Blur Algorithm. It utilizes Gaussian distribution to process images.This article is to introduce Gaussian Blur algorithm, you will find this is a simple algorithm. In fact, it is a kind of data smoothing which can be used in many situations.1. Gaussian Blur theoryThe so called blur can be understood as taking a pixel as the average value of its surrounding pixels.On the above graph, 2 is the center point, the surrounding points are 1.The ce...

107,599 8       ALGORITHM GAUSSIAN BLUR IMAGE BLUR


  Problem and Solution for Installing wxPython on Ubuntu 20.04

When we try to install wxPython lib on Ubuntu system to do software GUI development,most of time we may meet some installation and lib dependency problems. For the latest Ubuntu version, the problems still happen. Below are some common problems which happened frequently and their solution:---------------------------------------------------------------------------------------------------------------Problem [1]: Install wxPython on Ubuntu 20.04 fail because of dependency package Gtk is not installed.Error Message:No package 'gtk+-3.0' found Package gthread-2.0 was not found in the pkg-config sea...

23,017 7       UBUNTU 20.04 WXPYTHON PYTHON


  Implement struct no copy in GoLang

There is some case where some of the struct in GoLang which is not meant to be copied. For example, sometimes a global configuration which should have only one version passed around the whole application and should not be copied and modified.In GoLang, there is no intuitive solution on preventing copying of struct. But there is still some way which can be leveraged to help prevent this while developing the code. The trick is to define some struct implementing sync.Locker interface and has this struct embedded in any struct not meant to be copied.// noCopy may be embedded into structs which mus...

19,352 0       GO VET NOCOPY NO COPY


  Basic Mistakes Developers Make When Creating APIs

Today, there are many tools that developers can use to create an API, meaning that some of them can come up with an API within a matter of minutes. However, there is a vast difference between just creating an API and building one that meets all your expectations, is reliable and secure. Some developers create APIs that work well but forget some basic things that, within no time, bring a lot of issues to the API users. In this article, we are going to talk about the basic mistakes that developers make when creating APIs.Image Source: https://www.pexels.com/photo/photography-of-person-typing-118...

1,082 0       RESTFUL API API DESIGN API