Skip to content

Instantly share code, notes, and snippets.

Avatar

Charles Lowell cowboyd

View GitHub Profile
@cowboyd
cowboyd / atom-operation-map.ts
Created Feb 18, 2021
map a key-value object to an operation
View atom-operation-map.ts
export function* map<A>(slice: Slice<Record<string, A>>, operation: (slice: Slice<A>) => Operation<void>): Operation<void> {
let contexts = new Map<string,Context>();
function* synchronize(record: Record<string, A>) {
let keep = new Set<string>();
for (let key of Object.keys(record)) {
if (!contexts.has(key)) {
contexts.set(key, yield spawn(operation(slice.slice(key))))
}
@cowboyd
cowboyd / describe.ts
Created Feb 12, 2021
Hypothetical BDD syntaxt for bigtest that uses generators to build a test tree
View describe.ts
import { Page, TextField, Button, HTML, Heading, including } from '@bigtest/interactor';
import { describe } from '@bigtest/suite/bdd'; //hypothetical bdd syntax entry point
import { createUser } from './helpers';
export default describe("login test", function*() {
yield createUser("cowboyd", "password"); //=> injects `user` into context
yield Page.visit('/sign-in');
yield Heading(including('Sign into app')).exists();
yield describe("with good credentials", function*() {
@cowboyd
cowboyd / pipelined-interactors.ts
Created Dec 3, 2020
Hypothetical pipeline syntax for bigtest tests
View pipelined-interactors.ts
import { Page } from 'bigtest';
import { DashboardCard, Heading } from './interactors';
import { test, step, child, createList } from './client-test-helpers';
export default test('Admin UI: Main Dashboard')
|> createList('SomeEntity', 3)
|> Page.visit('/admin/dashboard')
|> Heading("Dashboard").exists()
|> DashboardCard("Stock Entities").exists()
|> child(
@cowboyd
cowboyd / konami.ts
Created Nov 19, 2020
Konami Code detector written in effection
View konami.ts
import { run } from 'effection';
import { once } from '@effection/events';
run(function*() {
yield konamiCodeEntered();
alert('99 lives!');
});
function * konamiCodeEntered() {
while (true) {
@cowboyd
cowboyd / operation-state.ts
Created Nov 3, 2020
A POJO representing an operation state
View operation-state.ts
type OperationState<T> = {
status: 'unstarted';
} | {
status: 'started';
} | {
status: 'running';
isRunning: true;
} | {
status: 'completed';
value: T;
@cowboyd
cowboyd / nr-spa-1016.js
Created May 8, 2017
New Relic SPA Agent (copyright New Relic, Inc.) : Posted here so that its line numbers can be referenced in a research document.
View nr-spa-1016.js
// modules are defined as an array
// [ module function, map of requires ]
//
// map of requireuires is short require name -> numeric require
//
// anything defined in a previous bundle is accessed via the
// orig method which is the require for previous bundles
(function (modules, cache, entry) { // eslint-disable-line no-extra-parens
// Save the require from previous bundle to this closure if any
@cowboyd
cowboyd / wat.rs
Created Oct 28, 2020
Do stuff on windows
View wat.rs
use neon::prelude::*;
use winapi::shared::minwindef::{TRUE, FALSE};
use winapi::um::winnt::LPSTR;
//use winapi::um::synchapi::{WaitForSingleObject};
//use winapi::um::handleapi::CloseHandle;
use winapi::um::processthreadsapi::*;
use winapi::um::consoleapi::*;
use winapi::um::wincon::*;
use std::process::Command;
@cowboyd
cowboyd / signin.test.json
Created Oct 7, 2020
BigTest suite and its raw JSON equivalent
View signin.test.json
{
"description": "Sign In",
"steps": [
{
"description": "visiting \"/\""
},
{
"description": "click on link \"Sign in\""
}
],
@cowboyd
cowboyd / checkin.interactors.js
Created Aug 26, 2020
One-off interactors I wrote for ui-courses and ui-checkin FOLIO modules
View checkin.interactors.js
import { createInteractor, App } from '@bigtest/interactor';
export const Input = createInteractor('Input')({
selector: 'input',
defaultLocator: (elem) => elem.name,
locators: {
byAriaLabel: element => element.ariaLabel
},
actions: {
type: (elem, val) => {
@cowboyd
cowboyd / index.ts
Created Aug 4, 2020
Setup Browser Simulation
View index.ts
import { Server } from 'miragejs';
import { createGraphQLHandler } from '@miragejs/graphql';
import { schema as schemaSource } from '@self/graphql';
import { factories } from './factories';
export interface Simulation {
create<T>(modelName: string, data?: Record<string, unknown>): T;
createList<T>(modelName: string, count: number): T[];