Hi there 馃憢

Musings about web development, design, and other things I’m interested in.

Xcode Tips to Supercharge Your Development Workflow

If you鈥檙e an iOS developer, you know how crucial it is to optimize your workflow in Xcode. In this blog post, we鈥檒l explore some powerful Xcode tips that can save you time and enhance your development experience. We鈥檒l cover three main categories: file navigation, efficient text editing, and optimizing screen real estate. Or if you can watch this video if you prefer File Navigation 1. Quick Open Use Command + Shift + O to open any file within your project swiftly....

February 20, 2024 路 2 min 路 384 words 路 Abdellah Hariti

Trigger a manual deployment on Cloudflare Pages

We鈥檝e all been there, you made a change that doesn鈥檛 warrant a git commit & push, a change in build command? Maybe. But want to retry a build & deploy on Cloudflare Pages. Sure you can retry a failed deployment, but with the previous settings. Deploy hooks to the rescue. These are meant to be called by CMS or outside the context of git integration, but can be useful to poke CF Pages to do another build....

May 23, 2023 路 1 min 路 139 words 路 Abdellah Hariti

Understand Svelte and Sveltkit $dollar signs

If you鈥檝e recently started working with Svelte/Sveltkit, you鈥檝e probably come across a few money signs ($) here and there. In this post we will get them demystified. Table of contents Reactivity Variables Reactivity is a fundamental concept in Svelte. It鈥檚 the way to have your dependant UI (or a certain variable) stay in sync. For example, this total depends on price and tax: let tax = 0.1; let price = 20; let total = price * (1 + tax); // sometime later ....

May 23, 2023 路 4 min 路 774 words 路 Abdellah Hariti

IntersectionObserver `rootMargin` option.

The Intersection Observer API has been around for a few years now and has pretty good browser support. It has some nice options which can be intimidating or simple depending on what you want to do with it. In my case, I had a horizontal scrolling list of items in which I wanted to highlight the center most item. This is the final product. The first instinct we might have is to use an intersection observer, which is a way for the browser to tell us when some element intersects with (or not) another....

June 22, 2022 路 3 min 路 565 words 路 Abdellah Hariti

Parallel promise execution: Beyound Promise.all()

In this post, I will talk about running promises in parallel and optimizing for the lowest waiting time possible. When you have a bunch of promises that need to execute sequentially, you just run them in a sequence using .then() or awaits: getUser() .then(user => getPosts(user.id)) .then(posts => use(posts)); // Or let user = await getUser(); let posts = await getPosts(user.id); use(posts); But when they don鈥檛 depend on each other like the posts that need the user id, you can run them in parallel using Promise....

March 31, 2022 路 2 min 路 373 words 路 Abdellah Hariti

Use Typescript generics for a type safe `setTimeout` and `setInterval`

TLDR; Here鈥檚 the code: type Handler = ((...args: any[]) => any) | string; function safeSetTimeout<F extends Handler>( handler: F, timeout?: number, ...args: F extends string ? any[] : Parameters<F extends string ? never : F> ) { return setTimeout(handler, timeout, ...args); } If you understand everything in the following snippet, you don鈥檛 have much to gain from this post. But you might want check out the practical snippet at the end of this post....

March 20, 2022 路 5 min 路 956 words 路 Abdellah Hariti
some image

Promises | async await vs .then(), how we got here and why I use both

How we got here Promises marked a huge turning point in async js, they enabled a new type of control flow that saved us from callback hell. But some people found that calling .then() multiple times was too much, too callbacky. Then after a while, we resorted to generator functions and cogenerators, which made async code feel like its synchronous, at the cost of wrapping it in a generator function, yielding every line and introducing a cogenerator library (for example co) to deal with unwrapping the promises like the following example, where we could just yield a promise whenever we encounter it and pretend that the yield does not exist on that line of code....

March 19, 2022 路 3 min 路 492 words 路 Abdellah Hariti

Promises | run any promise with a timeout

A promise has two states: either pending or settled (resolved or rejected). The user has no control over the time it takes from going from the first state to the second. Which makes it harder to bail out on a certain promise when it takes too long in a promise friendly way. Promise.race() to the rescue. Table of contents How does Promise.race work? This method takes an array of promises and - as its name suggests - races them, the first one to be settled in either state wins....

March 18, 2022 路 3 min 路 468 words 路 Abdellah Hariti