Skip to content

Instantly share code, notes, and snippets.

View mlabbe's full-sized avatar

Michael Labbe mlabbe

View GitHub Profile
@mlabbe
mlabbe / ClaypotClient.cpp
Created January 14, 2015 07:21
Claypot Client Posting to HTTP Queue
void OnClaypotHTTPResponse( const HTTP &http, void *datum )
{
HTTPError httpError;
Message("HTTP Queue callback. Response Code: %i: %s\n",
httpError.GetStatusCode(), httpError.GetStatusString() );
}
void PostClaypotEvent( const char *eventName,
const Dict &eventKeys,
@mlabbe
mlabbe / Type safe ints
Created January 15, 2015 22:01
Type safe handles
#include<stdio.h>
typedef struct { int value; } ElemType;
typedef struct { int value; } ElemType2;
int main (void )
{
ElemType a;
ElemType2 b;
@mlabbe
mlabbe / gist:2a3ba44cef4d75837a85
Created April 10, 2015 03:31
Please help @icculus test a huge number of iOS fixes for SDL2.
From: Ryan Gordon
to: SDL Development List
Subject: [SDL] Alex's iOS improvements...
...have just landed in revision control. If you have an iOS project, PLEASE update your copy of SDL if at all possible and let us know if anything has totally blown up, as this is slated to ship soon in 2.0.4.
A quick list of improvements and fixes Alex made are noted here:
https://hg.libsdl.org/SDL/rev/cf8fab52e33b
@mlabbe
mlabbe / output
Created April 24, 2015 18:47
libplist example
7 dictionary keys:
Nice is type number
OnDemand is type bool
ProgramArguments is type dict
StandardErrorPath is type string
StandardOutPath is type string
StartInterval is type number
label is type string
@mlabbe
mlabbe / premult.py
Created June 18, 2015 02:29
Premultiply Alpha
from PIL import Image
import numpy
import glob
for path in glob.glob("*.png"):
print(path)
im = Image.open(path).convert('RGBA')
a = numpy.fromstring(im.tostring(), dtype=numpy.uint8)
alphaLayer = a[3::4] / 255.0
a[::4] *= alphaLayer
@mlabbe
mlabbe / stricmp
Created June 30, 2015 19:24
stricmp
int ftg_stricmp(const char *s1, const char *s2)
{
int result;
const char *p1;
const char *p2;
if ( s1==s2)
return 0;
p1 = s1;
p2 = s2;
@mlabbe
mlabbe / stricmp
Created June 30, 2015 19:26
perf stricmp
#ifdef WIN32
void perf_stricmp_w32(void)
{
const unsigned long REPS=10000000; /* default is 10mil */
char s1[] = "dogeatdogisSTORYOFMYLIFE";
char s2[] = "DOGEATDOGISSTORYOFMYLIFE";
unsigned long i;
LARGE_INTEGER frequency;
LARGE_INTEGER start;
@mlabbe
mlabbe / extend_line.c
Created July 27, 2015 23:22
Two implementations to extend a line.
// worse for precision
void extend_dividing_line(vec2 pt1, vec2 pt2, float len)
{
vec2 unit_v;
vec2_sub(pt1,pt2,unit_v);
vec2_normalize(unit_v, unit_v);
vec2_mul(unit_v, len, unit_v);
vec2_add(pt1, unit_v, pt1);
vec2_sub(pt2, unit_v, pt2);
@mlabbe
mlabbe / point_on_side.java
Created July 29, 2015 01:01
Point on side of line - Processing
PVector l1, l2;
PVector pt;
float g_scale = 50.0f;
static final int SIDE_FRONT = 0;
static final int SIDE_BACK = 1;
static final int SIDE_COLINEAR = -1;
@mlabbe
mlabbe / missing_stdint.c
Created November 9, 2015 00:11
How I handle missing stdint.c
// Everything before vs2008 doesn't have stdint.h
#if defined(_MSC_VER) && (_MSC_VER < 1600)
typedef unsigned char svis__uint8;
typedef unsigned int svis__uint32;
#else
#include <stdint.h>
typedef uint8_t svis__uint8;
typedef uint32_t svis__uint32;
#endif