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

 PROGRAMMING


  The hidden risk of passing slice as function parameter

In Go's source code or other open source libraries, there are lots of cases where a slice pointer is passed to function instead of slice itself. This brings up a doubt why not passing slice directly as its internal is backed by an array pointer to point to underlying data?For example, in log package, the formatHeader function takes a parameter buf as type *[]byte instead of []byte.func (l *Logger) formatHeader(buf *[]byte, t time.Time, file string, line int) {}Let's understand the rationale behind this starting with an example.func modifySlice(innerSlice []string) { innerSlice[0] ...

7,991 2       GOLANG SLICE SLICE POINTER


  Tips of Drafting an R Markdown Document

When presenting the data summary and exploratory analysis, we used to copy a lot of tables, charts from Rstudio to PowerPoint, which makes the presentation preparation painful. It becomes essential for data scientists to make use of better reporting tools, such as R markdown, Jupyter notebook to prepare the analysis presentation in a more efficient and organized way. Of course, we want this to be reproducible!In this post, I would like to share some tips of using the right tools to draw tables, plot charts, summarize datasets, when I explore building report using R markdown/notebook.Configurin...

3,803 0       R 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,260 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,294 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,869 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,853 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...

108,075 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,148 7       UBUNTU 20.04 WXPYTHON PYTHON