AJAX the Good (Asynchronous) Way TL;DR : Javascript and AJAX are asynchronous, so your code must be asynchronous✶ too ! ✶: JS is event driven, which is some kind of asynchronous, and AJAX is asynchronous Be carefoul : Never, never use synchronous AJAX request !!! It will make your apps feels laggy, and on bad network it can be unusable : because 1 long request block the main loop and all processing is blocked too.

Continue reading

Is JS pass-by-reference or by value ? TL;DR JS use pass by value for primitive and by reference for object and array (simplification inside). So how to : Copy a (not nested) array : var my_copy = my_array.slice(0); // ATTENTION : works for not nested array ! Cloning a (not nested) object : (look here for source + polyfill for obj.assign()) var my_obj = { a: 1 }; // If you don’t have nested object !

Continue reading

Javascript for Beginner 1 This is a first post of a little serie : my steps to explain to colleague new to javascript what to know and how to develop app without (too much) headache. The first thing I explain to someone new to javascript : the unusual way JS variables (var) are scoped, and the (bad) consequence. Javascript is function scoped What does that mean exactly. Well usually (in other language) variables are block scoped.

Continue reading

or the unexpected behaviour of nullable type from sql to JSON Problem description When working with a database you will have to deal with nullable type, you have sql.null type in standard library. But if you use JSON, you will find that they don’t encode/decode in JSON has we intend : they expose their internal; example : a SqlnullInt (valid, and value 42) encoded in JSON will look like : { "number": { "Valid": true, "Int64": 42 } } but you wanted : { "number": 42 } Simple solution to encode to JSON Behaviour of the Go standart library is easy to overload : simply redefine the MarshalJSON for each type you want Here is an example to export a SQL NullInt64 as expected in JSON :

Continue reading

Some ressources The first 2 are sufficient to be ready to code with Go in 1 day ! Official go site : How to write Go code Golang bot : Golang tutorial series Go by example A tour of Go 50 shades of Go There is some other : to fully understand slice, map, context etc there is the official Go blog, and I also like to read Dave Cheney

Continue reading

Author's picture

Tristan Giovangrandi

Happy Web developper @Content-Square and happy father

Full Stack & Embedded

France - Paris