Skip to content

Instantly share code, notes, and snippets.

View allain's full-sized avatar

Allain Lalonde allain

View GitHub Profile
@allain
allain / need.js
Last active October 7, 2017 03:07
use npmjs from the browser
console.log('installed: need, crave')
crave = m => fetch(`https://wzrd.in/bundle/${m}@latest/`)
.then(r => r.text())
.then(eval)
.then(() => require(m))
need = m => {crave(m).then(r => {
window[m] = r
console.log(`installed: ${m}`)
})}
@allain
allain / reset.sh
Last active October 7, 2017 21:12
reset all git commits to some time in the past
git reset --hard PASTCOMMIT
git reset --mixed CURRENTCOMMIT
git commit -m "Message about reversal"
const vm = require('vm')
const repl = require('repl')
const globals = {
Date,
JSON
}
const state = {}
@allain
allain / index.ts
Last active December 27, 2018 18:45
stage0 TypeScript spike
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()
@allain
allain / AgentMemoryRepo.js
Created April 17, 2019 17:14
Amazing things with pikapkg and tree shaking
import AgentRepo from './AgentRepo'
class AgentMemoryRepo extends AgentRepo {
load() {
}
}
@allain
allain / delete-node-modules.sh
Created May 9, 2019 13:51
remove all node_modules recursively
#!/bin/bash
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
@allain
allain / mergeRequests.js
Last active June 26, 2019 15:28
merges GraphQL requests
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
})
@allain
allain / auto-fill.js
Last active May 23, 2020 18:14
Script to auto-fill a form
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 = () => {
@allain
allain / dreamcode1.js
Last active July 25, 2020 23:34
Dreamcoding an Event Sourced DDD JavaScript Library
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':
@allain
allain / items.spec
Last active August 8, 2020 16:42
Dream Code for a Event Sourced DSL System
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!