Skip to content

Instantly share code, notes, and snippets.

@pqnelson
pqnelson / bdd-rspec.md
Created December 18, 2018 18:47
Random Ruby Notes

Unit testing is best done with BDD in mind.

BDD considers "stories" described in Gherkin (a DSL). Stories have the template:

  • As a (user)
  • In order to (achieve some end)
  • I want to (something to realize that end)

Then we create scenarios which would happen in this story.

@pqnelson
pqnelson / Readme.md
Last active August 25, 2023 12:37
Dispatch Techniques for Interpreters

This was an attempt to see what Visual C++ does to a simple function call, and a simple goto spam type statement. The results are unsurprising (function calls use the call instruction, goto uses the jmp instruction). I produced the assembly by inserting a breakpoint, running the "Debug -> Start Debugging" (F5), then hitting CTRL+ALT+D to view the assembly. It works good enough.

Why?

If you want to implement a virtual machine, for example, which reads in bytecode, your repl function (in, say, C) will look something like:

@pqnelson
pqnelson / c-unit-test.md
Last active January 29, 2019 16:22
Unit Tests in ANSI C

Basic Structure

Since C does not provide a "canonical" unit testing framework, we have to implement our own. The basic template for testing frameworks is called xUnit, which we'll follow.

For C, I guess the analogous xUnit patterns would be:

  • Test runner: the .c file with the main() function running all (or some specified subset of) the test suites
  • Test suite: a collection of test cases
  • Test case: the function which is a single unit test, i.e., has a single assert
@pqnelson
pqnelson / 0.aut
Created November 3, 2017 18:16
Landau in Automath
+l
@[a:'prop'][b:'prop']
imp:=[x:a]b:'prop'
[a1:a][i:imp(a,b)]
mp:=<a1>i:b
a@refimp:=[x:a]x:imp(a,a)
b@[c:'prop'][i:imp(a,b)][j:imp(b,c)]
trimp:=[x:a]<<x>i>j:imp(a,c)
@con:='prim':'prop'
a@not:=imp(con):'prop'

1. What is rhetoric?

It comes from the Greek word Rhetorica meaning "Public speaking". It first and foremost means public speaking, but it typically is focused on persuasion.

It could be considered the art of persuasion. This includes written expression.

Until the renaissance, it was focused more on "oral

@pqnelson
pqnelson / stats.md
Created August 2, 2016 14:27
Collection of links, papers, etc. on Statistics, Machine Learning, etc.

Notes

  • Konstantin Zuev, "Statistical Inference" arXiv:1603.04929, 145 pages
    • If you are going to start anywhere, here's a good place to start.
  • Ryan Martin, "A statistical inference course based on p-values" arXiv:1606.02352, 16 pages
  • Ryan Martin, Chuanhai Liu, "Validity and the foundations of statistical inference" arXiv:1607.05051, 29 pages.
    • This answers a number of "foundational" concerns I have, like "What is a statistical inference, really?"
@pqnelson
pqnelson / contracts.bib
Created February 19, 2016 17:28
Contracts Reading List
@string{icse = "International Conference on Software Engineering"}
@string{cacm = "Communications of the {ACM}"}
@string{ieee-software = "{IEEE Software}"}
@string{tools = "Technology of Object-Oriented Languages and Systems"}
@string{lncs = "Lecture Notes in Computer Science" }
@string{jacm = "Journal of the {ACM}"}
@string{ecoop = "European Conference on Object-Oriented Programming"}
@string{toplas = "{ACM} Transactions on Programming Languages and Systems"}
@string{oopsla = "{Object-Oriented Programming, Systems, Languages, and Applications}"}
@string{oopsla-companion = "{Object-Oriented Programming, Systems, Languages, and Applications Companion}"}
@pqnelson
pqnelson / automath.py
Created January 2, 2016 18:45
Automath Pygments Highlighter
from pygments import highlight
from pygments.lexer import RegexLexer, bygroups
from pygments.token import *
from pygments.formatters import HtmlFormatter
# A quick and dirty syntax highlighter for Automath code
# Admittedly, this should be cleaned up some, but it's just a proof of concept.
class AutomathLexer(RegexLexer):
name = 'Automath'
@pqnelson
pqnelson / minimal_we.c
Created January 1, 2016 19:20
Terrible C hack for Linked Lists
// a doubly linked list of "stuff"
struct item {
int kind;
struct item *next, *prev;
};
// an item can be a man eating bear
#define MAN_EATING_BEAR_KIND 1
struct manEatingBear {
int kind;
@pqnelson
pqnelson / ZFC.aut
Created December 22, 2015 04:57
Automath examples
#!/usr/local/bin/aut -Q
{
This is ZFC in AUT-QE, as opposed to AUT-68 which Wiedijk provides. The difference
is fewer primitive notions: we have 1+3+2+6+8+1=21 primitive notions,
Wiedijk's AUT-68 version has 31 primitive notions.
To see Wiedijk's version, see https://www.cs.ru.nl/~freek/zfc-etc/
}