Skip to content

Instantly share code, notes, and snippets.

Avatar

Leroy Campbell artisonian

View GitHub Profile
@artisonian
artisonian / line_reader.ts
Last active Mar 23, 2020
How to read lines in Deno
View line_reader.ts
import { readLines } from "https://deno.land/std@v0.36.0/io/mod.ts";
import { parse } from "https://deno.land/std@v0.36.0/flags/mod.ts";
import { basename } from "https://deno.land/std@v0.36.0/path/mod.ts";
export {};
if (import.meta.main) {
const args = parse(Deno.args, {
boolean: ["h"],
alias: {
View app.ts
import {
yellow,
cyan,
bold,
red
} from "https://deno.land/std@v0.31.0/fmt/colors.ts";
import { serve } from "https://deno.land/std@v0.31.0/http/mod.ts";
import {
MultipartReader,
FormFile
View spark.ts
/**
* spark - https://github.com/holman/spark
*
* The MIT License
* Copyright (c) Zach Holman, https://zachholman.com
*/
import { parse } from "https://deno.land/std@v0.30.0/flags/mod.ts";
export function spark(...nums: number[]): string {
let min = Infinity;
View erudite.ts
import { parse } from "https://deno.land/std@v0.30.0/flags/mod.ts";
import { EOL } from "https://deno.land/std@v0.30.0/path/mod.ts";
import marked from "https://raw.githubusercontent.com/denolib/marked/master/main.ts";
const args = parse(Deno.args);
if (args.h || args.help) {
printUsage();
Deno.exit(0);
}
View the-most-beautiful-program.rkt
#lang racket/base
(require racket/list
racket/match)
; The call-by-value lambda calculus:
(define (eval-expr expr env)
(match expr
[(? symbol?)
(env expr)]
View main.go
// see http://www.eprg.org/computerphile/tripref.c
package main
import (
"fmt"
"strings"
)
type thing struct {
item string
@artisonian
artisonian / use-flux.js
Created Mar 3, 2019
Bringing back the central dispatcher from Flux, but this time with hooks
View use-flux.js
import { useEffect, useReducer } from "react";
const dispatchers = new Map();
function centralDispatch(type, payload) {
for (const dispatch of dispatchers.keys()) {
dispatch({ type, payload });
}
}
@artisonian
artisonian / async-iterator.js
Last active Mar 1, 2019
Async Iterator Example
View async-iterator.js
main().catch(console.error);
async function main() {
const clicks = streamify(document, "click");
let clickCount = 0;
for await (const event of clicks) {
console.log("click", event, clickCount);
if (clickCount++ > 2) {
clicks.return();
}
View async-iterator.js
main().catch(console.error);
async function main() {
const clicks = streamify(document, "click");
let clickCount = 0;
for await (const event of clicks) {
console.log("click", event, clickCount);
if (clickCount++ > 2) {
clicks.return();
}
View automata.rkt
#lang racket
(module+ test
(require rackunit))
(define state-machine
'((init (c more))
(more (a more)
(d more)
(r end))