Skip to content

Instantly share code, notes, and snippets.

@bradharms
bradharms / redux-inject.js
Last active December 9, 2015 19:15
Allows Redux action creators to use a limited form of dependency injection.
/**
* Allows Redux action creators to use a limited form of dependency injection.
*
* To apply:
*
* import { applyMiddleware, createStore } from 'redux';
* import inject from './redux-inject';
*
* import dep1 from '.../dep1';
* import dep2 from '.../dep2';
@bradharms
bradharms / backbone-bookshelf-inheritence-test.js
Last active December 9, 2015 23:22
Test behavior of Backbone and Bookshelf using different kinds of inheritence
var _ = require('lodash');
var Backbone = require('backbone');
var Bookshelf = require('bookshelf');
var Knex = require('knex');
var ModelBaseMixin = {
initialize: function() {
console.log('ModelBaseMixin.initialize()');
this.say();
const PWD = process.cwd();
const BASEDIR = `${PWD}/spec`;
module.exports = config => config.set({
logLevel: config.LOG_INFO,
frameworks: ['browserify', 'jasmine'],
files: [`${BASEDIR}/stuff.karma.js`],
// files: [`${BASEDIR}/**/+([^.]|*.karma).js`],
browsers: ['PhantomJS'],
@bradharms
bradharms / win2wsl.cpp
Last active August 5, 2016 07:55
Communication shim between Wsl and Windows
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <iostream>
#include <regex>
using namespace std;
string toUnix(char*);
@bradharms
bradharms / module-manager.js
Last active September 6, 2016 04:06
An asynchronous module dependency manager that is loosely based on the AMD api. Requires an ES6 compatible browser.
/* jslint esversion: 6 */
/**
* # Module Manager
*
* An asynchronous module dependency manager that is loosely based on the AMD
* api.
*
* Requires an ES6 compatible browser.
*
* ## Usage Example:
@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() {
/**
@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 / 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 / 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.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({