Skip to content

Instantly share code, notes, and snippets.

immutable(uint[256]) crc32_lookup_table =
{
uint[] table;
foreach (ref i; 0 .. 256)
{
uint crc = i;
foreach (_; 0 .. 8)
crc = crc & 1 ? (crc >> 1) ^ 0xEDB88320 : crc >> 1;
table ~= crc;
}
@kovrov
kovrov / unpack.d
Created April 16, 2011 23:33
Delphine's unpacking routines
import std.intrinsic;
pure uint pop(ref const(uint)[] stream)
{
auto res = bswap(stream[$-1]);
stream.length -= 1;
return res;
}
DATA
@kovrov
kovrov / glsl_test.d
Created May 12, 2011 00:27
glsl_test.d
import std.stdio;
import std.conv;
import std.string : toStringz;
import gl;
import glut;
class ShaderException : Exception
void screenshot(char filename[160], int x, int y)
{
// get the image data
long imageSize = x * y * 3;
unsigned char *data = new unsigned char[imageSize];
glReadPixels(0,0, x,y, GL_BGR, GL_UNSIGNED_BYTE, data);
// split x and y sizes into bytes
int xa= x % 256;
int xb= (x - xa) / 256;
@kovrov
kovrov / config.pro
Created May 31, 2011 14:28
QMF config
TEMPLATE = app
TARGET = config
QT += core
QT -= gui
CONFIG += console
CONFIG -= app_bundle
LIBS += -lqmfclient
@kovrov
kovrov / qmailthreadmodel.h
Created July 21, 2011 13:53
QMF query threads
QMailStore *store = QMailStore::instance();
QMailAccountIdList accounts = store->queryAccounts();
QMailAccount account = QMailAccount(accounts[0]);
QMailFolderId folder_id = account.standardFolder(QMailFolder::InboxFolder);
QMailMessageKey folder_key = QMailMessageKey::parentFolderId(folder_id);
QMailThreadKey select_key = QMailThreadKey::includes(folder_key);
// we can only sort by id or serverUid ?
QMailThreadSortKey sort_key = QMailThreadSortKey::id(Qt::AscendingOrder);
def isFirstCodepoint(b):
return 0b10000000 & b == 0 or 0b11000000 & b != 0b10000000
def splitUtf8(arr, i):
if isFirstCodepoint(arr[i]):
return arr[:i], arr[i:]
while i > 0:
i -= 1
if isFirstCodepoint(arr[i]):
break;
struct Point { float x, y; }
Point[] triangulate(const ref Point[] contour)
{
assert (contour.length > 2);
Point[] result;
scope size_t[] V; // TODO: V.reserve(contour.length)
varying vec2 screenPos;
varying float radius;
uniform sampler2D tex;
void main()
{
float dist_squared = distance(gl_FragCoord.xy, screenPos);
// Sphere shaded
if (dist_squared > radius)