Skip to content

Instantly share code, notes, and snippets.

View rlamacraft's full-sized avatar

Robert Lamacraft rlamacraft

View GitHub Profile
@rlamacraft
rlamacraft / slices.js
Created December 26, 2023 11:31
Slices of arrays in JavaScript
function* makeSlices(delim, array) {
let offset = 0;
let length = 0;
for(let x of array) {
if (x === delim) {
yield {
offset,
length,
get: (i) => {
if (i < 0 || i > length) { throw "OutOfBounds"; }
@rlamacraft
rlamacraft / RocResultInTypeScript.ts
Last active June 21, 2023 20:11
Roc's Result type in TypeScript; an arguably a better version of Maybe type
/*
* This type defines the internal state of our class so
* that we can use type refinement to check each branch.
* It should not be exported from this module and is
* purely an implementation detail.
*/
type InternalResultState<Value, Error> = {
tag: "Ok",
value: Value,
} | {
@rlamacraft
rlamacraft / continuation-style.js
Last active April 10, 2022 15:24
JS without assignment or semicolons; a sort of E-DSL, I guess
/*
* We first need to create a few functions that will facilitate out weird syntax that
* relies on continuation-style programming wherein the next statement is executed as
* a lambda invoked by the previous statement. For clarity, `cf` is shorthand for
* callforward; like a callback, but not really.
*/
const define = (name, body, cf) => scope => cf({...scope, [name]: body(scope)});
const include = (as, module, cf) => scope => cf({...scope, [as]: module});
const main = (body) => scope => body(scope);
@rlamacraft
rlamacraft / goodReadToRec.sh
Last active January 2, 2021 17:12
Migrating GoodReads CSV export to Recfile
awk -v FPAT='[^,]*|"[^"]+"' 'BEGIN{
print "# -*- mode: rec -*-";
print "";
print "%rec: To Read";
print "";
}
/to-read/ {
gsub("\"","",$2);
print "Name: " $2;
print "Author: " $3;
# This YouTube video has a number of other people
# involved and links to them in the description in
# a clean way. Should serve as a good origin node.
ORIGIN_VIDEO_ID = "zUDqI9PJpc8"
import os
import json
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
@rlamacraft
rlamacraft / README.md
Created February 1, 2019 11:59
SCRIPT-8
@rlamacraft
rlamacraft / designer.html
Last active October 24, 2015 15:21
designer
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../core-pages/core-pages.html">
<polymer-element name="my-element">