The Well-Grounded Java Developer

java

The state model for a thread

The Java Memory Model (JMM)

The JMM is described in section 17.4 of the Java Language Specification (JLS). This is quite a formal part of the spec, and it describes the JMM in terms of synchronization actions and the mathematical construct known as a partial order. This is great from the point of view of language theorists and implementers of the Java spec (compiler and VM makers), but it’s worse for application developers who need to understand the details of how their multithreaded code will execute.

Rather than repeat the formal details, we’ll list the most important rules here in terms of a couple of basic concepts: the Synchronizes-With and Happens-Before relationships between blocks of code.

  • Happens-Before — This relationship indicates that one block of code fully completes before the other can start.
  • Synchronizes-With — This means that an action will synchronize its view of an object with main memory before continuing.

. . .


Undo reset HARD

git
$ git init
Initialized empty Git repository in .git/

$ echo "testing reset" > file1
$ git add file1
$ git commit -m 'added file1'
Created initial commit 1a75c1d: added file1
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 file1

$ echo "added new file" > file2
$ git add file2
$ git commit -m 'added file2'
Created commit f6e5064: added file2
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 file2

$ git reset --hard HEAD^
HEAD is now at 1a75c1d... added file1

$ cat file2
cat: file2: No such file or directory

$ git reflog
1a75c1d... HEAD@{0}: reset --hard HEAD^: updating HEAD
f6e5064... HEAD@{1}: commit: added file2

$ git reset --hard f6e5064
HEAD is now at f6e5064... added file2

$ cat file2
added new file

from


Scala and terminal

scala
src/greeting/api/Greeting.scala
package greeting.api

trait Greeting {
  def say(): String;
}

src/greeting/backend/Hello.scala
package greeting.backend

import greeting.api.Greeting

class Hello extends Greeting {
  override def say(): String = {
    "Hello";
  }
}

. . .


Further demistifying the Monad in Scala: a Category Theory approach

links

Some of you may have read my article on monads. This time I want to talk about monads from a different, more theoretical point of view. It is not mandatory to read the previous article first (in case you haven’t), but if you don’t know anything about the topic, I guess it wouldn’t hurt to become familiar with it before jumping on this one.

Let’s start. Some of you may have heard the popular quote:

A monad is just a monoid in the category of endofunctors, what’s the problem?

Original statement is from Categories for the Working Mathematician by Saunders Mac Lane, but it has been quoted and rephrased numerous times. I took this statement as a reference point; a teaching objective, if you will. So I will attempt to explain monads from the category theory point of view by explaining that particular sentence.

. . .


Easy go

golang


How to create a self-signed certificate with OpenSSL

linux

You can do that in one command:

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365

You can also add -nodes (short for no DES) if you don't want to protect your private key with a passphrase. Otherwise it will prompt you for "at least a 4 character" password.

. . .


Easy stuff with docker

docker

Docker images list

    docker image ls
    docker image ls -a

Docker containers list

    docker container ls
    docker container ls -a

. . .


Docker network

docker

Docker network list

    docker network ls

Inspect network

    docker network <network_name> inspect

. . .


EXIT FROM VIM

vim

HOW GET OUT FROM VIM

    :q and press enter

OR

    :q! and press enter

OR

    :qw and press enter

Eazy stuff with vim

vim

Undo and redo

    u
    ctrl + r

Find something

    press / and type stuff for search

Copy and paste

    press v and select text for copy then press v again
    press p for paste