Skip to content

Instantly share code, notes, and snippets.

View Snaipe's full-sized avatar
😱

Snaipe Snaipe

😱
View GitHub Profile
@Snaipe
Snaipe / malloc_article.md
Last active June 6, 2022 10:10
malloc_article

Please note that the article is now on my website, and even though I am still working on it, any feedback is appreciated. Thanks for reading !

On the Quest of recoding malloc(3)

Back when I did not know anything about programing and started to learn C, I was first introduced to pointers (and other dreaded horrors that made me curl into a corner and cry) and dynamic memory in general.

I was baffled, troubled, yet fascinated by the basic explanation on how memory worked, and started to dread the time where I would need to manually create my char arrays for each and every sentences of my program; right before learning about string literals and feeling like an idiot.

It was then where I was learning about memory allocation and came upon a function that I would call for long the "magic function" : malloc. Magic, because at that point I didn't know how it worked, let alone knew anything about memory other that it was a "chain of boxes for numbers".

@Snaipe
Snaipe / c.md
Last active August 29, 2015 14:23

Experiments on building high level abstractions with C

Introduction: facts vs bullshit (5 min)

C ⊄ C++

"C is just C++ without classes"

ANSI C has not been a subset of C++ since 1999!

  • Compound literals
@Snaipe
Snaipe / poc_stream_weirdness.cc
Last active September 20, 2015 20:35
Inherited basic_fstream operator weirdness
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
template <typename CharT>
class my_basic_fstream : public std::basic_fstream<CharT> {
public:
@Snaipe
Snaipe / goal.c
Last active September 30, 2015 13:47
panic
struct extra_data {
int foo,
int bar,
};
struct data_type {
const char *str;
struct extra_data *data;
};
@Snaipe
Snaipe / purge-gitlab-depproxy.rb
Last active May 23, 2024 11:16
purge Gitlab Dependency proxy blobs from the database if the corresponding local file is missing
# purge Gitlab Dependency proxy blobs from the database if the corresponding local file is missing
DependencyProxy::Blob.where(file_store: [nil, ::DependencyProxy::FileUploader::Store::LOCAL]).find_in_batches do |batch|
batch.each { |blob|
begin
blob.open
rescue Errno::ENOENT => e
puts "Blob #{blob.id} corrupted, deleting"
blob.destroy
end
}