Skip to content

Instantly share code, notes, and snippets.

@mhyee
mhyee / codex_compiler.sh
Last active March 21, 2023 13:40
"Compile" code with the OpenAI Codex model
#!/bin/bash
# Super simple "compiler" that uses OpenAI's Codex model.
# The Codex API was free before being discontinued on March 23, 2023.
#
# Usage:
# ./codex_compiler.sh input_file > out
#
# Requirements:
# - OpenAI API key (set the environment variable OPENAI_API_KEY)
@mhyee
mhyee / BugRepro.scala
Last active July 12, 2017 18:10
Repro of a bug in Flix v0.1
package ca.uwaterloo.flix
import ca.uwaterloo.flix.api.{Flix, InvokableUnsafe, WrappedType}
import ca.uwaterloo.flix.language.ast.Type
import ca.uwaterloo.flix.runtime.{Model, Value}
object BugRepro {
// To run this repro:
// Drop this file in main/src/ca/uwaterloo/flix/BugRepro.scala
@mhyee
mhyee / LambdaCalculus.scala
Created October 30, 2016 16:05
Encoding the lambda calculus and SKI calculus in Scala's type system.
import scala.language.higherKinds
// https://apocalisp.wordpress.com/2009/09/02/more-scala-typehackery/
// http://scala-lang.org/blog/2016/02/17/scaling-dot-soundness.html
// There is a proposed fix to disallow this, but there may be other ways to
// get Turing-completeness.
trait Lambda {
type subst[U <: Lambda] <: Lambda
@mhyee
mhyee / export-poster.sh
Created July 4, 2016 15:28
Takes input "poster.svg" and creates "poster.png" and a tiled "poster-draft.pdf". Requires imagemagick and inkscape. Thanks to @cbhl.
#!/bin/bash
inkscape --export-png="poster.png" poster.svg
inkscape --export-png="poster00.png" --export-area=0:0:900:675 --export-dpi=300 poster.svg
inkscape --export-png="poster01.png" --export-area=900:0:1800:675 --export-dpi=300 poster.svg
inkscape --export-png="poster02.png" --export-area=1800:0:2700:675 --export-dpi=300 poster.svg
inkscape --export-png="poster03.png" --export-area=2700:0:3600:675 --export-dpi=300 poster.svg
inkscape --export-png="poster04.png" --export-area=3600:0:4320:675 --export-dpi=300 poster.svg
inkscape --export-png="poster10.png" --export-area=0:675:900:1350 --export-dpi=300 poster.svg
inkscape --export-png="poster11.png" --export-area=900:675:1800:1350 --export-dpi=300 poster.svg
AST:
def f: Int =
match () with { _ => 11 }
SAST:
def f: Int =
let matchVar1 = () in
let case2 = λ() -> MatchError in
(* B. C. Pierce, Types and Programming Languages. MIT Press, 2002, ch. 22, sec 7. *)
(* This progam is well typed, but demonstrates worst-case exponential time of the typechecker. *)
(* In practice, typechecking takes linear time. *)
let f0 = fun x -> (x,x) in
let f1 = fun y -> f0(f0 y) in
let f2 = fun y -> f1(f1 y) in
let f3 = fun y -> f2(f2 y) in
let f4 = fun y -> f3(f3 y) in
let f5 = fun y -> f4(f4 y) in
f5 (fun z -> z)
@mhyee
mhyee / dependency_graph.gv
Last active March 27, 2020 17:05
Graphviz file for drawing a dependency graph. http://www.graphviz.org/
// Online Graphviz: http://webgraphviz.com/
// https://i.imgur.com/NHmoDnj.png
digraph g{
node [shape="box",style=rounded];
"a.out" -> "C.o"
"a.out" -> "B.o"
"a.out" -> "A.o"
"C.o" -> "C.cpp"
"B.o" -> "B.cpp"