Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 / _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>
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 / 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);
// GraphicsPipelineInfo
GraphicsPipelineInfo::GraphicsPipelineInfo(vk::RenderPass renderPass,
vk::PipelineLayout layout, vk::SampleCountBits samples,
vpp::ShaderProgram&& prog)
{
static const auto dynStates = {
vk::DynamicState::viewport,
vk::DynamicState::scissor};
blendAttachment.blendEnable = true;
IndentWidth: 4
PointerAlignment: Left
Language: Cpp
UseTab: ForIndentation
TabWidth: 4
ColumnLimit: 80
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
[3934530.276] -> [email protected]_registry(new id wl_registry@2)
[3934530.410] -> [email protected](new id wl_callback@3)
[3934530.567] [email protected]_id(3)
[3934530.639] [email protected](1, "wl_data_device_manager", 3)
[3934530.828] -> [email protected](1, "wl_data_device_manager", 3, new id [unknown]@4)
[3934531.079] [email protected](2, "wl_shm", 1)
[3934531.253] -> [email protected](2, "wl_shm", 1, new id [unknown]@5)
[3934531.538] -> [email protected]_pool(new id wl_shm_pool@6, fd 10, 2304)
[3934532.011] -> [email protected](6912)
[3934532.192] -> [email protected](16128)