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

 PROGRAMMING


  Run JavaScript in GoLang

In some cases, there might be some JavaScript code needs to be ran in a GoLang project. Fortunately, there are a few libraries which support running JavaScript in GoLang. The most famous one would be v8. This is a Go API for the famous v8 JavaScript engine originally developed for the Chrominum project and the foundation of NodeJS.In this post, we will show some simple steps to get v8 working in a GoLang program on MacOS. First you need to install the package so that you can import it. Run belowgo get github.com/augustoroman/v8Unluckily you would encounter an error where some header file ...

14,494 0       V8 JAVASCRIPT GOLANG


  Be careful about nil check on interface in GoLang

nil check is frequently seen in GoLang code especially for error check since GoLang's special error handling convention. In most cases, nil check is straight forward, but in interface case, it's a bit different and special care needs to be taken.Take a look at below code snippet and guess what the output will be.package mainimport ( "bytes" "fmt" "io")func check(w io.Writer) { if w != nil { fmt.Println("w is not nil") } fmt.Printf("w is %+v\n", w)}func main() { var b *bytes.Buffer check(b) fmt.Printf("b is %+v", b)}The output will be:w is not nilw is b is In the check() method, you would expe...

16,425 1       NIL VALUE NIL TYPE NIL CHECK INTERFACE GOLANG


  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,264 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...

9,971 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,826 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,289 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...

25,675 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,092 0       AVALANCHE EFFECT HYSTRIX DISTRIBUTED SYSTEM