https://www.gravatar.com/avatar/f819a092b23cb25a09f87436f68df217?s=240&d=mp

Ang Gao

Software Engineer @ TripAdvisor, CS Ph.D @ University College Cork

JavaScript Note Eight

Project: A Programming Language We will build a programming language called Egg. Everything in Egg is an expression. An expression can be a variable, a number, a string, or an application. Applications are used for function calls but also for constructs such as if or while. And since the syntax has no concept of a block, we need a do construct to represent doing multiple things in sequence. The data structure that the parser will use to describe a program will consist of expression objects, each of which has a type property indicating the kind of expression it is and other properties to describe its content.

Docker Note One

images & containers A container is a stripped-to-basics version of a Linux operating system. An image is software you load into a container. Dockerfile The FROM keyword tells Docker which image your image is based on. Build an image from your Dockerfile docker build -t docker-whale . docker run docker-whale Tag, push, and pull your image docker tag 7d9495d03763 anggao/docker-whale:latest docker login to log into the Docker Hub docker push anggao/docker-whale Remove images docker rmi -f 7d9495d03763 docker rmi -f docker-whale Pull images docker pull anggao/docker-whale install Docker using Docker Toolbox Docker Machine for running the docker-machine binary

JavaScript Note Seven

Modules Though JavaScript provides no actual module construct yet, objects can be used to create publicly accessible subnamespaces, and functions can be used to create an isolated, private namespace inside of a module. Functions are the only things in JavaScript that create a new scope. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 var dayName = (function() { var names = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]; return function(number) { return names[number]; }; })(); console.

JavaScript Note Six

Exceptions 1 2 3 4 5 6 7 8 9 try { (function() { throw new Error("Error !"); })(); } catch (error) { console.log("Something went wrong: " + error); } finally { console.log("finally called"); } JavaScript (in a rather glaring omission) doesn’t provide direct support for selectively catching exceptions We want to catch a specific kind of exception. We can do this by checking in the catch block whether the exception we got is the one we are interested in and by rethrowing it otherwise let’s define a new type of error and use instanceof to identify it.

Java 8 Notes

Java 8 useful methods List.sort() 1 2 3 4 List<String> list = ... list.sort(null); // use natural order list.sort((s1, s2) -> s1.compareToIgnoreCase(s2)); // sort ignoring case list.sort(String::compareToIgnoreCase); // same with a method reference List.removeIf() 1 2 3 4 5 6 7 8 9 10 11 /* old way */ Iterator<String> it = list.iterator(); while(it.hasNext()) { String s = it.next(); if (s.length() %2 == 0) { it.remove(); } } /* java 8 */ list.

Golang Note Six

There are two types of Go programs: executables and libraries. Executable applications are the kinds of programs that we can run directly from the terminal Libraries are collections of code that we package together so that we can use them in other programs Types Numbers Go has several different types to represent numbers. Generally we split numbers into two different kinds: integers and floating-point numbers. Go’s integer types are: uint8, uint16, uint32, uint64, int8, int16, int32 and int64.