Skip to content

Instantly share code, notes, and snippets.

Avatar
♻️
obsessing over statecharts

Stephen Bussard sbussard

♻️
obsessing over statecharts
View GitHub Profile
View isHotdog.js
let prop = new Proxy({}, { get: (_, name) => (obj) => obj[name] });
let foods = [
{ name: 'hotdog', isHotdog: true },
{ name: 'pizza', isHotdog: false },
{ name: 'spaghetti', isHotdog: false }
];
console.log(foods.map(prop.name));
View machine.js
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
View run-analysis.sh
#!/usr/bin/env bash
cd ~/Desktop
YOUR_DESKTOP_FOLDER=`pwd` # Mac
mkdir output
docker run --rm -v $YOUR_DESKTOP_FOLDER:/codemaat code-maat -l /codemaat/git.log -c git -a age > output/age.csv
docker run --rm -v $YOUR_DESKTOP_FOLDER:/codemaat code-maat -l /codemaat/git.log -c git -a abs-churn > output/abs-churn.csv
docker run --rm -v $YOUR_DESKTOP_FOLDER:/codemaat code-maat -l /codemaat/git.log -c git -a author-churn > output/author-churn.csv
docker run --rm -v $YOUR_DESKTOP_FOLDER:/codemaat code-maat -l /codemaat/git.log -c git -a authors > output/authors.csv
View exampleRef.js
import React, { useState } from "react";
let ChildComponent = ({ setRef }) => <div ref={setRef}>{/* content */}</div>;
let ParentComponent = () => {
let [ref, setRef] = useState();
useEffect(() => {
if (ref) {
// whatever you want to use ref for
@sbussard
sbussard / EnergyBalls.js
Created Jun 16, 2012
EnergyBalls – animated "energy balls" floating in "space"
View EnergyBalls.js
/*
Author: Stephen Bussard
Twitter: @sbussard
*/
var sin = Math.sin,
cos = Math.cos,
tan = Math.tan,
View do.jsx
let itemData = [
{ name: 'Chair', price: '$199', id: 'abc123' },
{ name: 'Table', price: '$799', id: 'def456' }
];
let Item = ({ description, id }) => <li key={id}>{description}</li>;
let makeProps = ({ name, price, id }) => ({
id,
description: `${name} - ${price}`
View dont.jsx
let itemData = [
{ name: 'Chair', price: '$199', id: 'abc123' },
{ name: 'Table', price: '$799', id: 'def456' }
];
let ItemList = ({ items }) => (
<ul>
{items.map(({ name, price, id }) => (
<li key={id}>{`${name} - ${price}`}</li>
))}
View gem.sh
open https://youtu.be/rfMC2aVhYuo?t=39s
View serializeForm.babel.js
// given a form element
// get its children that have a name attribute
// map to { name, value } objects
// reduce individual into one { [name]: value } object
export default formElement => Array.from(formElement.querySelectorAll('[name]'))
.map(({ name, value }) => ({ name, value }))
.reduce((current, item) => ({ ...current, [item.name]: item.value }), {});
@sbussard
sbussard / minecraft-skydive.py
Last active Sep 30, 2017
skydiving in minecraft with teachcraft
View minecraft-skydive.py
from mcpi import minecraft
from mcpi import block
from minecraftstuff import MinecraftTurtle
from random import randint
import time
import os.path, sys
mc = minecraft.Minecraft.create(address="158.69.221.37", name="steve")
block_air = 0
You can’t perform that action at this time.