Skip to content

Instantly share code, notes, and snippets.

View schester44's full-sized avatar
👋

Steve Chester schester44

👋
View GitHub Profile
@schester44
schester44 / garage.js
Created May 8, 2020 00:22
RaspberryPi + NodeJS Garage Door Opener
/**
* This file should be a repo but oh well..
* This code will check a magnetic sensor value and send a text message via twilio if the circuit remains open for an extended amount of time
* Used Koa for an http server so I could read the current state via clients.
**/
const Koa = require("koa")
const Router = require("koa-router")
const rpio = require("rpio")
const cors = require("@koa/cors")
@schester44
schester44 / gist:16be0720bbe7b2d01a38eb1baa3a2d89
Created March 6, 2019 15:22
find the shortest distance between a point and a line segment.
import { render } from "react-dom";
import React from "react";
import { Stage, Text, Layer, Line, Circle } from "react-konva";
const originalPoints = [
{ x: 294, y: 344 },
{ x: 322, y: 451 },
{ x: 547, y: 379 },
{ x: 505, y: 251 },
{ x: 417, y: 317 }
@schester44
schester44 / gist:d71e02e230ee457437f6482a22d954a1
Created October 16, 2018 15:40
access nested objects by string key
function resolve(path, obj=self, separator='.') {
return (Array.isArray(path) ? path : path.split(separator)).reduce((prev, curr) => prev && prev[curr], obj)
}
@schester44
schester44 / flatten object.js
Last active October 16, 2018 15:44
deep flatten nested object
const flatten = (obj, prefix = '') => {
return Object.keys(obj).reduce((acc, key) => {
const value = obj[key]
const prefixedKey = `${prefix}${prefix !== '' ? '.' : ''}${key}`
if (typeof value === "string") {
return {
...acc,
prefixedKey]: curr
@schester44
schester44 / DeviceList.js
Created February 26, 2018 16:56
React-based Pagination component & HOC
# Example Usage:
import React from "react"
import Pagination, { withPagination } from "components/Pagination"
const DeviceList = ({ data, setCurrentPage, currentPage }) => {
const perPage = 25
const lastIndex = currentPage * perPage
const firstIndex = lastIndex - perPage
@schester44
schester44 / zshrc
Last active August 22, 2018 17:47
zsh backup
POWERLEVEL9K_MODE='nerdfont-complete'
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="%F{cyan}\u256D\u2500%f"
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%F{014}\u2570%F{cyan}\uF460%F{073}\uF460%F{109}\uF460%f "
POWERLEVEL9K_STATUS_VERBOSE=false
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(time)
POWERLEVEL9K_PROMPT_ON_NEWLINE=true