Skip to content

Instantly share code, notes, and snippets.

View Linux-cpp-lisp's full-sized avatar

Alby M. Linux-cpp-lisp

View GitHub Profile
@Linux-cpp-lisp
Linux-cpp-lisp / gist:2890984
Created June 7, 2012 19:20
Basic Sandboxing
require("timeout")
t=Thread.new(codeStr) do |code|
$SAFE=4
Timeout::timeout(5) {eval code} rescue nil
end
@Linux-cpp-lisp
Linux-cpp-lisp / UNIXError.cpp
Created May 24, 2012 13:23
A set of classes used to simplify error handling with POSIX and UNIX functions in C++ programs. Header and `.cpp` files. Contains a class that works with `errno` errors, and one that works with `getaddrinfo` errors.
/*
* File: UNIXError.cpp
* Author: a
*
* Created on March 19, 2012, 5:59 PM
*/
#include "UNIXError.h"
#include <netdb.h>
@Linux-cpp-lisp
Linux-cpp-lisp / cpp-posix-errors.cpp
Created May 24, 2012 13:20
A few small macros used to simplify error handling in C++ code that uses POSIX and UNIX system calls. Depends on an exception class UNIXError, which just happens to have an argument-less constructor that will get an error string based on the current value
#define ERR(__statment, __retVar) ((__retVar=(__statment))==-1 ? throw UNIXError() : (__retVar))
#define ERR_ERRVAL(__statment, __retVar, __errval) (((__retVar)=(__statment))==(__errval) ? throw UNIXError() : (__retVar))