Skip to content

Instantly share code, notes, and snippets.

@nyorain
nyorain / heap.c
Created September 18, 2017 10:45
Generic heap in C
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
typedef int (*compare_func)(void* a, void* b);
protos = [['xdg-shell', '/usr/share/wayland-protocols/unstable/xdg-shell/xdg-shell-unstable-v6.xml']]
wlscanner = find_program('wayland-scanner', required: false)
if wlscanner.found()
proto_targets = []
foreach proto : protos
code_output = proto[0] + '.c'
header_output = protoc[0] + '.h'
@nyorain
nyorain / _connection.hpp
Last active May 10, 2021 09:09
Small game-orientated UDP protocol, C++17
#pragma once
#include <kyo/message.hpp>
#include <asio/buffer.hpp>
#include <nytl/span.hpp>
#include <cstdint>
#include <cstddef>
#include <vector>
#include <memory>
@nyorain
nyorain / aud2.md
Last active February 3, 2018 19:17
AuD_Codemonkeys_2_nb_version

Djikstra

One test in 'Djiktra - complete' is not working but it's most likely a wrong test/a bug.

public void preProcess() throws InvalidInputException
{
    if(getGraph() == null || getSourceNode() == null)
        throw new InvalidInputException();
@nyorain
nyorain / sat.cpp
Last active December 26, 2023 23:14
Small Separating Axis Theorem implementation in C++
#include <nytl/vec.hpp>
#include <nytl/vecOps.hpp>
#include <vector>
#include <limits>
using Polygon = std::vector<nytl::Vec2f>;
/// Returns whether the two given convex polygons intersect using the
/// separating axis theorem. The given polygons can be in clockwise or
@nyorain
nyorain / AuD_Codemonkeys_1.md
Last active June 19, 2017 19:32
Codemonkey solutions

Notes

  • All code snippets should pass all unit tests, but may have bugs beyond the tests
  • the exercise list contains findSmallestElement_iterative, but codemonkeys does not.
    • the same for singly_linked_list::revert iterative...
    • and for singly_linked_list::find
    • also array_list::get
@nyorain
nyorain / thread_local_storage.cpp
Last active November 29, 2020 18:52
C++ 14 Implementation of a thread local storage object
// Copyright (c) 2017 nyorain
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt
#pragma once
#include <unordered_map> // std::unordered_map
#include <thread> // std::thread::id
#include <shared_mutex> // std::shared_mutex
#include <utility> // std::pair