Skip to content

Instantly share code, notes, and snippets.

View sjelfull's full-sized avatar

Fred Carlsen sjelfull

View GitHub Profile
<?
# MIT license, do whatever you want with it
#
# This is my invoice.php page which I use to make invoices that customers want,
# with their address on it and which are easily printable. I love Stripe but
# their invoices and receipts were too wild for my customers on Remote OK
#
require_once(__DIR__.'/../vendor/autoload.php');
import { GetServerSideProps } from "next";
import Head from "next/head";
import { useEffect, useRef, useState } from "react";
// I suggest to create a read-only Stripe key with access to invoices + customers for this)
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY_INVOICE_GENERATOR);
export default function InvoicePage(props) {
const invoice = props.invoice;
@sjelfull
sjelfull / removeContent.js
Created October 2, 2022 21:30 — forked from RiFi2k/removeContent.js
Cloudflare Worker Function to find and replace content on a page
addEventListener("fetch", event => {
event.respondWith(handle(event.request))
})
async function handle(request) {
// Fetch from origin server.
let response = await fetch(request)
// Make sure we only modify text, not images.
let type = response.headers.get("Content-Type") || ""
@sjelfull
sjelfull / index.js
Last active August 25, 2022 13:36 — forked from zkat/index.js
npx is cool
#!/usr/bin/env node
const isNpx = process.argv.some((segment) => segment.includes('_npx') || segment.includes('npx'))
console.log('yay gist');
console.log(process.argv, process.argv0);
console.log(`${isNpx ? 'likely npx' : 'not likely to be npx'}`)
console.log(process.env)
console.log(['env._ ends with npx', process.env._.endsWith('/npx')])
@sjelfull
sjelfull / geolocation.ts
Created April 26, 2022 07:00
Netlify Edge Functions: Geolocation example
import type { Context } from "netlify:edge";
import {
Cookie,
setCookie,
} from "https://deno.land/std@0.78.0/http/cookie.ts";
import { CookieJar } from "https://deno.land/x/cookies/mod.ts";
let bots = [
// generic
'bot', // googlebot, bingbot, telegrambot, twitterbot, yandexbot, etc.
@sjelfull
sjelfull / .htaccess
Created January 25, 2019 09:21 — forked from ludo237/.htaccess
The ultimate .htaccess file. Please feel free to fork it, edit it and let me know what do you think about it.
# Apache configuration file
# httpd.apache.org/docs/2.2/mod/quickreference.html
# Note .htaccess files are an overhead, this logic should be in your Apache
# config if possible: httpd.apache.org/docs/2.2/howto/htaccess.html
# Techniques in here adapted from all over, including:
# Kroc Camen: camendesign.com/.htaccess
# perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/
# Sample .htaccess file of CMS MODx: modxcms.com
# This is the free sample of .htaccess from 6GO s.r.l.
# @author Claudio Ludovico Panetta (@Ludo237)
@sjelfull
sjelfull / _lazyFocusImager.twig
Created April 6, 2017 12:51 — forked from hendrikeng/_lazyFocusImager.twig
Twig/Craft macro for lazy responsive images/bgimages with Imager and Focuspoint
{#
// lazyLoaded Image/bgImages, optimized with Imager and Focuspoint
---------------------------------------------------------------------------
https://nystudio107.com/blog/creating-optimized-images-in-craft-cms
https://github.com/aelvan/Imager-Craft
https://github.com/smcyr/Craft-FocusPoint
for the bgImage intrinsic ratio classname creation check:
https://github.com/inuitcss/inuitcss/blob/develop/objects/_objects.ratio.scss
@sjelfull
sjelfull / pane.js
Created September 25, 2020 07:34 — forked from runeb/pane.js
Custom control over Desk pane menu items based on user group membership
import React, {
useEffect, useState
} from 'react'
import DefaultPane from '@sanity/components/lib/panes/DefaultPane'
import client from 'part:@sanity/base/client'
const CustomPane = (props) => {
const [groups, setGroups] = useState([])
useEffect(() => {
import * as React from "react";
import { useMousePosition } from "~/hooks/useMousePosition";
/** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */
export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) {
const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {};
const [mouseX, mouseY] = useMousePosition();
const positions = { x, y, h, w, mouseX, mouseY };
return (
<div
@sjelfull
sjelfull / php-pools.md
Created August 25, 2020 21:13 — forked from holmberd/php-pools.md
Adjusting child processes for PHP-FPM (Nginx)

Adjusting child processes for PHP-FPM (Nginx)

When setting these options consider the following:

  • How long is your average request?
  • What is the maximum number of simultaneous visitors the site(s) get?
  • How much memory on average does each child process consume?

Determine if the max_children limit has been reached.

  • sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log