Skip to content

Instantly share code, notes, and snippets.

View elliott-beach's full-sized avatar

Elliott Beach elliott-beach

  • Epic
  • Minnesota
View GitHub Profile
@elliott-beach
elliott-beach / problem4.c
Last active September 14, 2017 22:36
Problem 4
/*
Here’s a function that’s intended to reverse the order of a subsequence of integers within an
array. For instance suppose the array a originally contains the integers 1 2 3 4 5 6 7 8 9. If
you call reverse_range(a, 2, 5), the afterwards the array a will contain the same integers but
with the ones in positions 2 through 5 (counting from zero) in the opposite order. I.e., a will be 1
2 6 5 4 3 7 8 9.
Unfortunately you’ll see that this function was not implemented very carefully.
*/
/*
@elliott-beach
elliott-beach / bcvi.c
Created September 20, 2017 16:37
Badly Coded v 1.1
/* Badly Coded Text Editor BCVI, a product of Badly Coded, Inc. */
/* This is an example insecure program for CSci 5271 only: don't copy
code from here to any program that is supposed to work
correctly! */
/* version 1.0 was for exploits due 9/15/2017 */
/* This is version 1.1, for exploits due 9/22/2017. */
long bcvi_version = 110; /* 1.1 */
.file "foo.c"
.section .rodata
.align 8
.LC0:
.string "%s should get paid %.3f because %s.\n"
.text
.globl write_check
.type write_check, @function
write_check:
.LFB0:
@elliott-beach
elliott-beach / bcvi.c
Created October 2, 2017 16:27
Version 1.4
/* Badly Coded Print Server BCLPR, a product of Badly Coded, Inc. */
/* Change log: */
/* Version 1.4, released 10/ 6/2014 */
/* Version 1.3, released 9/29/2014 */
/* Version 1.2, released 9/22/2014 */
/* Version 1.1, released 9/15/2014 */
/* Version 1.0, released 9/ 9/2014 */
@elliott-beach
elliott-beach / setjmp.c
Created October 12, 2017 20:10
Comments on setjmp
#include <stdio.h>
#include <setjmp.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#define SECOND 1000000
#define STACK_SIZE 4096
@elliott-beach
elliott-beach / WA.json
Last active November 8, 2017 17:22
Web Speech API JSON Definition
{
"info": {
"name": "Web Speech API Specification",
"subsection_number": null,
"subsection_name": null,
"url": "https://w3c.github.io/speech-api/webspeechapi.html"
},
"features": [
"SpeechRecognition",
"SpeechRecognitionAlternative",
@elliott-beach
elliott-beach / solver.py
Last active May 14, 2022 05:24
Solving SEND+MORE=MONEY rapidly using backtracking search
# Solves the SEND + MORE = MONEY letter substituion puzzle as a constraint satisfaction problem using backtracking search,
# searching variables (letters) in the least constrained ordering and values (digits) in the most constrained ordering,
# making the algorithm thousands of times faster.
from pprint import pprint
s1 = 'send'
s2 = 'more'
s3 = 'money'
import logic
# Write problem 3 into a logic base.
prob3 = logic.PropKB()
A, B, C, D, E = logic.expr('A, B, C, D, E')
prob3.tell(A)
prob3.tell(~A | C)
prob3.tell(C | ~D)
prob3.tell(D | C)
prob3.tell(~B | ~D | E)
import logic
# Write problem 3 into a logic base.
prob3 = logic.PropKB()
A, B, C, D, E = logic.expr('A, B, C, D, E')
prob3.tell(A)
prob3.tell(~A | C)
prob3.tell(C | ~D)
prob3.tell(D | C)
prob3.tell(~B | ~D | E)
# Ping [email protected] for questions about using this.
from glob import glob
import os
import re
import sys
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)