Skip to content

Instantly share code, notes, and snippets.

View jktravis's full-sized avatar

Joshua Travis jktravis

View GitHub Profile
@jktravis
jktravis / machine.js
Created July 13, 2021 14:38
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@jktravis
jktravis / remix test
Created June 6, 2021 22:35
Created from Remix Form!
if (remix.isAwesome) {
return "Tell your friends";
} else {
return "Demand a refund!";
}
@jktravis
jktravis / remix test
Created June 6, 2021 22:33
Created from Remix Form!
if (remix.isAwesome) {
return "Tell your friends";
} else {
return "Demand a refund!";
}
/**
* A "parser" of an object similar to classnames.
* Includes the key and value when the include prop is truthy
* Filters out the key/value otherwise.
*/
const reduce = require('lodash/fp/reduce');
const toPairs = require('lodash/fp/toPairs');
const compose = require('lodash/fp/compose');
@jktravis
jktravis / wrap.js
Created February 20, 2020 20:08
A function to wrap numbers around
// I found this somewhere, but cannot remember where.
// feel free to leave a comment if you'd like to claim it.
const wrap = function(min, max, v) {
const rangeSize = max - min;
return ((((v - min) % rangeSize) + rangeSize) % rangeSize) + min;
};
@jktravis
jktravis / Map1.jsx
Created December 14, 2018 00:35
Comparing listener-based v non-listener approach of getting geojson
class Map extends Component {
loadIncidents = () => {
const { project, baseMapApi } = this.props;
this.incidentEntrySource = new VectorSource({
format: new GeoJSON(),
url: `${baseMapApi}path/to/resource/${project.id}`
});
this.incidentEntryLayer = new VectorLayer({
source: this.incidentEntrySource,
const partial1 = function partial(fn) {
// Drop the function from the arguments list and
// fix arguments in the closure.
const args = [].slice.call(arguments, 1);
// Return a new function with fixed arguments.
return function() {
// Combine fixed arguments with new arguments
// and call fn with them.
const combinedArgs = args.concat(
@jktravis
jktravis / convert.js
Created May 27, 2017 02:01
Converts a Font Awesome font into a image using canvas.
// Thanks to Jake Trent for the tip on how to do this
// https://jaketrent.com/post/react-dnd-text-drag-preview/
// Create the canvas
const c = document.createElement('canvas');
const ctx = c.getContext('2d');
const body = document.querySelector('body');
body.appendChild(c);
@jktravis
jktravis / createErrorHandler.js
Last active February 14, 2017 01:18
A simple error handler to be used with the auto-dispatched failTypes in redux-logic.
function handleError (type, error) {
console.error(error);
let payload;
if (typeof error === 'string') {
payload = error;
} else if (error.message) {
payload = error.message;
}
return {type, payload, error: true };
}

Keybase proof

I hereby claim:

  • I am jktravis on github.
  • I am jktravis (https://keybase.io/jktravis) on keybase.
  • I have a public key ASBnSUSRq2VafF3mvh7BrVUC1waCoHWIzIGgkLR3V5VBfQo

To claim this, I am signing this object: