Skip to content

Instantly share code, notes, and snippets.

@jhaberstro
jhaberstro / ScopeStackDemo.cpp
Created November 5, 2010 22:00
ScopeStack implementation stolen from Andreas Fredriksson's DICE presentation on Scope Stack Allocation.
// Simplified scope stack implementation
#include <new>
#include <cstdio>
#include <cassert>
typedef unsigned char u8;
class LinearAllocator {
public:
@machinamentum
machinamentum / microsoft_craziness.h
Created May 19, 2019 05:51
Code for finding the path to Visual Studio by Jon Blow.
//
// Author: Jonathan Blow
// Version: 2
// Date: 7 May, 2019 (update to original version released on 31 August, 2018).
//
// This code is released under the MIT license, which you can find at
//
// https://opensource.org/licenses/MIT
//
//
@fpsunflower
fpsunflower / nanopng.cpp
Last active January 31, 2023 19:04
Tiny PNG output
// c++ -o nanopng nanopng.cpp && ./nanopng /tmp/foo.png
#include <cstdio>
// write an uncompressed PNG file from a uint8 RGB buffer
struct Png {
FILE*f; unsigned int tab[256], crc; ~Png() { fclose(f); }
Png(const char* fn, int w, int h, const unsigned char* c) {
crc=0x575e51f5;unsigned char d[]={137,80,78,71,13,
10,26,10,0,0,0,13,73,72,68,82,73,68,65,84,120,1,0,
0,0,73,69,78,68,174,66,96,130};/*chunk headers*/
@vurtun
vurtun / gui.md
Last active October 4, 2023 15:44

Graphical User Interfaces

For the last few weeks I spend some time coding, writing and cleaning up my notes from almost a year since I published nuklear.

Basically this is a possible implementation for a graphical user interface builder backend with support for an immediate mode style API. So it provides a way to define non-mutating UI state, an immediate mode style API for dynamic UI components (lists,trees,...) and a combination of both.

The core implementation is ~800 LOC without any kind of default widgets or extensions. At first this seems quite counter intuitive. However since the inherent design allows for lots of different ways to define any widget like buttons it does not make sense to provide a specific default implementation. The way this code was architectured furthermore removes the need for style/skinning configurations used in Nuklear since widget painting is just calling a small

Graphical User Interfaces

Last time I wrote a little bit about my current GUI research progress. There are some things that were misunderstood so I want to clarify some fundamental design decisions and finally write up some current problems and their solutions.

First up I want to clarify a component is not another term for what is usually refered to as widget. Instead wigets in this implementation are made out of n >= 1 components. Components themself are just rectangles with attributes left, right, top, bottom, center_x, center_y, width and height some behavior flags and an optional surface to draw into. For example a scroll regions is made up out of at least three

@pervognsen
pervognsen / api.txt
Last active December 10, 2023 23:51
This is a brief comment on this article on API design principles:
https://gist.github.com/vurtun/192cac1f1818417d7b4067d60e4fe921
I've called that style of API a coroutine, iterator, state machine, push/pull or client/server API
depending on what seems most appropriate for the context, but they are all variants of the same idea.
It's particularly superior in many cases as an alternative to callback-based APIs, which are the more
common way of providing this kind of fine-grained interleaving between library code and user code.
Callbacks can still be superior in usability for context-free operations like memory allocation,

API Design: Coroutines APIs (Janurary-2017)

I am currently dealing with a lot of libraries at work. Both third party as well as libraries written or being currently in process of being written by me. I absolutely love writing and working with libraries. Especially if they present or bring me to either a new or different approach to solve a problem. Or at least provide a different view.

Over time I noticed however that quite regulary we had to decide that we cannot use a third party library. Often it is the usual reason.

@mmozeiko
mmozeiko / meow_hash_c.h
Created June 29, 2020 00:19
Meow v0.5 in C
#pragma once
#define MEOW_HASH_VERSION 5
#define MEOW_HASH_VERSION_NAME "0.5/calico"
// Meow hash v0.5 in C without dependency on special CPU instructions
// Ported from https://github.com/cmuratori/meow_hash
// Performance on Ryzen 9 3950X
// AESNI code = ~16 bytes/cycle
@mmozeiko
mmozeiko / meow_hash_armv8.h
Last active December 22, 2023 17:02
Meow v0.5 in C and ARMv8
#pragma once
#define MEOW_HASH_VERSION 5
#define MEOW_HASH_VERSION_NAME "0.5/calico"
// Meow hash v0.5 with ARMv8 Crypto Extension instructions
// Ported from https://github.com/cmuratori/meow_hash
// Performance on Pine A64 (Cortex-A53, 1.2GHz)
// (compiled with clang v10.0 with -O3 -mcpu=cortex-a53)
@inaz2
inaz2 / client.c
Created March 4, 2016 08:20
IPv6 server & client in C
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
void ping(int s, char *message)
{
char buf[8192];