Skip to content

Instantly share code, notes, and snippets.

View kohesion's full-sized avatar

Matthew C Baker kohesion

  • Kohesion
  • Atlanta GA
View GitHub Profile
@kohesion
kohesion / git-activity-summary
Created October 9, 2023 20:33
git activity summary
git log --no-merges --since="21 days ago" --pretty=format:%an --numstat | awk '/./ && !author { author = $0; next } author { ins[author] += $1; del[author] += $2 } /^$/ { author = ""; next } END { for (a in ins) { printf "%10d %10d %10d %s\n", ins[a] - del[a], ins[a], del[a], a } }' | sort -rn
// standardize square size
iconSizeX = 50
iconSizeY = 50
gridSizeX = 20
gridSizeY = 15
shipX = Math.floor(gridSizeX / 2)
shipY = gridSizeY - 1
grid = Array(gridSizeY).fill().map(() => Array(gridSizeX).fill(' '))
shots = []
@kohesion
kohesion / retryWrapper.js
Created January 21, 2021 19:23
Fetch Retry Wrapper
/**** Use it like this ****/
/*
RW = new RetryWrapper({max: 3, delay: 3000});
RW.fetch('http://www.google.com/')
.then(r => console.log('worked', r))
.catch(e => console.error('whoops', e));
*/
class RetryWrapper {
@kohesion
kohesion / Observable.js
Last active January 17, 2022 17:40
Simple Observable implementation
// sometimes you want to queue up messages for a component that isn't loaded yet
// This is the type of problem RXJS is useful for...
// ...but I didn't want to import RXJS for such a simple need
// Use it like this:
///////// In your producer code //////////////////
// import Observable from '_shared/util/Observable';
// o = new Observable();
//
@kohesion
kohesion / mysql-async-await-queries
Created July 9, 2018 21:40
node mysql query callback to async await for connection pools
pool.q = (...args) => new Promise ((resolve, reject) => {
pool.query(...args, (error, ...successParams) => {
if(error) {
console.error('MYSQL Error:', error);
reject(error.toString());
}
else {
resolve({
results: successParams[0],
fields: successParams[1]
@kohesion
kohesion / donut.js
Created July 3, 2018 18:07
Donut - Customization of d3 donut pie chart visualization
import * as d3 from "d3";
var i = 0;
let radius;
const donut = function() {
var data = [],
width,
height,
margin = {top: 10, right: 10, bottom: 10, left: 10},
@kohesion
kohesion / ReactD3VisualizationComponentWrapper.jsx
Created June 4, 2018 15:38
React D3 Visualization Component Wrapper Example
import React, { Component } from 'react';
import Gauge from '../../visualizations/gauge';
import * as _ from 'lodash';
class ComponentGauge extends Component {
constructor (props) {
super(props);
}
componentDidMount() {
this.gauge = new Gauge(this.refs.gauge, _.extend({
@kohesion
kohesion / gauge.js
Created June 4, 2018 15:35
D3 v4 Gauge Visualization
import * as d3 from "d3";
import * as _ from 'lodash';
export default function(container, configuration) {
let that = {};
// eventually these should be class members
let svg,
r,
tickData,
@kohesion
kohesion / diff-objects.lodash.js
Last active September 20, 2017 16:36
Diff Objects with lodash.js
// Returns array of keys that are different between the two objects
// takes account of values that differ between matching keys or missing keys from either object
// result is deduped
function diffObjects (a, b) {
return _(a).toPairs().xorBy(_.toPairs(b), JSON.stringify).fromPairs().keys().value();
}
class Clock extends React.Component {
constructor (props) {
super(props);
console.log('props', props);
this.state = {
timeTarget: props.timeTarget,
days: 0,
hours: 0,