Skip to content

Instantly share code, notes, and snippets.

@jsimmons
jsimmons / resize.c
Created October 4, 2014 05:38
Resize Cursors SDL
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#define STBIR_NO_ALPHA_EPSILON
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "stb_image_resize.h"
#include <stdbool.h>
@jsimmons
jsimmons / Parser.py
Created February 15, 2010 12:36
irc parser.py
def parse(msg):
prefix, trailing = None, None
if msg[0] == ':':
prefix, msg = msg[1:].split(' ', 1)
if msg.find(' :') != -1:
msg, trailing = msg.split(' :', 1)
args = msg.split()
if trailing != None:
args.append(trailing)
return prefix, args.pop(0), args
@jsimmons
jsimmons / gist:455360
Created June 28, 2010 02:16
lua irc parsing
function parse(line)
local prefix
if line:sub(1,1) == ":" then
local space = line:find(" ")
prefix = line:sub(2, space-1)
line = line:sub(space)
end
local colonsplit = line:find(":")
local last
@jsimmons
jsimmons / gl.c
Created July 16, 2010 00:58
opengl error checking
#include "gl.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
void sgl_check_gl_error(const char *func, const char *file, int line)
{
GLenum error = glGetError();
bool had_error = false;
@jsimmons
jsimmons / client.lua
Created July 21, 2010 03:00
some irc stuff in lua for something
local pairs = pairs
local setmetatable = setmetatable
local unpack = unpack
module 'irc.client'
local meta = {}
meta.__index = meta
function meta:add_handler(command, callback)
@jsimmons
jsimmons / sandbox.lua
Created July 22, 2010 04:43
old lua sandboxing code
require "task"
function dothebox( )
local makeReadOnly = function( t )
proxy = {}
mt = {}
mt.__metatable = "None of your business!"
mt.__index = t
mt.__newindex = function( t, k, v )
@jsimmons
jsimmons / config.lua
Created September 14, 2010 08:32
Mongrel2 config loading, in lua
local chat_demo = Handler {
send_spec = 'tcp://127.0.0.1:9999';
send_ident = '8b7c7833-0932-4d9a-92c3-3b8c06d9b855';
recv_spec = 'tcp://127.0.0.1:9998';
recv_ident = '';
}
local chat_demo_dir = Dir {
base = 'static/chatdemo/';
index_file = 'index.html';
@jsimmons
jsimmons / output.txt
Created October 4, 2010 13:01
Test cases for my ringbuffer codes
josh@josh-laptop:~/Projects/rirc$ ./build/tests/rirc-tests
/ringbuffer/new free: OK
/ringbuffer/read write: OK
/ringbuffer/stream: OK
/ringbuffer/wrap around: OK
@jsimmons
jsimmons / bench-lj.c
Created October 12, 2010 20:42
lumberjack bench
#include <errno.h>
#include <unistd.h>
#include <glib.h>
#include <jansson.h>
#include <zmq.h>
#include <lumberjack.h>
#include "timer.h"
@jsimmons
jsimmons / template.lua
Created December 4, 2010 23:25
Simple templating system in Lua using Lua as the templating language.
local concat, coroutine, insert, loadstring, open, pcall, setfenv, setmetatable =
table.concat, coroutine, table.insert, loadstring, io.open, pcall, setfenv, setmetatable
module 'spin.template'
function parse_file(path, env)
local file, err = open(path, 'r')
if not file then return nil, err end
local source = file:read('*a')