Skip to content

Instantly share code, notes, and snippets.

View nikatlas's full-sized avatar

Nikos Atlas nikatlas

  • Berlin, Germany
View GitHub Profile
@nikatlas
nikatlas / browser-caching.md
Created June 28, 2024 10:33
Browser Caching techniques

Efficient Caching Strategies for Web Development: A Comprehensive Guide

In the rapidly evolving world of web development, efficient management of browser cache is a crucial aspect of improving site performance, reducing latency, and enhancing user experience. This article delves into the advanced caching strategies for different types of web resources such as HTML, JavaScript, CSS files, media content, and API requests. Drawing from detailed insights on HTTP Caching from Mozilla Developer Network (MDN) and specific caching practices, we present a tailored approach for the fictional company "apadua."

Understanding HTTP Caching

HTTP caching is a technique that helps reduce server load, bandwidth usage, and latency by storing copies of resources locally on the browser. The decision on whether to fetch data from the cache or the server is governed by cache headers. These headers include:

  1. Cache-Control: Directs browsers on caching policies such as duration and revalidation.
  2. Pragma: A legacy h
@nikatlas
nikatlas / composition-react.md
Created January 9, 2024 10:44
Prevent React re-renders with composition
@nikatlas
nikatlas / github-aliases
Created July 24, 2023 14:06
Github Aliases
[user]
email = nikatlas@gmail.com
name = Nikos Atlas
[credential]
helper = cache
[alias]
# fast status
s = status -uno
# Pretty log
lg = log --oneline --decorate --date=relative --all

Type-check the crap out of everything

  • Dict is evil

  • State is evil, all forms of it, avoid it like the plague

  • Functional over object-oriented, using then latter sparingly

  • Split and organize code by functionality rather than type

  • Treat all code you write as if you were writing a library to be consumed by millions

  • Use nested exceptions for error handling

@nikatlas
nikatlas / dry-run.md
Last active August 7, 2024 19:21
dry_run done properly

What is dry-run

Dry run is a great way to emulate a process running on a specific hardware to gain insights into what the process is doing, whether it may fail and how it will affect your system without it actually performing any changes on your live application.

How it is properly done?

Usually, the persistence layer of an application is a database. In this case, a dry_run is very simple.

# Wrap your code in a transaction
@nikatlas
nikatlas / soft-delete.md
Created September 27, 2022 11:27
Soft Delete - How and why

Soft Deletion

Soft delete means to treat an entry in a database as deleted without actually deleting the row/entry from the table.

Also known as paranoid tables.

How

A deleted boolean column is added to the table.

@nikatlas
nikatlas / debug-queries.md
Created September 7, 2022 14:17
Debug/Count queries performed by Django on the DB
from django.db import connection
from django.test.utils import CaptureQueriesContext

with CaptureQueriesContext(connection) as ctx:
    some_function_that_executes_qeuries()

    # assert that 4 queries were executed
    assert len(ctx.captured_queries) == 4
@nikatlas
nikatlas / generality.md
Last active April 8, 2021 17:29
How to Generalize your codebase

Generality

Problem

Code needs to be reusable and we need to write minimal code in order to be maintainable.

Solution

Generalize your codebase.

@nikatlas
nikatlas / loose-interface.md
Last active April 5, 2021 08:53
Loose interface

Loose the interface

Components in a loosely coupled system:

  • can be replaced with alternative implementations that provide the same services.
  • are less constrained to the same platform, language, operating system, or build environment.

An interface also provides a level of abstraction that makes programs easier to understand.

@nikatlas
nikatlas / docker-cleanup-resources.md
Created February 27, 2021 11:36 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm