Skip to content

Instantly share code, notes, and snippets.

@btnwtn
btnwtn / machine.js
Last active January 26, 2021 22:05
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: 'Create Campaign Workflow',
initial: 'processing',
context: {
// Change this to pikachu or charizard
campaignId: 'ditto',
processingStatus: 'idle',
},
states: {
processing: {
@btnwtn
btnwtn / resources.md
Last active November 6, 2018 20:44
frontend engineering resources

Web/JS-focused newsletter. Usually has really great content. No spam either, I always sign up for this on new email accounts.

There is a ton of stuff in here, pick something from the left sidebar that you don't know about and check it out. There's interesting stuff on PWAs, performance, security, etc..

Also if you go to the updates tab and select "BY YEAR". You will find the developers web blog which just has a ton of articles. A lot of it is about brand new Web APIs in coming to Chrome.

@btnwtn
btnwtn / 50.js
Last active September 18, 2019 16:09
Automat dat +50 clapping on Medium.com
(() => {
const up$ = new MouseEvent("mouseup", { bubbles: true });
const down$ = new MouseEvent("mousedown", { bubbles: true });
const node = document.querySelector(
`.js-postActionsFooter button[data-action="multivote"]`
);
let attempts = 0;
const withTracking = WrappedRoute => {
return class PageViewWrapper extends Component {
componentDidMount() {
console.log(this.props);
if (window.dataLayer) {
window.dataLayer.push({
event: "pageview or something"
});
}
@btnwtn
btnwtn / withTracking.js
Created June 19, 2017 18:10
GTM Tracking HOC
const withTracking = WrappedRoute => props => {
console.log(props);
if (window.dataLayer) {
window.dataLayer.push({
event: "pageview or something",
// https://developers.google.com/tag-manager/devguide
});
}
import React, { Component } from 'react';
const mockAPI = {
emailExists(email) {
return new Promise(resolve => setTimeout(resolve(true), 300))
}
}
const validateEmail = async email => new Promise(resolve => {
mockAPI.emailExists(email).then(exists => {
// Logs all calls to preventDefault / stopPropagation in an user-friendly way
if ( process.env.NODE_ENV !== "production" ) {
(function monkeyPatchEventMethods() {
const logEventMethodCall = (event,methodName) => {
const MinimumMeaningfulSelectors = 3; // how much meaningful items we want in log message
const target = event.target;
const selector = (function computeSelector() {
import React, { Component } from 'react'
import YouTube from 'react-youtube'
export default class Video extends Component {
constructor(props) {
super(props)
this.state = {
progress: 0,
duration: 0,
player: null,