Skip to content

Instantly share code, notes, and snippets.

View zettadam's full-sized avatar

Adam Ziółkowski zettadam

  • Dallas-Fort Worth, TX
View GitHub Profile
@zettadam
zettadam / CartProvider.tsx
Last active November 15, 2024 19:57
CartProvider.tsx (a React context provider and a hook for a simple shopping cart)
import * as React from "react";
interface CartItem {
description: string;
id: string;
largeImage: string;
mediumImage: string;
name: string;
price: number;
smallImage: string;
@zettadam
zettadam / groupByTimePeriod.js
Last active October 27, 2024 15:42
Partition a JS array of dated items into 'previous week', 'previous month', 'previous quarter', 'previous year' and then each consequtive year.
/**
* Partitions given array with date field (published) into period arrays.
*
* @param {Array.<Object>} items
* @returns Map<string | number, Array.<Object>>
*/
export function groupByPublishedPeriod(items) {
const o = new Map() // since key insertion order may be important
o.set('week', [])
o.set('month', [])
@zettadam
zettadam / solid-static-pages.js
Created October 19, 2024 11:58
Static pages in a Solid single-page app
// @solidjs/router; redirect to a static URL defined somewhere in a web server configuration
<Route path="/me" component={() => {
onMount(() => {
window.location.href = "https://thispage.is/about-me"
})
return null
}} />
// Nginx config; point to static files on a disk.
server {
@zettadam
zettadam / machine.js
Last active February 25, 2020 06:40
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@zettadam
zettadam / schedule-status.js
Last active February 25, 2020 06:27
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@zettadam
zettadam / textInputMachine.js
Last active November 21, 2019 19:30
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@zettadam
zettadam / searchMachine.js
Last active November 18, 2019 20:55
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions