Skip to content

Instantly share code, notes, and snippets.

View kmicinski's full-sized avatar

Kristopher Micinski kmicinski

View GitHub Profile
; I took most of this from Matt Might's:
; http://matt.might.net/articles/lexers-in-racket/
#lang racket
(require parser-tools/lex)
(require (prefix-in : parser-tools/lex-sre))
;(struct char (c) #:)
(define lex
(lexer
// gcc cpyarg.c -o cpyarg
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void gadgets() {
int y = 0;
char *x = 0;
asm("popq %rsi\n"
"ret\n"
@kmicinski
kmicinski / server.c
Created February 20, 2018 04:30
Hint code for 311
// Note that I am using:
// https://github.com/francoiscolas/multipart-parser
// Assuming it is compiled in subdirectory multipart-parser, I compile with:
// gcc server_example.c multipart-parser/multipartparser.o
// Standard C libraries
#include <stdio.h>
#include <stdlib.h>
// Various POSIX libraries
>>> x = [[0] * 3] * 3
>>> x[1][1] = 3
>>> x
[[0, 3, 0], [0, 3, 0], [0, 3, 0]]
def isEmpty(lst): return len(lst) == 0
def hd(lst): return lst[0]
def tl(lst): return lst[1:]
# Return the reverse of lst
def reverse(lst): return []
# Find the minimum element of the list
# Prove that the cost of this function is O(n)
#
# Prove that this function computes a result x' such that:
# x' = x * (x+1) / 2
def e(x):
if (x == 0): return 0
return: x + e(x - 1)
# Prove that the return value of this function is a list l' such that:
# forall i < len(l). l'[i] = 2 * l[i]
method foo(argument1, argument2) {
r1 = argument1.baz();
if (r1) {
r2 = 3;
}
if (argument2.bar()) {
// We want the taint here to be `argument2.bar()` rather than
// argument2.bar() /\ argument1.baz()
useCamera();
}

CS107 -- Exam 1 Practice

Here are some practice problems for the upcoming exam. These are somewhat representative, but won't be precisely what's on the exam: they exercise the same kinds of ideas.

I'll just do a quick dump of problems. I won't be giving a key right now, because my experience is that studnets don't work the questions but just look at the key if they have one. I am happy to check your answers if you write them up. I'll also comment on problems a bit tomorrow.

  1. In git, briefly explain what a merge conflict is and how you might fix it. You do not need to
@kmicinski
kmicinski / find-redexes.rkt
Last active April 1, 2019 05:26
Find all possible redexes of a given lambda term
#lang racket
(define (find-redexes e)
(match e
[`(λ (,x) ,body) (find-redexes body)]
[(? symbol? x) (void)]
[`((λ (,x) ,body) ,arg)
(begin
(display "I found this redex!\n")
(pretty-print e)
; Some church-encoding hints
#lang racket
(define (build-an-argument-list arg-list f)
(match arg-list
[(list x) `(,f ,x)]
[`(,hd . ,tl) `(,(build-an-argument-list tl f) ,hd)]))
(match '(2 3 5)
[`(,f . ,args) args])