Skip to content

Instantly share code, notes, and snippets.

@FurryHead
FurryHead / TimeoutThread.py
Created June 14, 2011 22:15
Timeout thread.
import threading
class TimeoutException(Exception):
pass
class TimeoutThread(threading.Thread):
def run(self):
def timeout_handler(signum, frame):
raise TimeoutException()
import threading
import inspect
import ctypes
def _async_raise(tid, exctype):
"""raises the exception, performs cleanup if needed"""
if not inspect.isclass(exctype):
raise TypeError("Only types can be raised (not instances)")
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
@FurryHead
FurryHead / gist:1045197
Created June 24, 2011 16:58
Class user to parse raw irc user chunk.
class User(str):
def __new__(cls, user):
if getattr(user, "nick", None) is not None:
cls.nick = user.nick
cls.ident = user.ident
cls.host = user.host
else:
if re.match(".+!.+@.+", user):
cls.nick = user.split("!")[0]
cls.ident = user.split("!")[1].split("@")[0]
@FurryHead
FurryHead / configparser.cxx
Created June 27, 2011 16:21
Code file for ConfigParser
/*
* configparser.cxx
*
* Copyright 2011 FurryHead <[email protected]>
*
* ConfigParser is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
@FurryHead
FurryHead / configparser.hxx
Created June 27, 2011 16:22
ConfigParser header file
/*
* configparser.hxx
*
* Copyright 2011 FurryHead <[email protected]>
*
* ConfigParser is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
@FurryHead
FurryHead / main.cxx
Created June 27, 2011 16:23
ConfigParser test file
/*
* main.cxx
*
* Copyright 2011 FurryHead <[email protected]>
*
* ConfigParser is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
@FurryHead
FurryHead / test.ini
Created June 27, 2011 16:24
ConfigParser test ini file
; This is a comment
# This is also a comment
; This is a variable defined outside a section,
; you can access _these_ by using section name "DEFAULT"
; (Note: "DEFAULT" doesn't appear when you use ConfigParser.sections();)
foo = bar
[ freenode ] ;This is a section, leading/trailing whitespace trimmed, always enclosed by [ ]
host = irc.freenode.net ;This is a unquoted variable
lua_getglobal(L, "plugins");
lua_pushnil(L);
string pname;
bool loaded = false;
while (lua_next(L, -2) != 0) {
/* key is at -2, value at -1 */
if (lua_isstring(L, -2)) {
pname = lua_tostring(L, -2);
if (pname == name) {
loaded = true;
string[3] user;
// this end up in the sequence [0] = nick, [1] = ident, [2] = host
user[0] = split(trim(words[0], ":"), "!")[0];
if (words[0].find("!") != string::npos && words[0].find("@") != string::npos) {
user[1] = split(split(trim(words[0], ":"), "!")[1], "@")[0];
user[2] = split(split(trim(words[0], ":"), "!")[1], "@")[1];
} else {
user[1] = "";
user[2] = "";
}
void PluginManager::fire(string event, int numargs, ...) {
lua_getglobal(L, "plugins");
int table_index = lua_gettop(L);
if(!lua_istable(L, table_index)) {
lua_pop(L, 1);
lua_newtable(L);
lua_setglobal(L, "plugins");
return;
}
lua_pushnil(L);