Skip to content

Instantly share code, notes, and snippets.

@balsimpson
balsimpson / getFormattedDate.js
Last active October 19, 2022 08:10
A simple function to convert a date to a human readable string
// format date with time and AM/PM
/**
* A simple function to convert a date to a human readable string
* @param date a date object or a string that can be parsed into a date object
* @returns string formatted as "D MMM YYYY, hh:mm am/pm"
*/
const getFormattedDate = (date) => {
return date.toLocaleString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true })
}
@balsimpson
balsimpson / powerWords.txt
Created September 12, 2022 14:55
A list of power words to use in your headlines for greater impact.
Abandon Negative Sentiment
Abandoned Negative Sentiment
Abandons Negative Sentiment
Abducted Negative Sentiment
Abduction Negative Sentiment
Abductions Negative Sentiment
Abhor
Abhorred Negative Sentiment
Abhorrent Negative Sentiment
Abhors
@balsimpson
balsimpson / UncommonWords.txt
Created September 12, 2022 14:53
A list of uncommon words to use in your headline to make it more interesting.
Actually
Baby
Being
Boy
Day
Dog
Down
Every
Facebook
First
@balsimpson
balsimpson / EmotionalWords.txt
Created September 12, 2022 14:52
A list of emotional words to use in headlines with positive and negative sentiment marked.
Absolutely Positive Sentiment
Admiration Positive Sentiment
Admirer Positive Sentiment
Adulation
Advice
Affordable Positive Sentiment
Agony Negative Sentiment
Almighty
Amour Positive Sentiment
Announcing
@balsimpson
balsimpson / uploadImageToCloudinary.js
Last active August 20, 2022 07:04
Upload Image to Cloudinary in a Vue Component
const uploadImage = async (event) => {
let file = event.target.files[0];
const data = await readData(file);
let formData = new FormData();
formData.append("file", file);
formData.append("upload_preset", "custom-upload");
formData.append("folder", "blog");
const response = await fetch(
@balsimpson
balsimpson / SidebarScaffold.vue
Created February 4, 2022 13:24
A Vue component for a responsive sidebar
<template>
<div class="flex h-screen">
<!-- create a sliding sidebar with tailwind -->
<div class="flex-shrink-0 hidden w-64 px-6 py-4 bg-gray-800 md:block">
<div class="flex flex-col justify-between h-full">
<div>
<!-- sidebar header -->
<slot name="sidebar_header"></slot>
<div class="flex flex-col justify-between h-full pt-20 text-white">
@balsimpson
balsimpson / AppAutocomplete.vue
Created February 4, 2022 08:21
A Vue component text input with a dropdown that filters results as you type
<template>
<div class="relative my-2">
<input
@keyup="findOption()"
v-model="optionInput"
type="text"
class="w-full px-2 py-1 border rounded-t"
placeholder="choose category"
/>
<!-- add an icon on the right -->
@balsimpson
balsimpson / CloudinaryUpload.vue
Created February 4, 2022 08:02
A Vue Component to upload images to Cloudinary
<template>
<div class="w-full py-3">
<!-- Upload images to cloudinary -->
<div class="grid grid-cols-1 gap-2 sm:grid-cols-2 md:grid-cols-3">
<div class="flex items-center justify-center w-full">
<label
class="flex flex-col items-center w-full transition-colors border-2 border-gray-300 border-dashed rounded cursor-pointer h-44 hover:bg-gray-200 "
:class="[
isUploading
@balsimpson
balsimpson / relativeTime.js
Created December 11, 2021 14:10
A simple function to find the relative time
function timeDifference(current, previous) {
let msPerMinute = 60 * 1000;
let msPerHour = msPerMinute * 60;
let msPerDay = msPerHour * 24;
let msPerMonth = msPerDay * 30;
let msPerYear = msPerDay * 365;
let elapsed = current - previous;
@balsimpson
balsimpson / SearchBar.vue
Created October 13, 2021 13:43
A search Bar Vue Component
<template>
<div class="relative max-w-md mx-auto">
<form @submit.prevent="clickHandler">
<input
v-model="query"
type="text"
:placeholder="placeholder"
class="w-full px-3 py-3 font-bold text-red-500 border-2 rounded-lg focus:outline-none focus:ring-2 focus:ring-red-500"
/>
<div class="absolute inset-y-0 right-0">