Skip to content

Instantly share code, notes, and snippets.

View panphora's full-sized avatar
👋
Hello

David Miranda panphora

👋
Hello
View GitHub Profile
import React, { useState } from 'react';
const useEditable = (initialText) => {
const [text, setText] = useState(initialText);
const [isEditingDraft, setIsEditingDraft] = useState(false);
const [draftText, setDraftText] = useState(text);
const enableEditingDraft = () => {
setDraftText(text);
setIsEditingDraft(true);
/*
Files in directories in "ephemeral" will be deleted
when they're older than the name specified by the directory
For example:
- Files in directory "min5" won't be older than 5 minutes
- Files in directory "min15" won't be older than 15 minutes
- Files in directory "day30" won't be older than 30 days
function animateFavicon () {
const frameDelay = 10;
const angleChange = .5;
let angle = 0;
let lastFrameTime = 0;
const favicon = document.querySelector("[rel='icon']");
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const img = new Image();
@panphora
panphora / taxes.js
Last active December 2, 2023 00:45
/*
# calculate your taxes in your browser console
## Usage ##
taxes.bracket(0, 22000, .10)
taxes.bracket(22001, 89450, .12);
taxes.bracket(89451, 190750, .22);
/*
# taxes.js - calculate Federal Taxes
## Usage:
taxes.bracket(0, 22000, 0.10)
taxes.bracket(22001, 89450, 0.12);
taxes.bracket(89451, 190750, 0.22);
@panphora
panphora / polite-pop-email-platforms.js
Created April 7, 2023 18:17
How to use AJAX POST or JSONP to send subscribers to ConvertKit, Mailchimp, Mailerlite, SendFox, and EmailOctopus on the front-end
import toastNotification from "./toast-notification";
import {callEventCallbacks} from "./event-callbacks";
let emailPlatforms = [
{
urlIncludes: ".convertkit.com/forms",
subscribeFunction: addSubscriberToConvertKit
},
{
urlIncludes: ".list-manage.com/subscribe",
<style>
/* never show exit intent pop: */
.polite-pop__pop--exit-intent {
display: none !important;
}
</style>
<script>
let politeScript = document.createElement("script");
politeScript.src = "https://cdn.politepop.com/polite-pop-v1.5.0/polite-pop.min.js";
/*
DON'T ALLOW THESE USERNAMES IN YOUR APP
if you want to allow www.yourapp.com/{username}
here are the words you wouldn't want people to use
as their username
words followed by star (*) mean you don't want to
function addSubscriberToConvertKit ({firstName, email, formAction, onSuccess, onError}) {
fetch(formAction, {
method: "POST",
body: JSON.stringify({
"first_name": firstName,
"email_address": email
}),
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
function addSubscriberToMailChimp ({email, firstName, formAction, onSuccess, onError}) {
// Get url for mailchimp
let url = (formAction || "").replace('/post?', '/post-json?');
// add email and first name
url += `&EMAIL=${encodeURIComponent(email)}&FNAME=${encodeURIComponent(firstName)}`;
// Create & add post script to the DOM
let script = document.createElement('script');
script.src = url + "&c=mailchimpCallback";