My learning diary

CryptoJS and URL

Like this Stack Overflow thread, I needed to encrypt some string which will become part of a URL. However, there was a slash in one of the encrypted strings, like c3ViamVjdHM/X2Q9MQ==. Feel free to decode this. It’s something I copied from the internet. I thought there would be a lot of symbols in the Base64 alphabet at first (I was wrong). I didn’t want to deal with them and set up a giant substitution map, like a Map<string, string>.

Continue reading "CryptoJS and URL"

Quick Go 2

Chapter 3 and 4 were about variables (var, const and so on) and control structures (for, if and so on). package main import "fmt" b := "Hello, world!" // Block scope func main() { // Chapter 3: Variables var x string = "Hello, world!" var y string y = "Hello, world!" // x = x + y // x += y z := "Hello, world!" var a = "Hello, world!" fmt.

Continue reading "Quick Go 2"

JSLT

I’ve a GraphQL service and a Spring Boot application. The latter consumes the former. In the application, I transform the retrieved JSON with the help of JSLT. Today, I wrote a JSLT program to do de-duplication and array intersection. Below is the context: My GraphQL query: query MyQuery(...) { arrayA: someModel(...) { someInnerModel { id } }, arrayB: someModel(...) { someInnerModel { id } } } Expected JSON response from GraphQL service:

Continue reading "JSLT"

Quick Go 1

It was a busy weekend for me. Last Saturday, I went out to catch up with my friends, and I went shopping for an ebook reader. Last Sunday, I cycled with my in-laws and played computer games. On both days, I travelled by public transport, so a couple of hours went into travelling too. Over the weekend, I also had to set up my ebook reader. Besides my HumbleBundle books, I borrowed some books from NLB via OverDrive.

Continue reading "Quick Go 1"

Writing Calculators

My friends needed an interest calculator. For the simple interest calculator, the parameters are: The principal (P), Annual interest rate (r), Number of months (t), and An optional parameter to represent a periodic top-up amount. Here’s v1 of my simple interest calculator: /** * Calculates simple interest. * * Uses the formula A = P(1 + rt). * * @param {Object} param Object containing parameters. * @param {Number} param.principal Principal amount.

Continue reading "Writing Calculators"