PROGRAMMING


  Can two new objects point to the same memory address in GoLang?

Do you have any idea what the output will be for below GoLang snippet?package mainimport ( "fmt")type obj struct{}func main() { a := &obj{} fmt.Printf("%p\n", a) c := &obj{} fmt.Printf("%p\n", c) fmt.Println(a == c)}Many people would think that a and c are two different object instances which have different memory addresses. Hence a == c will be false. But if you try to run the above program, you would see below output0x5781c80x5781c8trueTo get to know the reason why the comparison returns true, some understanding of how Go allocates memory and how variable memory escape happens are ne...

12,393 0       ZEROBASE VARIABLE ESCAPE GOLANG GO


  An experience on fixing HTTP 406 Not Acceptable error

This post is about an experience of mine on fixing a HTTP 406 Not Acceptable error seen on one of my page.Just got back from a business trip and opened my computer as usual to start to monitor my website statistics. But when I opened the page on showing real time page views, it shows nothing but zero. So I pressed F12 to bring up the developer tool to check on what's going on. The logic of loading the real time page view is backed by AJAX call. In the developer tool console, I see that the rAJAX request gets HTTP 406 Not Acceptable error. And in the network tab, see similar result.This confuse...

10,140 1       HTML AJAX HTTP 406 PHP CONTENT-TYPE


  Bug caused by using changeable value as the default in "python method overload"​

In python we can set the passed in parameter's default value to make the function has the same running feature as the method overload in Java.Define a function like this:def testFunction(self, param1, param2=None, param3=None):Normally we use "None" as the parameter's default value. We can also use str/bool as the default value, but is it OK we use empty list [] as its default value?This is our test program:""" A test program using empty list as the passed-in parameter's default value."""class TestFunc(object): def __init__(self, id, parm = []): self.ObjId = id self.parm = ...

2,916 0       PYTHON


  Algorithm: Traverse binary tree

PrefaceThere are three ways to traverse a binary tree based on the traversing order.Pre-Order: Root - Left - RightIn-Order: Left - Root - RightPost-Order: Left - Right - RootTake below binary tree as exampleThe node to be traversed in different order would bePre-Order: A - B - C - D - E - FIn-Order: C - B - D - A - E - FPost-Order: C - D - B - F - E - ABelow are the implementations of different orders for traversing the binary tree.Pre-Order TraversingRecursive implementationNon-recursive implementationIn-Order traversingRecursive implementationNon-recursive implementationPost-Order traversing...

2,375 0       ALGORITHM BINARY TREE


  The difference between System.load and System.loadLibrary in Java

When writing code using native library in Java, normally the first step is loading some native library.static{  System.load("D:" + File.separator + "Hello.dll");}JDK provides two ways to load libraries:System.load(String filename)System.loadLibrary(String libname)This post will try to explain the differences of these two ways.According to Java Doc on System.load(), it has below description.Loads the native library specified by the filename argument. The filename argument must be an absolute path name.The parameter of this method should be an absolute file path with the exten...

26,006 1       SYSTEM.LOADLIBRARY SYSTEM.LOAD JAVA JNI NATIVE


  What is Hystrix and How does Hystrix work

BackgroundIn distributed systems, there is one effect where the unavailability of one service or some services will lead to the service unavailability of the whole system, this is called service avalanche effect. A common way to prevent service avalanche is do manual service fallback, in fact Hystrix also provides another option beside this.Definition of Service Avalanche EffectService avalanche effect is a kind of effect where the service provider fails to provide service which causes the service caller also fail to work. And this kind of service unavailability will propagate to the whol...

4,253 0       AVALANCHE EFFECT HYSTRIX DISTRIBUTED SYSTEM


  git reset vs git revert

When maintaining code using version control systems such as git, it is unavoidable that we need to rollback some wrong commits either due to bugs or temp code revert. In this case, rookie developers would be very nervous because they may get lost on what they should do to rollback their changes without affecting others, but to veteran developers, this is their routine work and they can show you different ways of doing that.In this post, we will introduce two major ones used frequently by developers.git resetgit revertWhat are their differences and corresponding use cases? We will discuss them ...

102,454 14       GIT GIT RESET GIT REVERT


  Be careful about printing error as string in GoLang

In GoLang, we can format and produce string using fmt.Printf(), just like C, GoLang also supports format verbs like %s, %d which can be placeholder for different types of values. But please pay attention when printing error as string so that you will not fall into some trap.Let's first take an example code snippet and see what trap we are talking about.package mainimport "fmt"type A stringfunc (a A) Error() string { return fmt.Sprintf("%s is an error", a)}func main() { a := A("hello") fmt.Printf("error is %s", a)}What do you expect the output is? Do you expect "error is hello is an error"? Unf...

21,540 2       STACKOVERFLOW GOLANG FMT