This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: | |
// console.log(await new PromisedValue([1,2,3]).map(x => x * 2).filter(x => x % 2)) | |
// | |
// instead of this: | |
// console.log(await Promised.resolve([1,2,3]) | |
// .then(arr => arr.map(x => x * 2)) | |
// .then(arr => arr.filter(x => x % 2))) | |
export function PromisedValue(target) { | |
target = Promise.resolve(target) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function (Alpine) { | |
const findInParent = (prop) => (el) => { | |
while (el && !el[prop]) el = el.parentElement | |
return el?.[prop] | |
} | |
Alpine.magic('attrs', findInParent('_x_attrs')) | |
Alpine.magic('props', findInParent('_x_props')) | |
Alpine.magic('slots', findInParent('_x_slots')) | |
Alpine.directive('component', xComponentDirective) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context items | |
// Define commands and their respective events when they succeed. | |
// creatorId would be extracted from the context of the command | |
command CreateItem { | |
title: String! | |
} -> ItemCreated { | |
id: ID! | |
title: String! | |
creatorId: RefID! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { App, Event, Problem, Reducer, Validator } from '.' | |
const app = App() | |
// an reducer middleware that places the reduction on the context | |
const statsReducer = Reducer( | |
'stats', | |
({count, total, min, max}, event) => { | |
switch (event.name) { | |
case 'recorded': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function insertJquery() { | |
let loaded = false | |
if (loaded) return Promise.resolve(jQuery) | |
return new Promise(resolve => { | |
const scriptEl = document.createElement('script') | |
scriptEl.setAttribute('src', 'https://code.jquery.com/jquery-3.5.1.min.js') | |
scriptEl.setAttribute('integrity', "sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=") | |
scriptEl.setAttribute('crossorigin', 'anonymous') | |
scriptEl.onload = () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { parse, print, visit } from "graphql" | |
export default function mergeRequests(requests) { | |
const numberedAsts = requests.map(({ query }, index) => { | |
let ast = parse(query) | |
ast = numberVars(ast, index) | |
ast = numberSelectionSet(ast, index) | |
return ast | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
find . -name "node_modules" -type d -prune -exec rm -rf '{}' + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AgentRepo from './AgentRepo' | |
class AgentMemoryRepo extends AgentRepo { | |
load() { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface AugmentedNode extends Node { | |
collect(node?: Node): { [key: string]: AugmentedNode } | |
} | |
// A helper function to clean up some of the tree iteration code | |
function createIterator(node: Node) { | |
// Since #refs can only be on Elements and Texts, limit the iteration to them | |
// createTreeWalker receives a deprecation warning, node iterator seems to work as well | |
const i = document.createNodeIterator(node, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT) | |
return () => i.nextNode() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const vm = require('vm') | |
const repl = require('repl') | |
const globals = { | |
Date, | |
JSON | |
} | |
const state = {} |
NewerOlder