Month: August 2024

  • [MySql] Transaction Isolation level

    [MySql] Transaction Isolation level

    1. Intro When dealing with atomic operations in databases, it’s essential to use transactions effectively. However, simply processing transactions in a First-In-First-Out (FIFO) order can lead to serious logical inconsistencies. Imagine a scenario where Transaction A interrupts and updates data that Transaction B has already read and is relying on. Or consider a case where…

  • [Go & MySQL] parseTime option

    [Go & MySQL] parseTime option

    Intro When working with MySQL databases in Go, handling DATE, DATETIME, and TIMESTAMP fields can sometimes lead to confusion, especially when dealing with time parsing. By default, Go’s MySQL driver treats date and time fields as []uint8 (byte slices) unless explicitly configured to handle them as time.Time. This behavior can cause issues if you’re expecting…

  • [Mysql] ID jumps when using UPSERT

    [Mysql] ID jumps when using UPSERT

    You might have noticed that the PRIMARY KEY ID jumps even when no new record is inserted. This behavior commonly occurs when using the UPSERT operation. In MySQL, where the ID column is set to AUTO_INCREMENT, the increment key is consumed whenever you perform an UPSERT (INSERT … ON DUPLICATE KEY UPDATE). This happens because…

  • [Go] How to deal with sort and heap (2)

    [Go] How to deal with sort and heap (2)

    1. Quick Recap In the previous post, we explored the concept of interfaces and how the sort package utilizes them. Understanding the abstract role that interfaces play, independent of specific implementations, was crucial. This abstraction allowed us to work with various types by tying them to the same interface, enabling them to be passed as…

  • [basic CS] Understanding 2’s complement

    [basic CS] Understanding 2’s complement

    1. Computer is not smart In the era of Artificial Intelligence, we often treat computers like magical wands. Thanks to AI, we can effortlessly generate images and retrieve information through tools like ChatGPT. While these capabilities might seem like magic, at their core, they are driven by the principles of a simple calculator. Let’s delve…

  • [Go] How to deal with sort and heap (1)

    [Go] How to deal with sort and heap (1)

    1. Understanding Interface 1-a. What is an interface Before we take a look at sort and heap packages, we have to understand what Interface is and how it works. We use Interface to maintain flexible code. Instead of relying on concrete implementations, interfaces allow you to work with abstract method sets, enabling you to apply…

  • [Network] What is a socket

    [Network] What is a socket

    1. Packet before socket Network Interface Card(NIC) receives packet from the outside network. These packets are handed over to Network Stack of an operating system. The Network Stack refers to the software module that handles TCP/IP protocol. When an application sends data to TCP/IP stack, the headers should be added. On the contrary, when application…

  • [LeetCode] 1062. Longest Repeating Substring

    [LeetCode] 1062. Longest Repeating Substring

    Description Given a string s, find the length of the longest  substring without repeating characters. Example 1: Input: s = “abcabcbb” Output: 3 Explanation: The answer is “abc”, with the length of 3. Example 2: Input: s = “bbbbb” Output: 1 Explanation: The answer is “b”, with the length of 1. Example 3: Input: s = “pwwkew” Output:…