Skip to content

Instantly share code, notes, and snippets.

View mike-at-redspace's full-sized avatar
🎧

Mike Vardy mike-at-redspace

🎧
View GitHub Profile
import React from "react"
import { Swiper, SwiperSlide } from "swiper/react"
import useSWR from "swr"
const fetcher = (url) =>
fetch(url, {
headers: {
Authorization: `Bearer YOUR_JWT_TOKEN`
}
}).then((res) => res.json())
@mike-at-redspace
mike-at-redspace / devices.md
Last active October 29, 2023 11:23
Common Devices by Viewport Ranges

Tiny Mobile (0-413px):

  • iPhone 5, iPhone 5c, iPhone 5s
  • iPhone 6, iPhone 6s, iPhone 7, iPhone 8, iPhone SE (2020), iPhone SE (2022)
  • iPhone 12 mini, iPhone 13 mini
  • iPhone 12, iPhone 12 Pro, iPhone 13, iPhone 13 Pro, iPhone 14, iPhone 14 Pro, iPhone 15, iPhone 15 Pro
  • iPhone 11 Pro, iPhone X
  • Samsung Galaxy S21 (Dynamic AMOLED 2X, 6.2 inches, 1080 x 2400) Portrait
  • Google Pixel (AMOLED, 5 inches, 1080 x 1920) Portrait
  • Sony Xperia 1 III (OLED, 6.5 inches, 1644 x 3840) Portrait
@mike-at-redspace
mike-at-redspace / usePageTransition.js
Created September 19, 2023 03:02
usePageTransition
function usePageTransition({
beforeChange,
afterChange,
done,
}) {
const startResolverRef = useRef(null);
const dataRef = useRef(null);
const transitionRef = useRef(null);
useLayoutEffect(() => {
@mike-at-redspace
mike-at-redspace / serverResponseTest.js
Last active August 15, 2023 16:11
Node Server Response testing
const timestamp = getCurrentTimestamp()
const startTime = new Date()
try {
const { status, headers } = await axios.get(site)
const { date, trace_id: traceId } = headers
const responseTime = new Date() - startTime
const log = `${timestamp},${date},${status},${site},${responseTime}ms,${traceId},${headers['cache-control']}\n`
await fs.appendFile(logFilePath, log)
console.log(`${timestamp}: ${site} - ${responseTime}ms`)
} catch (error) {
@mike-at-redspace
mike-at-redspace / App.js
Created August 11, 2023 07:32
Ink/Pastel Test Runner
import { useState, useEffect } from 'react';
import { render } from 'ink';
import inquirer from 'inquirer';
import fs from 'fs';
import path from 'path';
import TestRunner from './TestRunner';
const App = () => {
const [testPackages, setTestPackages] = useState([]);
@mike-at-redspace
mike-at-redspace / useResponsiveImage.js
Created August 10, 2023 07:12
DynamicPicture - useResponsiveImage
/**
* React hook to get responsive image dimensions
*
* DynamicPicture could use the height and width from sources[0] as initial dimensions (SSR)??
*
* @param {string} imageUrl - Image src url
* @param {object} initialDimensions - Initial dimensions for SSR
* @returns {{dimensions: {width: number, height: number}, imageRef}} - Image dimensions and ref
*/
const useResponsiveImage = (imageUrl, initialDimensions) => {
@mike-at-redspace
mike-at-redspace / index.js
Last active August 5, 2023 08:48
Website Speed Test Github Action
// webpagetest-action/index.js
const core = require('@actions/core');
const webpagetest = require('webpagetest');
async function run() {
try {
const domains = core.getInput('domains');
const apiKey = core.getInput('key');
@mike-at-redspace
mike-at-redspace / collectData.js
Last active July 29, 2023 10:15
Client-side scrape Cast from IMDB
// https://www.imdb.com/title/tt1865740/fullcredits
const collectData = () => {
try {
const data = { cast: [], crew: [] };
const fullCredits = document.getElementById('fullcredits_content');
for (const child of fullCredits.children) {
if (child.classList.contains('simpleCreditsTable')) {
@mike-at-redspace
mike-at-redspace / getCriticalCSS.js
Last active July 21, 2023 12:53
Grab above the fold css
/**
* Get critical CSS and class names for elements matching a selector
*/
function getCriticalCSS(selector) {
try {
const elements = document.querySelectorAll(selector);
const classNames = new Set();
import React from 'react';
import styled from '@emotion/styled';
const Loader = styled.div`
position: relative;
`;
const Flex = styled.div`
display: flex;
flex-wrap: nowrap;