Skip to content

Instantly share code, notes, and snippets.

@maurocen
maurocen / s3deploy.js
Last active July 5, 2020 20:44
Deploy build directory to S3 bucket using aws-cli and environment variables
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
const cmd = (command) => {
const { exec } = require('child_process');
@maurocen
maurocen / eventPromise.js
Last active July 12, 2022 17:02
Get a promise that resolves/rejects when the specified `accepted` or `rejected` events are received.
const EventEmitter = require('events');
const event = new EventEmitter();
// THIS IS THE IMPORTANT BIT
const eventPromise = (accepted, rejected, acceptMessage = '', rejectMessage = '') => new Promise((resolve, reject) => {
event.on(accepted, (...args) => {
event.removeAllListeners(accepted);
event.removeAllListeners(rejected);
@maurocen
maurocen / useDebounce.js
Created July 5, 2020 20:40
A hook to debounce events
import { useState } from 'react';
const useDebounce = () => {
const [timer, setTimer] = useState(null);
const debounce = (callback, time) => (e) => {
e.persist();
if (timer) {
clearTimeout(timer);
@maurocen
maurocen / useInputValue.js
Created July 5, 2020 20:41
A hook to handle input value and if said value has changed. Allows resetting value to initial or new value.
import { useState } from 'react';
const useInput = (initialValue = '') => {
const [value, setValue] = useState(initialValue);
const [touched, setTouched] = useState(false);
const onChange = (newValue) => {
setValue(newValue);
setTouched(true);
}
@maurocen
maurocen / neuromorphic.html
Last active March 8, 2022 00:25
Neuromorphic button
<style>
html, body {
margin: 0;
padding: 0;
}
.container {
align-items: center;
background-color: #EEEEEE;
display: flex;