Instantly share code, notes, and snippets.

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"
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
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
View abstract-company-api.js
const express = require("express");
const app = express();
class Company {
static find(id) {
// Eventually be using an ORM, like Sequelize
const companies = this.all;
const company = companies.find(c => c.id === id);
if (!company) return null;
View company-api.js
const express = require("express");
const app = express();
function expand(companies, ids) {
return ids.map(id => companies.find(c => c.id === id));
}
// GET /1234
app.get("/api/v1/companies/:id", (req, res) => {
const companies = [
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>
);
}
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)
}
}
View webpack.config.js
const path = require('path')
const NODE_ENV = process.env.NODE_ENV || 'development'
const outputFile = 'pdfmake.js'
const libraryName = 'pdfmake'
const config = {
entry: './src/browser-extensions/pdfMake.js',
output: {
path: path.join(__dirname, './build'),