Skip to content

Instantly share code, notes, and snippets.

View michaelbollin's full-sized avatar

Michael Bollin michaelbollin

View GitHub Profile
@michaelbollin
michaelbollin / useConsoleOverride.ts
Last active October 15, 2025 23:48
Override console.log for showing the output on-page
export function useConsoleOverride() {
const originalLog = useRef(console.log);
const [output, setOutput] = useState("");
const override = () => {
originalLog.current = console.log;
console.log = (...args) => {
originalLog.current.apply(console, args);
const formattedArgs = args.map(arg =>
@michaelbollin
michaelbollin / client.js
Last active October 31, 2024 00:21
Fetching Shopify pages with specific template name
import { shopifyApi, LATEST_API_VERSION, Session } from '@shopify/shopify-api';
const shopifyConfig = {
apiKey: process.env.SHOPIFY_API_KEY,
apiSecretKey: process.env.SHOPIFY_API_SECRET,
scopes: ['read_products', 'write_products'],
hostName: '127.0.0.1:3000',
apiVersion: LATEST_API_VERSION,
isPrivateApp: true,
isEmbeddedApp: false,
@michaelbollin
michaelbollin / graphql-wrapper-wordpress-react.ts
Created October 31, 2024 00:10
Api wrapper function for wordpress-based React site
const API_URL = process.env.WORDPRESS_API_URL;
async function fetchAPI(query = "", { variables }: Record<string, any> = {}) {
if (!API_URL) {
console.error('WORDPRESS_API_URL is not defined');
throw new Error('WORDPRESS_API_URL is not defined');
}
const headers = { "Content-Type": "application/json" };
<?php
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
/**
* Assigns an attachment URL to a post, setting it as the featured image.
*
* @param int $post_id The ID of the post.
@michaelbollin
michaelbollin / node-upload-file-to-bunny.ts
Last active October 22, 2024 11:02
Upload file to bunny.net with Node.js
import { File } from 'formidable';
import fs from 'fs';
import path from 'path';
const BUNNY_API_URL = process.env.BUNNY_API_URL || '';
const BUNNY_API_KEY = process.env.BUNNY_API_KEY || '';
const BUNNY_STORAGE_ZONE_NAME = process.env.BUNNY_STORAGE_ZONE_NAME || '';
const BUNNY_PULL_ZONE = process.env.BUNNY_PULL_ZONE || '';
export const uploadToBunny = async (file: File): Promise<string> => {
@michaelbollin
michaelbollin / run-chromium-on-vercel-puppeteer-core.ts
Last active October 22, 2024 11:02
NextJS with Chromium, Puppeteer, that works on Vercel
import puppeteer from 'puppeteer-core';
import chrome from '@sparticuz/chromium';
const production = process.env.NODE_ENV === 'production';
export default async function handler(req, res) {
try {
const browser = await puppeteer.launch(
production ? {
args: chrome.args,