Skip to content

Instantly share code, notes, and snippets.

@lilliemarck
lilliemarck / cppbloat.py
Last active August 29, 2015 14:01
Parses nm output and groups together templates with the same name
import argparse
import fileinput
import re
import sqlite3
import sys
class Symbol:
def __init__(self, name, size, type, template):
self.name = name
self.size = size
@lilliemarck
lilliemarck / gist:5788010
Created June 15, 2013 12:45
Android Interlaved Vertices
mFloatBuffer.position(0);
GLES11.glEnableClientState(GLES11.GL_VERTEX_ARRAY);
GLES11.glVertexPointer(2, GLES11.GL_FLOAT, 16, mFloatBuffer);
mFloatBuffer.position(2);
GLES11.glEnableClientState(GLES11.GL_TEXTURE_COORD_ARRAY);
GLES11.glTexCoordPointer(2, GLES11.GL_FLOAT, 16, mFloatBuffer);
@lilliemarck
lilliemarck / uri_reference_regex.h
Last active October 16, 2021 03:19
URI Regular Expression
/**
* Regex for validating a URI or URI Reference as defined in RFC3986.
*
* A URI Reference is a URI without the scheme part. They are otherwise the
* same except that the first segment of a relative path of a URI reference
* can't contain a ':'.
*
* This syntax does not have IPv6 address support and does not include the IPv4
* rule because IPv4 addresses happens to be a subset of registered names.
* Although the final regex can be made a little bit more compact the intent is
@lilliemarck
lilliemarck / gist:1971905
Created March 4, 2012 10:12
Color depth reduction without floating point math
The bit reduction formulas converts the colors to give a minimal error after converting back to 8 bit. The sum of the signed errors is 0 and the sum of absolute diffs are as small as possible.
The formulas that convert back to 8 bit are done using bit shifting which introduces a rounding error for some color values. However bit shifting creates nice symmetric patterns and seems to be how hardware does it.
8 bit -> 4 bit -> 8 bit
c4 = (c8 + 8) / 17
c8 = c4 << 4 | c4
8 bit -> 5 bit -> 8 bit
c5 = (31 * c8 + 127) / 255