Skip to content

Instantly share code, notes, and snippets.

View andymagill's full-sized avatar
👀
Looking for Opportunities

Andrew Magill andymagill

👀
Looking for Opportunities
View GitHub Profile
@andymagill
andymagill / Example JS class
Last active May 24, 2023 20:23
Simple JS class for copiepasta
// Example Class
class Example {
// properties
// methods
constructor() {
@andymagill
andymagill / Taleo Injector
Created February 8, 2024 14:08
For a consistent navigation and branding, this script loads content, styles and dependencies from one website and injects them into a 3rd party service platform.
// Taleo brandfile external JS
class Injector {
site_url;
style_paths;
script_paths;
script_paths_loaded;
scripts_inited;
@andymagill
andymagill / middleware.ts
Created June 14, 2024 13:04
Next.JS TypeScript CSP middleware - broken
import { NextRequest, NextResponse } from 'next/server';
export function middleware(request: NextRequest) {
const nonce = Buffer.from(crypto.randomUUID()).toString('base64');
const cspHeader = `
default-src 'self';
script-src 'self' 'nonce-${nonce}' 'strict-dynamic';
style-src 'self' 'nonce-${nonce}';
img-src 'self' blob: data:;
font-src 'self';
@andymagill
andymagill / setup.cjs
Created August 27, 2024 01:37
Create Project Skeleton in NODE.js
const fs = require('fs');
const path = require('path');
const directories = [
'src/lib/components',
'src/lib/stores',
'src/lib/utils',
'src/routes/history',
'src/routes/reports',
'static'
@andymagill
andymagill / jotform-extract.js
Created February 20, 2025 17:53
Extract Product data from Jotform
function extractProductData() {
const products = [];
const productItems = document.querySelectorAll('.form-product-item');
productItems.forEach(item => {
const productId = item.getAttribute('pid');
const name = item.querySelector('.form-product-name')?.textContent?.trim() || ''; // Adjust selector. Use ? to avoid errors if element is missing.
const description = item.querySelector('.form-product-description')?.textContent?.trim() || ''; // Adjust selector.
const price = item.querySelector('.form-product-detail span span')?.textContent?.trim() || ''; // Adjust selector.
const image = item.querySelector('.image_area img')?.src || ''; // Adjust selector. Assumes image is in an <img> tag.