Skip to content

Instantly share code, notes, and snippets.

View mpolichette's full-sized avatar
🏠
Working from home

Matt Polichette mpolichette

🏠
Working from home
  • Tandem Diabetes Care
  • Salt Lake City, UT
View GitHub Profile
@mpolichette
mpolichette / index.d.ts
Last active July 25, 2020 22:31
React Ranger types
declare module 'react-ranger' {
import React, { CSSProperties } from 'react'
export interface RangerOptions {
values: number[]
min: number
max: number
stepSize: number
steps?: number[]
tickSize?: number
@mpolichette
mpolichette / SlidingWindow.js
Created April 24, 2020 05:33
A simple sliding window class
class SlidingWindow {
constructor(options) {
this.before = options.before || 0
this.after = options.after || 0
this.blockSize = options.blockSize || 1
this.bounds = options.bounds || [-Infinity, +Infinity]
this.start = null
this.end = null
this.startIndex = null
@mpolichette
mpolichette / PasteInConsole.js
Created October 2, 2018 19:39
Global log all media events
window.repeat = (str, times) => (new Array(times + 1)).join(str);
window.pad = (num, maxLength) => window.repeat('0', maxLength - num.toString().length) + num;
window.formatTime = time => `${window.pad(time.getHours(), 2)}:${window.pad(time.getMinutes(), 2)}:${window.pad(time.getSeconds(), 2)}.${window.pad(time.getMilliseconds(), 3)}`;
window.logMediaEvent = (name, event) => {
const time = formatTime(new Date)
const video = event.target
console.log(`${name} @ ${time}`, video)
}
window.events = [
@mpolichette
mpolichette / MachineCore.js
Last active May 10, 2018 19:18
An xstate interpreter
import EventEmitter from 'eventemitter3'
import { Machine } from 'xstate'
import fibonacci from 'shared/lib/fibonacci'
const CORE_EVENT_REGX = /^core:(.*)/
export default class MachineCore extends EventEmitter {
constructor(chart) {
super()
this.machine = new Machine(chart)
@mpolichette
mpolichette / index.js
Created May 6, 2015 16:48
Alfred holla workflow
#! /usr/bin/env node
var alfredo = require('alfredo')
var exec = require('child_process').exec;
var _ = require('lodash');
var team = require('./team.json')
function fuzzyFindUsers(query) {
var names = _(team).pluck('name').value()
var matches = alfredo.fuzzy(query, names)
return _.map(matches, function(name){ return _.findWhere(team, {name: name})})
function delegate (child) {
// make it happen
determineKey = function (on, toFind) {
var correctKey;
keys = Object.keys(on);
keys.forEach(function(key){
if (on[key] === toFind) {
correctKey = key;
}
});
@mpolichette
mpolichette / RouteListener.js
Last active December 23, 2015 11:29
Example route listener
App.module("BreadcrumbApp", function(BreadcrumbApp, App, Backbone, Marionette, $, _){
var API = {
showProject: function(id){
new BreadcrumbApp.Show.Controller({
/* Stuff */
});
},
showUser: function(id){
Imagine that you are generating a report of assignment submission information for all of the students in a particular course from given arrays of students, assignments, and submissions. Here is some pseudocode that accomplishes that goal:
for assignment in assignments
print assignment.name
for student in students
for submission in submissions
continue if submission.student_id != student.id
continue if submission.assignment_id != assignment.id
print student.name, submission.grade
// Original Code
// I've annoted some places where I find bugs
$(function() {
$.get("/reviews.json", {}, function(data) {
for (var review in data) {
var elem = "<li>";
if (review.rating) {
elem += review.rating + " - ";
}
elem += review.title + " - ";
(function () {
$(function(){
$("#colorize").on("click", function () {
$("div.color-container > p").css({"color": "red"});
});
});
})();