Skip to content

Instantly share code, notes, and snippets.

View BenGoldberg1's full-sized avatar

Ben Goldberg BenGoldberg1

View GitHub Profile
@BenGoldberg1
BenGoldberg1 / libtcc.c
Last active April 9, 2016 02:15
c-source file plugin for hexchat using libtcc
#include "hexchat-plugin.h"
#include "libtcc.h"
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
#define PNAME "C src"
#define PDESC "Compile and load C source plugins"
#define PVERSION "0.1"
<html>
<head>
<link rel="openid2.provider" href="https://www.google.com/accounts/o8/ud?source=profiles">
<link rel="openid2.local_id" href="https://plus.google.com/102632605368689768910">
</head>
</html>
@BenGoldberg1
BenGoldberg1 / forksort.c
Last active February 28, 2016 01:06
Fork Sort in C
#include <stdio.h>
int main(int argc, char **argv) {
int count = 1;
char first[1024], current[1024], cmdline[1024];
FILE *lesser = NULL, *greater = NULL;
snprintf( cmdline, sizeof(cmdline), "\"%s\"", argv[0] );
if( NULL == fgets( first, sizeof(first), stdin ) ) return 0;
while( NULL != fgets( current, sizeof(current), stdin ) ) {
int cmp = strcmp( current, first );
@BenGoldberg1
BenGoldberg1 / PloverArray.pl
Last active January 27, 2016 03:29
Array based replacement for PloverHash.pl
use strict;
use warnings;
do 'PloverOO.pl';
package NFA;
# The NFA object is simply an arrayref.
# The starting state is index 0, the final state
use strict;
use warnings;
do 'PloverOO.pl';
package NFA;
################################################################
#
# Compile parsed regexp into representation of NFA
use strict;
use warnings;
# First, I started with http://perl.plover.com/Regex/Regex.pm
# Then, I beat it with an OO shaped stick until it looked like this.
# Note: Only the parser and executer are in this file; a compiler
# based vaguely on the original is in PloverHash.pl, and a compiler
# which uses an array instead of a hash is in PloverArray.pl
@BenGoldberg1
BenGoldberg1 / Math-BigInt-SubProcess.pm
Last active January 17, 2016 17:10
Math::BigInt::SubProcess
package Math::BigInt::SubProcess;
use 5.010;
use strict;
use warnings;
use warnings qw,FATAL io uninitialized,;
use Scalar::Util qw,weaken,;
use Fatal qw,fork waitpid pipe open close,;
use version 0.77 (); our $VERSION = version->declare('v0.0.0.2016.01.16_1');
use constant DEBUGGING => !!$::{'B::'} || defined &DB::sub;
@BenGoldberg1
BenGoldberg1 / Safer.pm
Last active December 31, 2015 02:15
Improved replacement for Safe.pm
package Safer;
$VERSION = '0.000001';
use strict;
use warnings;
use 5.010;
no overloading;
use Opcode qw,opset opset_to_hex invert_opset,;
use Scalar::Util qw,weaken blessed reftype,;
use Carp qw,croak,;
<script>
(function (factors, primes) {
var a_prime = 3, a_squared_prime = 9, maybe_prime = 3;
function insertPrimeIntoSieve( factor ) {
/* This functions deliberately makes factors a sparse array */
/* It will have nulls in the places which might be prime, */
/* and primes in the places which are surely composites. */
var where = factor;
while( factors[where] )
where += factor;
import java.util.*;
import java.lang.*;
import java.io.*;
class Primes
{
public static void my_insert(ArrayList<Integer> factors, Integer factor) {
int where = factor, count = factors.size();
while( where < count && factors.get(where) != null ) where += factor;
if( where >= count ) {