Skip to content

Instantly share code, notes, and snippets.

@bradharms
bradharms / _base-spawn.js
Last active December 23, 2021 21:18
Generates an extendable CommonJS module for spawning sub-processes.
// @ts-check
const child_process = require('child_process');
/**
* Generates an extendable CommonJS module for composing shell commands and running them as child processes.
*
* @param {object} parentConfig
* @param {any[]} parentConfig.args
* Arguments that will be prepended to root shell command.
import getQuizzes from './selectors/getQuizzes';
import setQuizAnswer from './actions/setQuizAnswer';
const useQuizController = () => {
const dispatch = useDispatch();
const quizzes = useSelector(g);
const setQuizAnswer = useCallback((quiz, answer) => dispatch(setQuizAnswer(quiz, answer)), []);
return {
@bradharms
bradharms / index.html
Created June 22, 2018 04:16
Drag to Rotate
<!doctype html>
<html>
<head>
<title>Rotate</title>
<style>
body {
background-color: #443366;
}
#thing {
background-color: #FF3344;
import React, { Component } from 'react';
type Day = {
dayText : string;
}
type Props = { }
type State = {
days : Day[]
#!/bin/bash
skipDownload=false
for arg in $@; do
case $arg in
'--skip-download')
skipDownload=true;
;;
esac
@bradharms
bradharms / index.jsx
Created May 1, 2018 21:02
Composable Components with IC
import React from 'react';
import ReactDOM from 'react-dom';
window.onload = () => ReactDOM.render(<App />, document.body);
class App extends React.Component {
render() {
const pid = 999;
const ProductClosure = makeProductClosure({
@bradharms
bradharms / ccc.ts
Created April 12, 2018 16:27
ccc.ts
type Deps = {
aaa : () => number,
bbb : (a : number, b : number) => number
};
export default ({ aaa, bbb } : Deps) =>
(a : number, b : number) => {
const x = aaa();
const y = bbb(a, b);
return x + y;
@bradharms
bradharms / index.js
Created April 12, 2018 16:11
Example entry point for container-less DI-based application in ES6.
/**
* Example entry point for container-less DI-based application in ES6.
*/
// Master list of all modules used in this configuration in alphabetical order
import aaa_ from './aaa';
import bbb_ from './bbb';
import ccc_ from './ccc';
import altCcc_ from './alternates/ccc';
import ddd_ from './ddd';
@bradharms
bradharms / preprocess.js
Created March 20, 2018 06:12
Language-neutral file preprocessor
/**
* Preprocess a file's contents represented as a string.
*
* This will look for lines containing custom preprocessor directives embedded
* in a string. The directives take the form of psuedo-HTML tags, which begin
* with <@@ COND @@> and end with </@@>, where COND is any valid JavaScript
* expression that is used to test whether the text between the tags
* should be output or not.
*
* Within the COND expressions, the variable __ (double underscore)
@bradharms
bradharms / fs-xml-http-request.js
Last active September 23, 2019 04:17
An XMLHttpRequest-compatible interface to Node's "fs" module.
import fs from 'fs';
let WindowXMLHttpRequest = null;
/**
* An XMLHttpRequest-compatible interface to Node's "fs" module.
*/
class FSXHR {
constructor() {
/**