Skip to content

Instantly share code, notes, and snippets.

@amite
amite / machine.js
Last active March 20, 2020 04:53
Generated by XState Viz: https://xstate.js.org/viz
const lit = {
on: {
BREAK: "broken",
TOGGLE: "unlit"
}
};
const unlit = {
on: {
BREAK: {
@amite
amite / Fields.js
Created January 22, 2019 05:53
React Final form Fields component
import React from 'react'
import { Field } from 'react-final-form'
const Fields = ({
names,
subscription,
fieldsState = {},
children,
originalRender,
}) => {
@amite
amite / stacktrace.sh
Created December 2, 2017 14:35
lambda stack trace for aunch_scrapers function
{ StatusCode: 200,
FunctionError: 'Handled',
LogResult: 'U1RBUlQgUmVxdWVzdElkOiBkNjJmNGE1Yy1kNzZkLTExZTctYWU0Yy1kNWNlNTgzOGI2ZjAgVmVyc2lvbjogJExBVEVTVAoyMDE3LTEyLTAyVDE0OjM0OjAxLjAwMloJZDYyZjRhNWMtZDc2ZC0xMWU3LWFlNGMtZDVjZTU4MzhiNmYwCXsiZXJyb3JNZXNzYWdlIjoiRXJyb3Igc2NyYXBpbmcgbWlzc2lvbi1kb2xvcmVzLXBhcmstc2FuLWZyYW5jaXNjbzogXCJFcnJvciBwYXJzaW5nIHBhZ2U6IHt9XCIiLCJlcnJvclR5cGUiOiJFcnJvciIsInN0YWNrVHJhY2UiOlsiZ2V0UGFnZS50aGVuLnRoZW4udGhlbi5jYXRjaC5lcnJvciAoL3Zhci90YXNrL2hhbmRsZXIuanM6MjU6MTYpIiwidHJ5Q2F0Y2hlciAoL3Zhci90YXNrL25vZGVfbW9kdWxlcy9ibHVlYmlyZC9qcy9yZWxlYXNlL3V0aWwuanM6MTY6MjMpIiwiUHJvbWlzZS5fc2V0dGxlUHJvbWlzZUZyb21IYW5kbGVyICgvdmFyL3Rhc2svbm9kZV9tb2R1bGVzL2JsdWViaXJkL2pzL3JlbGVhc2UvcHJvbWlzZS5qczo1MTI6MzEpIiwiUHJvbWlzZS5fc2V0dGxlUHJvbWlzZSAoL3Zhci90YXNrL25vZGVfbW9kdWxlcy9ibHVlYmlyZC9qcy9yZWxlYXNlL3Byb21pc2UuanM6NTY5OjE4KSIsIlByb21pc2UuX3NldHRsZVByb21pc2UwICgvdmFyL3Rhc2svbm9kZV9tb2R1bGVzL2JsdWViaXJkL2pzL3JlbGVhc2UvcHJvbWlzZS5qczo2MTQ6MTApIiwiUHJvbWlzZS5fc2V0dGxlUHJvbWlzZXMgKC92YXIvdGFzay9ub2RlX21vZHV
@amite
amite / ProductTable.jsx
Last active December 2, 2017 06:45
Composing Predicates
const Just = v => ({
isJust: true,
value: v
});
const Nothing = { isJust: false };
const last = xs => xs.length > 0 ? Just(xs[xs.length-1]) : Nothing;
const catMaybes = xs => xs.reduce((newList, m) => m.isJust && newList.push(m.value), []);
const flatten = () => this.reduce((newList, l) => newList.concat(l), []);
const compose = f => g => x => f(g(x));
// ...
@amite
amite / CartPage.jsx
Last active November 18, 2017 11:22
Adding Tab Body
function CartPage({ items }) {
return items ? (
<ul className="CartPage-items">
{items.map(item => (
<li key={item.id} className="CartPage-item">
<Item item={item}>
<div className="CartItem-controls">
<button className="CartItem-removeOne">&ndash;</button>
<span className="CartItem-count">{item.count}</span>
<button className="CartItem-addOne">+</button>
<?php
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* @hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<?php
/**
* Admin new order email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/admin-new-order.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@amite
amite / handleChange.js
Last active September 29, 2017 03:42
Curry Examples
const handleChange = (fieldName) => (event) => {
this.setState(fieldName, event.target.value)
}
<input type="text" onChange={handleChange('email')} ... />
@amite
amite / functional-setstate.js
Last active September 18, 2017 09:14
Immutable Updates to nested data with setState in React
// Functional setState (Recommended)
this.setState(prevState => {
const newState = {
...prevState.data,
transactions: [...data, prevState.data.transactions]
}
return { data: newState }
})
@amite
amite / actions.test.js
Created April 25, 2017 05:39
testing action creators in redux
import expect from 'expect';
import * as courseActions from './courseActions';
import * as types from './actionTypes';
import thunk from 'redux-thunk';
import nock from 'nock';
import configureMockStore from 'redux-mock-store';
// Test a sync action
describe('Course Actions', () => {