Skip to content

Instantly share code, notes, and snippets.

@RobertFischer
RobertFischer / JS.this.gotcha.js
Last active April 27, 2018 13:39
The Mystery of the Vanishing Self: A deep dive into a JavaScript functional programming gotcha and the meaning of "this".
"use strict";
import Promise from 'bluebird';
import _ from 'lodash';
Promise.resolve({a:'a',b:2,c:True}).then(_.values); // This will work, returning ['a',2,True] (or some permutation thereof)
// Now let's create our own object implementing _.values(obj).
class Valuator {
values(obj) {
@RobertFischer
RobertFischer / task.js
Last active April 3, 2018 15:58
Task Completion Calculation
const {taskArray,completeTasks} = this.props; // These are both arrays of task ids (and nothing else)
const totalTaskSize = _.size(taskArray);
const completeTaskSize = _.size(_.intersection(taskArray, completeTasks)) // https://lodash.com/docs/4.17.5#intersection
const pctComplete = (completeTaskSize*1.0)/(totalTaskSize*1.0);
@RobertFischer
RobertFischer / Parchment Processing.jsx
Last active March 12, 2018 16:51
Parchment Processing
// Initialize the loop variables
let currentLine = [] // ops making up the current line
const content = [] // Components that we will ultimately render
// Map parchment attributes to React styling object
const attrsToStyle = (attrs) => {
console.warn("Don't forget to implement styling!");
return {};
};
onClick=>{
() => this.setState({pageNumber:this.state.pageNumber+1})
}
@RobertFischer
RobertFischer / .babelrc
Last active March 6, 2018 21:15
Babel Configuration File for a Nicer Development Environment
{
"presets": [
"react-native"
],
"plugins": [
"transform-strict-mode",
[ "auto-import",
{ "declarations": [
{ "default": "React", "path": "react" },
{ "default": "_", "path": "lodash" },
@RobertFischer
RobertFischer / fib.hs
Last active March 6, 2018 14:07
Haskell fib
fib :: Int -> Int
fib 0 = 0
fib 1 = 1
fib 2 = 2
fib i | i < 0 = error "argument to fib must be > 0"
fib i = fib (i-1) + fib (i-2)
import Promise from "bluebird";
Promise.try(() => axios.get(CAREPLAN_URL))
.tap(response => console.log(CAREPLAN_URL, response))
.then(response => response.data)
.then(data => this.ds.cloneWithRows(data))
.then(dataSource => this.setState({dataSource}))
.catch(e => console.error("Getting careplan failed", CAREPLAN_URL, e)
;
@RobertFischer
RobertFischer / index.scss
Created January 9, 2018 22:01
Nesting for .ql-editor
.ql-editor {
font-family: "Museo Sans";
h1 {
font-weight: 500;
font-size: 22pt;
color: #002F5F;
}
h2 {
@RobertFischer
RobertFischer / index.scss
Created January 9, 2018 21:46
Hide blank Quill sections via SCSS
.ql-blank {
@extend .d-none;
}
@RobertFischer
RobertFischer / pretty-print-alternative.js
Created January 9, 2018 14:59
pretty-print replacement
const print = function() { require("console").dir(it); }