Skip to content


Test Double is a generic term for any case where you replace a production object for testing purposes.

Under test doubles, there are various types like stubs, spies and indeed mocks! Check out Martin Fowler’s post for more detail.


When creating an array in Go, we can put ... in place of array’s length to determine the length of the array automatically based on the number of elements provided.

nums := [...]int{1, 2, 3} // [3]int{1, 2, 3}


When working with session cookie, it’s important to be aware that using SameSite=Strict will block the session cookie being sent by the user’s browser for all cross-site usage — including safe requests with HTTP methods like GET and HEAD.

While that might be the safest setting, the downside is that the session cookie won’t be sent when a user clicks on a link to your application from another website. Your application will initially treat the user as ‘not logged in’ even if they have an active session.

So if your application will potentially have other websites linking to it (or even links shared in emails or private messaging services), then SameSite=Lax is generally the more appropriate setting.


Javascript compatible valid email regex recommended by W3C and Web Hypertext Application Technology Working Group.



In Go, the syntax for SQL parameter placeholder differs depending on your database. MySQL, SQL Server and SQLite use the ? notation, but PostgreSQL uses the $N notation.

For example:

-- MySQL
INSERT INTO ... VALUES (?, ?, ?);
-- PostgreSQL
INSERT INTO ... VALUES ($1, $2, $3);


To remove a package in a Go project:

  • Run go get and postfix the package path with @none.

    Terminal window
    $ go get
  • Remove all references to the package in your code, then run go mod tidy, which will automatically remove any unused packages from your go.mod and go.sum files.

    Terminal window
    $ go mod tidy -v


A Tailwind snippet to emulate .stretched-link from Bootstrap

<a class="before:absolute before:inset-0 before:z-0 before:overflow-hidden before:whitespace-nowrap before:indent-[100] before:content-['']">link</a>


  • Make sure the parent element has position relative class
  • Make sure the z-index value of the other nested links are bigger than 0


Analogy of how OAuth works:

At a high level, the process is similar to sending a child home from school with a permission slip to go on a field trip. The teacher asks students if they want to go on a field trip. If they say yes, she sends them home with a paper for their parents to sign. Their parents then sign the permission slip and send the child back to school with it. Once the teacher receives the signed permission slip, the child can be taken on the field trip.


Quickly write to a file through command line:

  • Replace whole file
    Terminal window
    echo "Hello world" | cat > hello.txt
  • Append to end of file
    Terminal window
    echo "Hello world" | cat >> hello.txt


A CSS snippet to handle nested border radius:

.parent {
--nested-radius: calc(var(--radius) - var(--padding));
.nested {
border-radius: var(--nested-radius);