Skip to content

Instantly share code, notes, and snippets.

@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 / wscript
Created July 22, 2010 10:29
waf example wscripts
#! /usr/bin/env python
# encoding: utf-8
# Joshua Simmons 2010
def configure(conf):
pass
def build(bld):
pong = bld(
features = 'c cprogram',
@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 / ring-buffer.c
Created October 4, 2010 13:19
ringbuffer implementation
#include "ring-buffer.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
RingBuffer *rb_new(size_t size)
{
RingBuffer *buf = malloc(sizeof(*buf));
assert(buf != NULL);
@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"