Skip to content

Instantly share code, notes, and snippets.

View didito's full-sized avatar

Dietmar Suoch didito

View GitHub Profile
@rygorous
rygorous / magic_ring.cpp
Created July 22, 2012 03:55
The magic ring buffer.
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <string.h>
#include <Windows.h>
// This allocates a "magic ring buffer" that is mapped twice, with the two
// copies being contiguous in (virtual) memory. The advantage of this is
// that this allows any function that expects data to be contiguous in
// memory to read from (or write to) such a buffer. It also means that
@airekans
airekans / memlayout.cpp
Created July 31, 2012 09:26
Memory Layout for C++ multiple inheritance
// The output from the program compiled under gcc 3.4.4
// sizeof Base: 8
// sizeof Derived: 12
// sizeof AnotherBase: 8
// sizeof AnotherDerived: 20
// And you can run the program to get the log.txt to check its content
// =========================================================
//
// The inheritance relationship is as follow:
// class Base;
@nlguillemot
nlguillemot / main.c
Created August 14, 2012 07:27
attempt to sort image by hue
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <math.h>
SDL_Surface *screen;
float hue_from_rgb(int r, int g, int b)
{
// return atan2(sqrt(3.0) * (g - b), 2.0f * r - g - b);
return atan2(2.0f * r - g - b, sqrt(3.0) * (g - b));
@darktable
darktable / IncrementBuildVersion.cs
Created September 8, 2012 21:43
Unity3d: Post-process script that increments revision number of iPhone and Android builds.
/* **************************************************************************
Copyright 2012 Calvin Rien
(http://the.darktable.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@klange
klange / _.md
Last active May 23, 2024 13:45
It's a résumé, as a readable and compilable C source file. Since Hacker News got here, this has been updated to be most of my actual résumé. This isn't a serious document, just a concept to annoy people who talk about recruiting and the formats they accept résumés in. It's also relatively representative of my coding style.

Since this is on Hacker News and reddit...

  • No, I don't distribute my résumé like this. A friend of mine made a joke about me being the kind of person who would do this, so I did (the link on that page was added later). My actual résumé is a good bit crazier.
  • I apologize for the use of _t in my types. I spend a lot of time at a level where I can do that; "reserved for system libraries? I am the system libraries".
  • Since people kept complaining, I've fixed the assignments of string literals to non-const char *s.
  • My use of type * name, however, is entirely intentional.
  • If you're using an older compiler, you might have trouble with the anonymous unions and the designated initializers - I think gcc 4.4 requires some extra braces to get them working together. Anything reasonably recent should work fine. Clang and gcc (newer than 4.4, at le
@1wErt3r
1wErt3r / SMBDIS.ASM
Created November 9, 2012 22:27
A Comprehensive Super Mario Bros. Disassembly
;SMBDIS.ASM - A COMPREHENSIVE SUPER MARIO BROS. DISASSEMBLY
;by doppelganger (doppelheathen@gmail.com)
;This file is provided for your own use as-is. It will require the character rom data
;and an iNES file header to get it to work.
;There are so many people I have to thank for this, that taking all the credit for
;myself would be an unforgivable act of arrogance. Without their help this would
;probably not be possible. So I thank all the peeps in the nesdev scene whose insight into
;the 6502 and the NES helped me learn how it works (you guys know who you are, there's no
@lynxluna
lynxluna / main.c
Created December 8, 2012 22:01
Win32 Game Loop
#include <Windows.h>
#include <tchar.h>
#define CURRENT_WND_CLASS _T("GameWndClass_Didiet")
#define DEF_CX 800
#define DEF_CY 600
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
INT WINAPI _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
@jvranish
jvranish / stack_traces.c
Last active April 25, 2024 15:51
An example of catching exceptions and printing stack traces in C on Windows, Linux and OS X
/* compile with:
on linux: gcc -g stack_traces.c
on OS X: gcc -g -fno-pie stack_traces.c
on windows: gcc -g stack_traces.c -limagehlp
*/
#include <signal.h>
#include <stdio.h>
#include <assert.h>
@cameron314
cameron314 / stabtest.cpp
Last active November 26, 2023 01:44
Simple stability test that I whipped up for exercising my lock-free queue. Compile with g++ -std=c++11 -DNDEBUG stabtest.cpp -O3 -pthread
#include "readerwriterqueue.h"
using namespace moodycamel;
#include <exception>
#include <fstream>
#include <thread>
#include <cstdlib> // rand()
#include <unistd.h> // usleep()
@macton
macton / vim_tips.txt
Created February 10, 2013 22:07
Tips for vim
----------------------------------------------------------------------------------------------------------------
Find & Replace non-printable characters in vim
http://durgaprasad.wordpress.com/2007/09/25/find-replace-non-printable-characters-in-vim/
1) Find hexa value of that non-printable character. Move your cursor to that character and press ‘ga’.
2) In escape mode, execute this ‘:%s/\%x85/\r/gc’. In my case, hexadecimal value of that non-printable character is 85. I replaced that with ‘\r’.
----------------------------------------------------------------------------------------------------------------