Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Full-time @ Bonsai

Dana Woodman danawoodman

👨‍💻
Full-time @ Bonsai
View GitHub Profile
@danawoodman
danawoodman / Field.svelte
Created Sep 16, 2020
Example of using Svelte (with Typescript) to make a simple login form with basic validation. Lot is missing but shows how a few useful concepts
View Field.svelte
<script lang="ts">
export let label: string
export let type: string = "text"
export let value: string = ""
export let disabled: boolean = false
export let validate: (val: string) => boolean
export let valid: boolean = false
let id = `field-${Math.floor(Math.random() * 1000)}`
View test.md

Hello world

This is a test.

  • Foo
  • Bar
  • Baz

Hello

@danawoodman
danawoodman / examples.js
Created Mar 11, 2019
Javascript array examples
View examples.js
// Lots of examples here:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
const arr = [ 1, 2, 3 ]
// first item in array:
arr[0]
// last item:
arr[2]
View doorlock.rules
SUBSYSTEM=="input", GROUP="input", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05df", MODE:="666", GROUP="plugdev"
KERNEL=="hidraw*", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05df", MODE="0666", GROUP="plugdev"
@danawoodman
danawoodman / relay-improved.js
Created Jul 19, 2018
Control a generic USB relay using node-hid. Handles up to 8 relays.
View relay-improved.js
/**
* Control a USB relay board using USB.
*
* This code helped a lot in the understanding of what they boards
* expect for hex inputs:
* https://github.com/jaketeater/Very-Simple-USB-Relay/blob/master/relay.py
*/
const HID = require('node-hid')
const ALL_ON = 0xfe
@danawoodman
danawoodman / relay.js
Last active Jul 19, 2018
Turn on a generic USB relay using node-hid, naive approach
View relay.js
/**
* Control a USB relay board using USB.
*
* This code helped a lot in the understanding of what they boards
* expect for hex inputs:
* https://github.com/jaketeater/Very-Simple-USB-Relay/blob/master/relay.py
*/
const HID = require('node-hid')
const ON = 0xfe
@danawoodman
danawoodman / react-router-basic.js
Last active Jul 3, 2018
Basic React Router setup with Async
View react-router-basic.js
import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
const COMPANIES = [
{
id: 1,
name: "Foo",
accounts: [{ id: 4, name: "SubAccount", accounts: [] }]
View aliases.bash
alias -='cd -'
alias ..='cd ..'
alias ..-='cd .. && cd -'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias be='bundle exec'
alias cl='clear'
alias cleanup='find . -name '\''*.DS_Store'\'' -type f -ls -delete'
alias d='docker'
View product-list.jsx
import React, { Component } from "react";
function ProductItem({ product }) {
return (
<li>
{product.name} {product.price}
</li>
);
}
@danawoodman
danawoodman / index.js
Last active Dec 22, 2016
Example of using WebPack to create frontend assets for a non-SPA (Single Page App) project where you selectively load React components within specific templates.
View index.js
import MyStuff from 'frontend/components/my-stuff'
module.exports = {
renderStuff(node, props) {
// Wrap in <Provider/> here too if using Redux
ReactDOM.render(<MyStuff {...props} />, node)
}
}
You can’t perform that action at this time.