Skip to content

Instantly share code, notes, and snippets.

View benwills's full-sized avatar

Ben Wills benwills

View GitHub Profile
@benwills
benwills / 0_reuse_code.js
Last active August 29, 2015 14:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@benwills
benwills / threads.tmpl.pl
Last active August 29, 2015 14:10
Template: Perl Thread Queue
#! perl -slw
use threads stack_size => 8*4096;
use Thread::Queue;
############################################################
#
# There are pipe errors that happen. I came across only
# one, but it breaks the code entirely.
#
#include <sys/mman.h>
#include <stdlib.h>
#include <unistd.h>
#define report_exceptional_condition() abort ()
struct ring_buffer
{
@benwills
benwills / uz.c
Last active August 29, 2015 14:12 — forked from supr/uz.c
#include <sys/mman.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#define INDEX(B, P) ((P) - (B))
const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.124 2013/03/20 11:30:05 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jbsockets.c,v $
*
* Purpose : Contains wrappers for system-specific sockets code,
* so that the rest of Junkbuster can be more
* OS-independent. Contains #ifdefs to make this work
* on many platforms.
*
// $Id: simple-proxy.c,v 1.4 2005/02/25 04:23:24 dean Exp $
//
// simple-proxy.c: simple tcp proxy for async bi-directional data transfer
//
// usage: simple-proxy host port
//
// this will open a socket to host:port and copy data from stdin to the socket,
// and from the socket to stdout. errors may appear on stderr.
//
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2013, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file connection.c
* \brief General high-level functions to handle reading and writing
* on connections.
/*
* $Id: simple-tcp-proxy.c,v 1.6 2002/11/27 00:40:31 wessels Exp $
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <string.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h> //lseek, write, close
#include <stdlib.h> //exit
#include <fcntl.h> //open
#include <sys/mman.h>
#define Mapmalloc(number, type, filename, fd) load_mmap(filename, &(fd), (number)*sizeof(type), 'y')
#define Mapload(number, type, filename, fd) load_mmap(filename, &(fd), (number)*sizeof(type), 'n')
#define Mapfree(number, type, fd, pointer) releasemmap(pointer, (number)*sizeof(type), fd)
#define Stopifnot(assertion, ...) if (!(assertion)){printf(__VA_ARGS__); exit(1);}
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <errno.h>
int main(int argc, char *argv[])