Skip to content

Instantly share code, notes, and snippets.

@cleure
cleure / gist:2501036
Created April 26, 2012 17:09
Primitive try/catch Exception Handling in C
#include <stdio.h>
#include <setjmp.h>
struct Exception {
jmp_buf jb;
int code;
};
/* Definitely not thread-safe... But we don't care :-) */
struct Exception *cur_ex_ptr = NULL;
@cleure
cleure / nonsensical-helloworld.c
Created November 6, 2012 00:05
C - Nonsensical Hello World
#include <stdio.h>
#include <stdint.h>
#define CHR(in) ((in) > 25 ? (in)+6 : (in)+65)
int main(int argc, char **argv)
{
int i;
uint64_t data = 976561444569328775LU;
@cleure
cleure / vector.c
Last active December 10, 2015 15:49
Vector Abstract Data Type in C89. Symbols exported via VECTOR_EXPORT() Macro, in case of symbol clashing.
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <stdint.h>
#define VECTOR_EXPORT(SYM) SYM
struct VECTOR_EXPORT(vector) {
uint32_t elmsize;
uint32_t capacity;
@cleure
cleure / deck.c
Last active December 14, 2015 17:28
Simple deck of cards example
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
/* Lookup array for card suits */
const char *card_suits[] = {
"hearts",
"diamonds",
@cleure
cleure / nearest_scale.py
Created March 18, 2013 19:45
Simple Nearest Neighbor Scaling Algorithm
#
# Simple Nearest Neighbor Scaling Algorithm
#
# @author Cameron Eure
# @license Public Domain
#
import os, sys, copy
import os, sys, copy, imagekit
class RGB_Sample(object):
def __init__(self, r, g, b):
self.set_value(r, g, b)
def set_value(self, r, g, b):
if r > 255:
r = 255
@cleure
cleure / emerald-city.py
Created April 26, 2013 04:29
Fun little demo of Convolution Kernels in image processing
from imagekit import *
i = ImageBuffer.fromJPEG('seattle.jpg')
# Darken, and pallete swap (emerald)
darken = [
0.00, 0.00, 0.00,
0.16, 0.16, 0.16,
0.16, 0.16, 0.16]
@cleure
cleure / tetris-permutations.txt
Last active December 16, 2015 22:09
Every possible tetromino combination in Tetris, using the 7-bag system.
There are 7 different tetrominoes in Tetris.
The 7-bag system works by shuffling an array with one of each tetromino.
There are about 5040 possible combinations of tetrominos in this system.
Here's every possible permutation:
1 2 3 4 5 6 7
1 2 3 4 5 7 6
1 2 3 4 6 5 7
1 2 3 4 6 7 5
@cleure
cleure / nes-color-palette.py
Last active December 17, 2015 12:59
Tool that outputs the NES Color Palette to a PNG file.
"""
Tool that outputs the NES Color Palette to a PNG file.
"""
import math
from imagekit import *
@cleure
cleure / teensy-gamepad.c
Last active December 18, 2015 15:09
NES / SNES Gamepad to USB with Teensy in less than 200 lines of C.
#include <stdint.h>
// GPIO pins used for connected gamepad
#define CLOCK 21
#define LATCH 20
#define DATA 19
#define DEVICE_TYPE_NES 0
#define DEVICE_TYPE_SNES 1