A mostly complete guide to Go's copy function
I came across a use of the copy function that made my eyes glaze over. Initially I had no idea what I was looking at. Here’s the relevant section of code. The goal is to add numbers to a sorted set. sorted := []int{} for i := x; i < len(nums); i++ { n := nums[i-x] idx, found := slices.BinarySearch(sorted, n) if !found { sorted = append(sorted, 0) /* ========= LOOK HERE ========= */ copy(sorted[idx+1:], sorted[idx:]) sorted[idx] = n } // ... } I wanted to understand what was happening so I started from the beginning and developed this guide for myself. Hopefully you will find it useful as well.
Insert millions of rows in Postgres - Hotel bookings part I
Being able to generate fake data for a project is an important skill. It helps with testing and opens up areas for data exploration. In this article we will explore creating fake data for a hotel booking platform. The application is written in TypeScript and we are using Prisma as an ORM. The data model First let’s look at the data model. Here we can see 3 tables: hotels, guests, and bookings. This article is going to focus on the first 2.
JavaScript Iterators
Iterators offer an alternative to the classic for loop in JavaScript/TypeScript. You have probably used them without even knowing it. const arr = [1, 2, 3]; // `for...of` loops use iterators for (const el of arr) { // do something } The for...of loop will feature prominently throughout this article but there are several other common use case for iterators such as spread syntax.