Skip to content

Instantly share code, notes, and snippets.

View Bambofy's full-sized avatar
Drinking coffee and coding!

Richard Bamford Bambofy

Drinking coffee and coding!
  • England
  • 22:35 (UTC +01:00)
View GitHub Profile
@Bambofy
Bambofy / list_dir.c
Created April 7, 2024 20:53
GTK create a queue of all the files in a directory recursively
#include <gtk/gtk.h>
/*
* Iterates a directory and all of its subdirectories to produce a list of the
* paths of the files inside of them.
*/
GQueue* list_directory(GString* dir_path) {
GQueue* unchecked_queue;
GQueue* checked_queue;
@Bambofy
Bambofy / replacestring.cpp
Last active January 15, 2023 10:35
A function that replaces a character in a given string with another.
#include <string>
using namespace std;
/**
* Replaces every occurance of repchar with newchar in the str
* and returns a copied value.
* @param[in] str The string who's characters are being replaced.
* @param[in] repchar The character to replace.
* @param[in] newchar The character to replace with.
* @param[out] The copied string with replaced characters.
@Bambofy
Bambofy / splitstring.cpp
Created January 15, 2023 10:28
A function that splits a string into substrings in C++.
#include <deque>
#include <string>
using namespace std;
/**
* Split a string into a sequence of substrings according to
* a deliminator.
* @param[in] str The string to split.
* @param[in] delim The deliminator of substrings.
* @param[out] The sequence of split strings.
@Bambofy
Bambofy / oopnoheap.cpp
Created April 16, 2021 11:29
OOP without the heap
#include <iostream>
class Mammal
{
public:
Mammal();
~Mammal();
};
@Bambofy
Bambofy / Ring.lua
Created July 4, 2020 20:30
Lua testing functions similar to Unity
Ring = {}
Ring._registeredFunctions = {}
Ring._currentTestFunctionPtr = nil
Ring._tests = {}
function Ring.RegisterTest(func)
table.insert(Ring._registeredFunctions, func)
end
function Ring.Assert(op, msg)
struct Cluster
{
Vector2 m_meanPosition;
std::vector<Vector2> m_points;
Color m_colour;
};
void InitializeClusters(std::vector<Vector2>& dataPoints, std::vector<Cluster>& clusters)
@Bambofy
Bambofy / pack.cpp
Created May 28, 2020 16:19
Function to combine two int32 into 1 int64.
static int64_t Pack(int32_t inX, int32_t inY)
{
int64_t x = static_cast<int64_t>(inX) << 32;
int64_t y = static_cast<int64_t>(inY);
// twos complement, therefore 32 msbs must be cleared.
if (inY < 0)
{
y = y ^ 0xFFFFFFFF00000000;
}
@Bambofy
Bambofy / NamingConventions.cpp
Last active May 28, 2020 11:08
Example c++ naming conventions from the book "Code Complete - 2nd Edition"
/*
Macros
*/
#define DEBUG(x) printf("%s\r\n", x)
#define THREADING_ENABLED false
/*
Constant
*/
/*
The MIT License (MIT)
Copyright (c) 2020 Richard Bamford
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WIT
/*
The MIT License (MIT)
Copyright (c) 2020 Richard Bamford
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIO