Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env stack runhaskell --package array --package bytestring --package containers --package time
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
import Control.Monad
import Data.Array.IArray
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
@bennydictor
bennydictor / python_photo.py
Created July 3, 2019 10:58
Make executable Python code screenshots
from bs4 import BeautifulSoup
from requests import Session
import sys
import zipfile
if len(sys.argv) >= 2:
code = open(sys.argv[1]).read()
else:
code = sys.stdin.read()
@bennydictor
bennydictor / BrainFuckMethodHandleCompiler.java
Created April 25, 2019 12:13
BrainFuck interpreter/jit compiler using java's MethodHandle
package org.bennydict.brainmethodfuckhandles;
import java.io.*;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.HashMap;
import java.util.Scanner;
public class BrainFuckMethodHandleCompiler {
@bennydictor
bennydictor / solution.mk
Created December 7, 2018 15:01
Advent of Code 2018 Day 7 Part 1 in GNU Make
RULES := $(file < input)
RULES := $(subst Step,,$(RULES))
RULES := $(subst must be finished before step,,$(RULES))
RULES := $(subst can begin.,,$(RULES))
RULES := $(strip $(RULES))
TARGETS := $(sort $(RULES))
set_get = $(strip $(__set_$(1)))
@bennydictor
bennydictor / receiver.c
Created April 24, 2018 09:29
Sending file descriptors over unix domain sockets
#include <err.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/un.h>
#include <unistd.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/sendfile.h>
#include <vector>
#include <set>
#include <limits.h>
using namespace std;
#include <unistd.h>
#define BUF_MAX (4 * 1024)
int read_char(void) {
static char buf[BUF_MAX];
static unsigned int size = 0;
static unsigned int ptr = 0;
if (ptr == size) {
size = read(0, buf, BUF_MAX);
ptr = 0;
#include <cerrno>
#include <cstring> // for strerror
#include <cctype> // for tolower
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
@bennydictor
bennydictor / proxy.c
Created April 12, 2017 09:55
Proxy for one website and it injects javascript (and probably doesn't work)
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <netdb.h>
#include <poll.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
@bennydictor
bennydictor / bf-vim.txt
Created March 18, 2017 08:00
Brainfuck on Vim macros
This is a Brainfuck interpreter written in vim macros
To use it, copy the fourth line to `a' register (4G"ayy),
and run the macro (@a).
{macro}
/^{letterh}
$h"cyl/^{program}
j0"cx/^{code:c}
j"myy@m
Your program here: