Skip to content

Instantly share code, notes, and snippets.

@nem0
nem0 / nullable.cpp
Created May 27, 2017 00:28
Compile time safe nullable/optional
#include <cstdio>
template <typename T>
class Nullable
{
public:
Nullable(T* _val) : value(_val) {}
void operator=(const Nullable<T>& rhs) { value = rhs.value; }
@nem0
nem0 / perf_test.cpp
Last active January 11, 2019 12:57
Perf test
template <typename F>
static void measure(float& avg, float& med, float& min, float& max, F&& func) {
LARGE_INTEGER b, e, f;
enum { ITERS = 10 };
LONGLONG dur[ITERS];
LONGLONG sum = 0;
for (int i = 0; i < 5; ++i) {
func();
}
@nem0
nem0 / csharp_pdb
Created December 16, 2019 15:27
detach and attach vs debugger
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text.RegularExpressions;
using System.Diagnostics;
void radixSort2(u64* _keys, u64* _values, int size) {
enum { WORKERS = 10 };
PROFILE_FUNCTION();
profiler::pushInt("count", size);
if (size == 0) return;
Array<u64>& tmp_mem = allocRadixTmp();
u64* keys = _keys;
@nem0
nem0 / imgui_treeview_clipper.cpp
Last active January 9, 2022 14:44
Simple treeview clipper for imgui
// only handles coplexity on top level, if you have a node with 1M children, you are out of luck
// changes in clipped parts are not detected, so if somebody deleted nodes in clipped, scrollbar is not updated until user actually scrolls
// scrolling and changes refresh the clipper == that part is as slow as no clipping at all
// only single list in BeginChild/EndChild is tested
struct TreeViewClipper {
// persist
float cursor_end = 0;
float cursor_visible_start = 0;
uint first_visible_index = 0;
float last_scroll = 0;
@nem0
nem0 / download.cpp
Created November 28, 2022 08:34
Donwload file on windows without 3rd party
#include <urlmon.h>
#pragma comment(lib, "urlmon.lib")
bool download(const char* url, OutputMemoryStream& blob) {
IStream* stream = nullptr;
if (S_OK != URLOpenBlockingStream(nullptr, url, &stream, 0, nullptr)) {
return false;
}
char buffer[4096];
ULONG read = 0;