Skip to content

Instantly share code, notes, and snippets.

View geekynils's full-sized avatar
😄

Nils geekynils

😄
View GitHub Profile
@mmozeiko
mmozeiko / shader.hlsl
Last active February 4, 2024 17:53
compute shader for rendering monospaced glyphs in grid
//
struct TerminalCell
{
// cell index into GlyphTexture, should be two 16-bit (x,y) values packed: "x | (y << 16)"
uint GlyphIndex;
// 0xAABBGGRR encoded colors, nonzero alpha for Foreground indicates to render colored-glyph
// which means use RGB values from GlyphTexture directly as output, not as ClearType blending weights
uint Foreground;
@gcatlin
gcatlin / sdl-metal-example.m
Last active April 20, 2024 13:04
Minimal C SDL2 Metal example
//
// cc sdl-metal-example.m `sdl2-config --cflags --libs` -framework Metal -framework QuartzCore && ./a.out
//
#include <SDL.h>
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
int main (int argc, char *args[])
{
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal");
@fay59
fay59 / Quirks of C.md
Last active January 23, 2024 04:24
Quirks of C

Here's a list of mildly interesting things about the C language that I learned mostly by consuming Clang's ASTs. Although surprises are getting sparser, I might continue to update this document over time.

There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.

1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]

struct foo {
   struct bar {
 int x;
@bishboria
bishboria / springer-free-maths-books.md
Last active June 8, 2024 06:39
Springer made a bunch of books available for free, these were the direct links
@niw
niw / libpng_test.c
Last active June 19, 2024 10:32
How to read and write PNG file using libpng. Covers trivial method calls like png_set_filler.
/*
* A simple libpng example program
* http://zarb.org/~gc/html/libpng.html
*
* Modified by Yoshimasa Niwa to make it much simpler
* and support all defined color_type.
*
* To build, use the next instruction on OS X.
* $ brew install libpng
* $ clang -lz -lpng16 libpng_test.c
@ssylvan
ssylvan / gist:5654932
Last active December 17, 2015 18:39
Stupid C++ lib for trying to avoid null pointers
// Class for non-nullable pointers
template<class T>
class ptr
{
private:
T* m_ptr;
ptr(nullptr_t); // avoids init with nullptr
ptr(int); // avoids init with 0 or NULL
public:
explicit ptr(T* ptr) throw() : m_ptr(ptr) { assert(ptr != nullptr); };
@jboner
jboner / latency.txt
Last active July 6, 2024 18:55
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@linusthe3rd
linusthe3rd / circles.cpp
Created January 30, 2011 18:54
The two methods used to create circles in opengl
/*
* Function that handles the drawing of a circle using the triangle fan
* method. This will create a filled circle.
*
* Params:
* x (GLFloat) - the x position of the center point of the circle
* y (GLFloat) - the y position of the center point of the circle
* radius (GLFloat) - the radius that the painted circle will have
*/
void drawFilledCircle(GLfloat x, GLfloat y, GLfloat radius){