Skip to content

Instantly share code, notes, and snippets.

View macmade's full-sized avatar
🦄
I may be slow to respond.

JD Gadina macmade

🦄
I may be slow to respond.
View GitHub Profile
@macmade
macmade / gist:4254411
Created December 10, 2012 23:44
XEOS: Buddy physical memory allocator
--------------------------------------------------------------------------------
XEOS: Buddy physical memory allocator
Total memory: 1024 MB (1073741824 B) at 0x101000000
--------------------------------------------------------------------------------
Memory zone 1 - Length: 639 KB
- Pages: 159
- Buddy 0: 159 blocks of 4 KB
- Buddy 1: 79 blocks of 8 KB
- Buddy 2: 39 blocks of 16 KB
- Buddy 3: 19 blocks of 32 KB
@macmade
macmade / generate-types.awk
Created August 1, 2013 02:32
AWK - Generate types header file
BEGIN {
RS = ""
FS = "@XEOS"
TYPE = ""
NAME = ""
DEF = ""
CONTENT = ""
GUARD = ""
}
{
@macmade
macmade / gist:6183970
Created August 8, 2013 11:53
Clang - List predefined macros
clang -x c /dev/null -dM -E
@macmade
macmade / gist:6250215
Created August 16, 2013 14:03
Objective-C singleton macros
#ifdef OBJC_ARC
#define SingletonImplementation( name ) \
\
static name * __sharedInstance = nil; \
\
+ ( id )sharedInstance \
{ \
static dispatch_once_t token; \
\
@macmade
macmade / CFPP
Created March 8, 2014 16:53
CoreFoundation++ Example
{
CF::Number number = 42;
CF::URL url = externalURL;
CF::Array array;
/* Adds number and URL to the array */
array << number << url;
CF::Data data
(
@macmade
macmade / CF
Created March 8, 2014 16:53
CoreFoundation Example
{
/* First of all, we need a C array to store our dictionary keys */
CFStringRef keys[ 2 ];
/*
* Let's create the dictionary keys. First key is straightforward because
* of the CFSTR macro, while the second one is less...
*/
keys[ 0 ] = CFSTR( "key-1" );
keys[ 1 ] = CFStringCreateWithCString
@macmade
macmade / strict-aliasing-bug.c
Created April 2, 2014 21:38
An example of C99 strict aliasing issue...
#include <stdio.h>
struct s1
{
int i;
};
struct s2
{
int i;
@macmade
macmade / libgit2-coveralls.c
Last active August 29, 2015 14:16
libgit2 - coveralls.io infos
/*!
* @author Jean-David Gadina
* @copyright (c) 2015, Jean-David Gadina - www.xs-labs.com
*/
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "git2.h"
@macmade
macmade / cpp-fibs.cpp
Created June 11, 2015 22:20
C++ Fibonacci
#include <iostream>
template< int N >
struct Fibonacci
{
static constexpr int value = Fibonacci< N - 1 >::value + Fibonacci< N - 2 >::value;
};
template<>
struct Fibonacci< 1 >
@macmade
macmade / objc_msg_lambda.cpp
Last active March 15, 2023 10:33
objc_msgSend - C++ Lambda
#include <functional>
#include <iostream>
#include <objc/runtime.h>
#include <objc/message.h>
template< typename _R_, typename ... _T_ >
_R_ CXX_IMP( id self, SEL _cmd, _T_ ... args )
{
Class cls;
id assoc;