Skip to content

Instantly share code, notes, and snippets.

View portedison's full-sized avatar

Piet van Leeuwen portedison

  • Ōtautahi, Aotearoa
View GitHub Profile
@portedison
portedison / PageTransition.tsx
Last active August 31, 2024 06:18
PageTransition
// This is an example of a 'curtain' page transition for nextjs app router
// when hijacking the <Link /> to set valio's pageTransitionState.requested = href;
// I start off a transition process, switching out the the page when the curtain is closed
// I quite like the way each pass resolves the value from mapCurtain01Props, feels tidy.
'use client';
import { animated, easings, useSpring } from '@react-spring/web';
import { ReactNode, useEffect, useRef } from 'react';
// This is an example of a simple react component on one of my sites,
// this component uses chart.js, typescript (generated from wagtail/django schema)
import {
CategoryScale,
Chart as ChartJS,
LineElement,
LinearScale,
PointElement,
Tooltip,
@portedison
portedison / bru~tasks.py
Last active August 29, 2024 04:25
bru / textures
# This is an example of a fabric texture (for 3d models) download client I created for a Python / Django site,
# 1. when a user requests a texture download, it creates a task using Celery,
# 2. this task creates a RequestTexture item in the database
# 3. if the textures have never been requested before -
# it retrieves the texture images (presigned files that expire) from an external bucket
# 4. once I have selected and pulled them to a temp/ folder I zip them up (with spec sheet pdf)
# 5. optionally (on the server, or locally if USE_AWS_S3_MEDIA is set) I push them onto our bucket
# 6. lastly, I send an email to the download view, which triggers an automatic download
@current_app.task(
@portedison
portedison / dynamics~abstractions.py
Last active August 23, 2024 04:33
dynamics / abstractions
# This is an example of some mixins I created for a Python / Django cart,
# these mixins ca be applied like so -
# - Cart(AbstractItemCollection, DynamicsPriceValidatedMixin):
# - CartLineItem(AbstractLineItem, DynamicsPriceMixin):
#
# The cart required unique prices per user on selected items, these prices
# can update at any time, so I revalidate the items -
# - when hitting the payment page
# - when we call get_cart / get_checkout (not is_order)
# - a. last_price_revalidation is greater than