Skip to content

Instantly share code, notes, and snippets.

View BluBloos's full-sized avatar

Noah Cabral BluBloos

View GitHub Profile
@BluBloos
BluBloos / nc_stretchy_buffers.h
Created June 6, 2022 15:58
Stretchy Buffers
#ifndef NC_STRETCHY_BUFFERS
#define NC_STRETCHY_BUFFERS
#include <stdlib.h>
#include <cassert>
// NOTE(Noah): Stretchy buffers adapated from the cryptic C code of https://nothings.org/stb/stretchy_buffer.txt
// Stretchy buffers basically work like so: A block of memory is allocated to store the current count, total element size,
// plus all the elements. The array pointer that was passed in originally is modified in place with the new element pointer,
// which is offset by 2 in the allocated block (just after the count and total element size).
//
#ifndef NC_TYPES_H
#define NC_TYPES_H
// TODO(Noah): Do we trust cstdint?
#include <cstdint>
typedef float float32_t;
typedef double float64_t;
#endif
// taken from https://www.gingerbill.org/article/2015/08/19/defer-in-cpp/
// How does code work?
// call defer macro to evaluate our code as a defer statement.
// code into defer macro can be an exp or a statement
// defer statement is defining a var (of type privDefer) with some unique autogen name
// code gets executed when var goes out of scope because code is slotted to execute
// in destructor of privDefer type.
template <typename F>
#include <cstdint>
#include <functional>
// TODO(Noah): Let's do some proper fast string functions, yeah?
// TODO(Noah): Let's also unit test these functions, yeah?
namespace nc {
namespace str {
enum get_line_result {
NC_EOL, NC_EOF
{
/* the following settings have been written manually,
even if they were the VS Code default. */
// VERSION CONTROL SETTINGS.
// only consider git repo when open the folder containing .git folder.
"git.openRepositoryInParentFolders": "never",
// do not ignore changes in leading or trailing whitespace.
"diffEditor.ignoreTrimWhitespace": false,
// Place your key bindings in this file to override the defaults
[
{
"key": "ctrl+left",
"command": "cursorWordLeft",
"when": "textInputFocus"
},
{
"key": "ctrl+right",
"command": "cursorWordRight",