Skip to content

Instantly share code, notes, and snippets.

View joshwilliams's full-sized avatar

Josh Williams joshwilliams

View GitHub Profile
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
int errnum, fd;
int main(int argc, char *argv[]) {
if ( argc == 2 ) {
fd = open(argv[1], O_CREAT);
@joshwilliams
joshwilliams / run_server.pl.py
Created May 19, 2011 16:21
An httpd-like thing in a PL/Python function
CREATE OR REPLACE FUNCTION run_server() RETURNS text
LANGUAGE plpythonu STRICT
AS $$
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class PGHandler(BaseHTTPRequestHandler):
def do_GET(self):
plpy.notice("Path: %s" % self.path)
if self.path.count('/') == 2 and self.path.split('/')[1] != "" and self.path.split('/')[2] != "":
nsp = plpy.quote_ident(self.path.split('/')[1])