From cf562b6ec125b33e00d12b307212f6a52e681716 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sat, 28 Aug 2021 05:52:47 -0500 Subject: [PATCH] add a basic example of a page --- .editorconfig | 2 +- compile-database/.gitignore | 1 + compile-database/db.ts | 14 ++++++++++++++ compile-database/index.ts | 30 ++++++++++++++++++++++++++++++ compile-database/package.json | 8 ++++++++ compile-database/tsconfig.json | 5 +++++ material/README.md | 17 ----------------- material/fp-course.yml | 4 ++++ material/fp-function.yml | 33 +++++++++++++++++++++++++++++++++ ideas.txt => notes.txt | 23 +++++++++++++++++++++-- 10 files changed, 117 insertions(+), 20 deletions(-) create mode 100644 compile-database/.gitignore create mode 100644 compile-database/db.ts create mode 100644 compile-database/tsconfig.json create mode 100644 material/fp-course.yml create mode 100644 material/fp-function.yml rename ideas.txt => notes.txt (51%) diff --git a/.editorconfig b/.editorconfig index f991008..fe226f3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,5 +3,5 @@ root = true [*] indent_style = space -[*.{svelte,ts,json}] +[*.{svelte,ts,json,rst}] indent_size = 2 diff --git a/compile-database/.gitignore b/compile-database/.gitignore new file mode 100644 index 0000000..85e3775 --- /dev/null +++ b/compile-database/.gitignore @@ -0,0 +1 @@ +/test.db diff --git a/compile-database/db.ts b/compile-database/db.ts new file mode 100644 index 0000000..2ea1b69 --- /dev/null +++ b/compile-database/db.ts @@ -0,0 +1,14 @@ +import { Sequelize, Model, DataTypes } from "sequelize"; + +class Page extends Model {} + +export async function init(path: string) { + let sequelize = new Sequelize(`sqlite:${path}`); + + Page.init({ + + }, { sequelize, modelName: "page" }); + + await sequelize.sync(); + return sequelize; +} diff --git a/compile-database/index.ts b/compile-database/index.ts index e69de29..309065a 100644 --- a/compile-database/index.ts +++ b/compile-database/index.ts @@ -0,0 +1,30 @@ +import { readdir, readFile } from "fs/promises"; +import { join } from "path"; +import * as yaml from "js-yaml"; + +import { init } from "./db"; + +class Page { +} + +async function main() { + // TODO: configure this thru cmdline or something later + let materials_dir = "../material"; + let db_file = "test.db"; + + let db = await init(db_file); + + let names = await readdir(materials_dir); + + await Promise.all(names + .filter(name => name.toLowerCase().endsWith(".yml")) + .map(async name => { + let path = join(materials_dir, name); + let rawData = await readFile(path, { encoding: "utf8" }); + let parsedData = yaml.load(rawData); + console.log("data", parsedData); + }) + ); +} + +main(); diff --git a/compile-database/package.json b/compile-database/package.json index 86069b0..6e9ed95 100644 --- a/compile-database/package.json +++ b/compile-database/package.json @@ -1,6 +1,14 @@ { "name": "compile-database", + "scripts": { + "start": "ts-node index.ts" + }, "devDependencies": { "ts-node": "^10.2.1" + }, + "dependencies": { + "js-yaml": "^4.1.0", + "sequelize": "^6.6.5", + "sqlite3": "^5.0.2" } } diff --git a/compile-database/tsconfig.json b/compile-database/tsconfig.json new file mode 100644 index 0000000..504cd64 --- /dev/null +++ b/compile-database/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "experimentalDecorators": true + } +} diff --git a/material/README.md b/material/README.md index 9239805..d706da5 100644 --- a/material/README.md +++ b/material/README.md @@ -1,19 +1,2 @@ material === - -This directory contains the material that's used in eduproj. The documents are -all written using restructured text, chosen over markdown for its ability to -specify more structured data while still appearing readable to humans. - -Recognized fields ---- - -General fields: - -- `:title:` specifies the title that will be used when rendering it to a page. - -- `:summary:` is a paragraph-long description of what the topic being discussed - is, and will be included in hover boxes or info boxes when included in other - pages. - - diff --git a/material/fp-course.yml b/material/fp-course.yml new file mode 100644 index 0000000..be8b60c --- /dev/null +++ b/material/fp-course.yml @@ -0,0 +1,4 @@ +title: Functional Programming Basics +content: | + This listing contains some of the basics of functional programming. + diff --git a/material/fp-function.yml b/material/fp-function.yml new file mode 100644 index 0000000..fc63ed3 --- /dev/null +++ b/material/fp-function.yml @@ -0,0 +1,33 @@ +title: Functions +summary: | + Functions describe a process of turning *inputs* into *outputs*. + +content: | + In a purely mathematical setting, functions typically have one input and one + output, but in functional programming, we can usually get around this either + by using [tuples][1] or by [currying][2]. + + [1]: page://tuples + [2]: page://currying + +exercises: + + - description: | + Write a function called `doubleIt` that takes an integer and doubles it. + + examples: + ocaml: + - | + + grader: + ocaml: + style: studentModule + props: + interface: | + val doubleIt : int -> int + driver: | + open List + let () = List.iter + (fun x -> assert ((doubleIt x) = (x * 2))) + (List.init 100 (fun x -> x + 1)); + diff --git a/ideas.txt b/notes.txt similarity index 51% rename from ideas.txt rename to notes.txt index e73982d..c592222 100644 --- a/ideas.txt +++ b/notes.txt @@ -1,9 +1,11 @@ concepts: - learning targets - can relate to other concepts in the following ways: - - concept A "depends" on concept B; explaining concept A requires some information from concept B + - concept A "depends" on concept B; explaining concept A requires some + information from concept B - concept A "optdepends" on concept B - - concept A "satisfies" concept B; mastery of concept A implies mastery of concept B + - concept A "satisfies" concept B; mastery of concept A implies mastery of + concept B topics: - groups of concepts @@ -15,3 +17,20 @@ each user has a mastery level for each concept references: - super memo algorithm used by anki: https://en.wikipedia.org/wiki/SuperMemo#Description_of_SM-2_algorithm + +--- + +ocaml should have a runner studentModule, which just puts the student code into +a file called student.ml + +the material file defines a student.mli, as well as a driver.ml, then they all +get called using: + +``` +ocamlc -c student.mli # produces student.cmi +ocamlc -c student.ml # produces student.cmo +ocaml student.cmo driver.ml +``` + +probably should have like $OCAMLCFLAGS in there to be able to customize each +step as well