Skip to content

Instantly share code, notes, and snippets.

View s3rj1k's full-sized avatar
🍀
https://andersoncardoso.github.io/ydd/

s3rj1k s3rj1k

🍀
https://andersoncardoso.github.io/ydd/
View GitHub Profile
@viega
viega / defer.h
Created March 20, 2025 01:58
A C implementation of defer using `goto`
// defer.h
// [email protected]
// © 2025 Crash Override, Inc.
// Licensed under the BSD 3-Clause license
#pragma once
#include <stdint.h>
typedef struct n00b_defer_ll_t n00b_defer_ll_t;
@Raimo33
Raimo33 / speed_optimizations.md
Last active April 4, 2025 17:17
C Speed Optimizations

C Speed Optimization Checklist

This is a list of general-purpose optimizations for C programs, from the most impactful to the tiniest low-level micro-optimizations to squeeze out every last bit of performance. It is meant to be read top-down as a checklist, with each item being a potential optimization to consider. Everything is in order of speed gain.

Algorithm && Data Structures

Choose the best algorithm and data structure for the problem at hand by evaluating:

  1. time complexity

Other posts

What is an "arena" in memory allocation?

I first leanred about "arena" when I was trying to understand the internal of [glibc malloc][glibc-alloc] around 2010, but I [later realized][trend] the concept is narrowly defined [in][arena1] [other][arena2] [context][arena3]. This blog post explains the difference in definition and the limitations in the so-called "arena allocators" we use today.

Background: why is malloc needed?

  1. Every atomic object has a timeline (TL) of writes:

    • A write is either a store or a read-modify-write (RMW): it read latest write & pushed new one.
    • A write is either tagged Relaxed, Release, or SeqCst.
    • A read observes some write on the timeline:
      • On the same thread, future reads can't go backwards on the timeline.
      • A read is either tagged Relaxed, Acquire, or SeqCst.
      • RMWs can also be tagged Acquire (or AcqRel). If so, the Acquire refers to the "read" portion of "RMW".
  2. Each thread has its own view of the world:

  • Shared write timelines but each thread could be reading at different points.
@jphsd
jphsd / interprocess.md
Last active October 13, 2024 16:46
Interprocess channels in Go by using named pipes

How to use channels across different processes in Go

A couple of code samples to show how a named pipe can be used to extend Go's channel paradigm for use between different processes running on a system.

  • interprocess1.go details a single byte channel.
  • interprocess2.go details a channel that passes slices of bytes.

Note that opening a write channel will return two channels -

{
"meta": {
"theme": "professional"
},
"basics": {
"name": "Serhii Ivanov",
"phone": "+48572260756",
"label": "Senior Software Engineer | Golang | Kubernetes | SRE | DevOps",
"image": "https://avatars.githubusercontent.com/u/11349489?v=4",
"summary": "Proactive software engineer with Golang as language of choice. I am used to wearing many hats and generally very flexible when investigating new roles.",
@michaelbeaumont
michaelbeaumont / mkosi.build.chroot
Last active March 9, 2025 13:19
Using mkosi and AUR to install packages
#!/usr/bin/env bash
set -ex
PACKAGES=(
neovim-git
)
# All this is basically to get around makepkg calling pacman with sudo
# Otherwise we could just call `aur sync` and be done with it
@alpominth
alpominth / rt_table123.sh
Last active July 19, 2024 12:26
rt_table123.sh - Easily create a firewall mark for an additional routing table and expose the IP adress(es) of a network interface to the system
#!/bin/bash
FW_MARK="$((RANDOM%2147483646 + 1))"
if [ "$(ip -4 rule show fwmark ${FW_MARK})" ] || [ "$(ip -6 rule show fwmark ${FW_MARK})" ]; then
while [ "$(ip -4 rule show fwmark ${FW_MARK})" ] || [ "$(ip -6 rule show fwmark ${FW_MARK})" ]; do
FW_MARK="$((RANDOM%2147483646 + 1))"
done
fi
TABLE="$((RANDOM%2147483396 + 1))"
if [ ! "$(ip -4 route show table ${TABLE} 2>/dev/null || echo 1)" = "1" ] || [ ! "$(ip -6 route show table ${TABLE} 2>/dev/null || echo 1)" = "1" ]; then
@yzdbg
yzdbg / auto-dr.md
Last active November 3, 2023 17:11

Automating Daily Reports, because fuck it, really...

Each day at our company, developers are required to document their activities, painstakingly jotting down their daily work and future plans. A monotonous chore that I just really dislike.

So now, there's a scribe for that :

auto-dr-

Code