Skip to content

Instantly share code, notes, and snippets.

View jacoblapworth's full-sized avatar
🌈

J jacoblapworth

🌈
View GitHub Profile
@brettohland
brettohland / 1.0 FormatStyle in Excruciating Detail.md
Last active April 16, 2025 17:37
FormatStyle in Excruciating Detail
@Purpzie
Purpzie / update-lockfile.yml
Last active May 6, 2023 13:22
Action to update pnpm-lock.yaml when Dependabot opens a PR. Be warned that this may cause lots of merge conflicts.
# https://github.com/dependabot/dependabot-core/issues/1736
name: Dependabot
on: pull_request_target
permissions: read-all
jobs:
update-lockfile:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
permissions:
pull-requests: write
@sindresorhus
sindresorhus / esm-package.md
Last active April 25, 2025 07:50
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@GuyARoss
GuyARoss / main.js
Created August 9, 2020 08:22
stripe noise thing
import {_ as e, L as t} from "./index-4deec983.js";
import {a as n, C as i} from "./Controller-26bd1e9e.js";
import {S as s} from "./ScrollObserver-d0732a2c.js";
import {F as o} from "./index-bee741e4.js";
class r {
constructor(e, t, n, i=!1) {
const s = this
, o = -1 !== document.location.search.toLowerCase().indexOf("debug=webgl");
s.canvas = e,
s.gl = s.canvas.getContext("webgl", {
@neilsmithdesign
neilsmithdesign / swift-ui-protocol-view-models.swift
Last active June 18, 2024 15:24
SwiftUI views with protocol interfaces to view models.
import SwiftUI
/// View model protocol
protocol ViewModel: ObservableObject {
var count: Int { get }
func increase()
}
/// Concrete implementation
class MyViewModel: ViewModel {
@alexjlockwood
alexjlockwood / delete-unused-component.ts
Last active November 24, 2021 21:01
Deletes the selected component if it is private and unused in the file.
if (figma.currentPage.selection.length !== 1) {
figma.notify("🚫 Select a component");
return;
}
const [componentNode] = figma.currentPage.selection;
if (componentNode.type !== "COMPONENT") {
figma.notify("🚫 Select a component");
return;
}
@alexjlockwood
alexjlockwood / flatten-icons.ts
Last active September 12, 2023 12:49
Flattens all components in a Figma file. Note that this script assumes that (1) every component in the file is an icon, (2) each icon contains a single color, and (3) the icons don't use masks. The `figma.flatten` function may not work as you expect if one of these conditions aren't met.
// Create a list of all component nodes in the Figma file.
const componentNodes = figma.root.children.flatMap(pageNode => {
return pageNode.findAll(node => node.type === 'COMPONENT');
}) as readonly ComponentNode[];
// Create a list of component nodes that have more than one child node.
const unflattenedComponentNodes = componentNodes.filter(componentNode => {
const childrenNodes = componentNode.findAll(() => true);
return childrenNodes.length > 1;
});
@alexjlockwood
alexjlockwood / generate-style-descriptions.ts
Last active September 12, 2023 12:54
Generates style descriptions for each color style in the current Figma file.
// Get the list of color styles in the current Figma file.
const colorStyles = figma.getLocalPaintStyles();
const updatedColorStyles = colorStyles.filter(style => {
const { paints } = style;
if (paints.length !== 1) {
// Skip styles containing multiple colors.
return false;
}
const [paint] = paints;
@fredrikbergqvist
fredrikbergqvist / Rss.ts
Created November 29, 2019 15:21
How to create an RSS feed for next.js
import React from "react";
import { NextPageContext } from "next";
const blogPostsRssXml = (blogPosts: IBlogPost[]) => {
let latestPostDate: string = "";
let rssItemsXml = "";
blogPosts.forEach(post => {
const postDate = Date.parse(post.createdAt);
if (!latestPostDate || postDate > Date.parse(latestPostDate)) {
latestPostDate = post.createdAt;
@jonkemp
jonkemp / do-not-use-switch.md
Last active April 10, 2024 14:44
'Don’t use switch' excerpted from 'Programming JavaScript Applications' by Eric Elliott, https://www.oreilly.com/library/view/programming-javascript-applications/9781491950289/

Don't Use switch

JavaScript has pretty normal control-flow statements that use blocks delineated by curly braces. There is an exception to this: the switch ... case statement. The strange thing about switch ... case is that you must include the keyword break at the end of each case to prevent control from falling through to the next case. Fall through is a trick that allows you to let more than one case be executed. Control will fall through automatically to the next case unless you explicitly tell it not to with break. However, like the optional semicolons and curly braces, it's possible to forget break when you really should have used it. When that happens, the bug is difficult to find because the code looks correct. For that reason, the break statement should never be left off of a case, even by design.

With that said, JavaScript has an elegant object-literal syntax and first-class functions, which makes it simple to create a keyed method lookup. The object you create for your method lookup is call