Skip to content

Instantly share code, notes, and snippets.

View luggage66's full-sized avatar

Donald Mull Jr. luggage66

View GitHub Profile
@luggage66
luggage66 / changeType.ts
Last active March 7, 2019 03:49
TS to change a type based on a "config type"
// original code by MadaraUchiha
// Just defines named types we can reference by key. Never used as a real value type.
interface Operations<T> {
'delete': never;
'nullable': T | null;
'box': {value: T};
};
type MemberConfig<T> = keyof Operations<T>;
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { accessor } from 'react-big-calendar/lib/utils/accessors';
import { accessor as accessorPropType } from 'react-big-calendar/lib/utils/propTypes';
import { noop } from 'lodash';
import { zonedToLocal, localToZoned } from '/client/utils/timezones';
import { hasTime, shiftDate, shiftHour } from '/client/utils/date';
/**
* withTimeZone - HOC to add time zone support to react-big-calendar
const KEYWORD_MAP = {};
/*
KEYWORD_MAP[<user_id>][<term>] returns the reply
*/
KEYWORD_MAP[774078] = {
'jesus': 'http://i.imgur.com/V1kcfEU.jpg'
};
KEYWORD_MAP[617762] = {
'BAM!' : 'SPACE GUN!'
};
@luggage66
luggage66 / Makefile
Created September 8, 2017 15:59 — forked from ssube/Makefile
webpack makefile
# Git
GIT_REF = $(shell git rev-parse --abbrev-ref HEAD)
GIT_REV = $(shell git rev-parse HEAD)
# CI
CI_COMMIT_REF_SLUG ?= $(GIT_REF)
CI_ENVIRONMENT_SLUG ?= local
CI_RUNNER_DESCRIPTION ?= $(shell hostname)
# Debug
import React, { Component } from 'react';
class Notification extends Component {
render() {
var type = this.props.type == null ? 'default' : this.props.type;
return <div className={"notification " + type}>{this.props.message}{this.props.cancellable == 1 && <i className="material-icons" onClick={this.props.onCancel}>&#xE5CD;</i>}</div>;
}
}
export default Notification;
@luggage66
luggage66 / dateInput.jsx
Created February 8, 2017 15:54
A simple date input
import React, { Component } from 'react';
import moment from 'moment';
const DEFAULT_DISPLAY_FORMAT = 'MM/DD/YYYY'; // what the input shows when the user isn't typing
const DEFAULT_DATA_FORMAT = 'YYYY-MM-DD'; // the value is expected to be in this format and this control ouputs this format
const DEFAULT_ACCEPTED_FORMATS = [ //the user may type of of these
'MM/DD/YYYY',
'M/D/YY',
'M/D',
'MM-DD-YYYY',
@luggage66
luggage66 / spawn-express.js
Created December 22, 2016 00:39
Example: running a process and piping output back to web client
import { spawn } from 'child_process';
// app is an express server
app.get('/some/url/:someOption' function(req, res, next) {
let { someOption } = req.params;
let commandProcess = spawn('node', ['someScript.js', someOption]);
commandProcess.stdout.setEncoding('utf8');
commandProcess.stderr.pipe(process.stderr);
@luggage66
luggage66 / valueInspector.jsx
Last active September 23, 2016 00:55
CFDump-like output for JS objects
import React, { Component } from 'react';
import './valueInspector.less';
import Immutable from 'immutable';
export default class ValueInspector extends Component
{
render() {
let referenceTracker = new CircularReferenceTracker();
let path = Immutable.List();
@luggage66
luggage66 / reactBindingHandler.js
Last active December 22, 2016 00:43
Knockout React BindingHandler. Fiddle: https://jsfiddle.net/luggage66/yoofaaqr/
// Inspired by http://www.intelligiblebabble.com/making-reactjs-and-knockoutjs-play-nice
import ko from 'knockout';
import ReactDOM from 'react-dom';
const reactBindingHandler = {
init(element, valueAccessor, allBindings, viewModel, bindingContext) {
// make sure we cleanup, later.
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
ReactDOM.unmountComponentAtNode(element);
});
@luggage66
luggage66 / fixBookShelfES6Inheritance.js
Created September 16, 2015 19:03
Bookshelf.js 0.8.2 static method inheritance monkey-punching
export default function fixBookShelfES6Inheritance(target) {
// console.log('Fixing:', target.name);
let parentConstructor = Object.getPrototypeOf(target.prototype).constructor;
let parentStaticProperties = Object.keys(parentConstructor);
// console.log('Adding static properties:', parentStaticProperties);
// TODO: Deal with static methods that want to call super() (right now they are REPLACED!)
parentStaticProperties.forEach(propName => target[propName] = parentStaticProperties[propName]);
}