Skip to content

Instantly share code, notes, and snippets.

View rdmurphy's full-sized avatar
🔴
Red pandas are the best.

Ryan Murphy rdmurphy

🔴
Red pandas are the best.
View GitHub Profile
@joshnuss
joshnuss / vite-plugin-sql.js
Last active July 10, 2024 17:20
Vite SQL plugin
import fs from 'node:fs/promises'
export function sql(url) {
return {
name: 'vite-plugin-sql',
// expose an import called 'sql:runtime'
resolveId(id) {
if (id.startsWith('sql:runtime')) {
return id
@tangentstorm
tangentstorm / sh.mjs
Last active May 20, 2024 08:49
shorthand javascript
// sh.mjs: javascript shorthand
// array helpers (apl/j/k)
export const id=x=>x
export const af=(n,x)=>Array(n).fill(x) // TODO: make this 'afl' or 'fil' (aa?)
export const ii=(n,f)=>{for(let i=0;i<n;i++)f(i)}
export const im=(n,f)=>af(n,0).map((_,i)=>f(i))
export const ia=(n,f)=>im(n,id)
export const at=(a,ixs)=>ixs.map(i=>a[i])
export const io=(xs,ys)=>ys.map([].indexOf.bind(xs))
@marvinhagemeister
marvinhagemeister / jsx-dom.html
Last active September 24, 2023 19:00
JSX DOM
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script type="module">
import { signal, effect } from "@preact/signals-core";
interface CustomStorage {
getItem(key: string): void;
setItem(key: string, value: string | null): void;
}
/**
* A version of signal() that persists and recalls its value in localStorage.
*
import { useSignal, signal, effect } from '@preact/signals';
import { useLayoutEffect, useMemo, useRef } from 'preact/hooks';
/** @template T @typedef {T extends (infer U)[] ? U : never} Items */
/** @param {{ v, k?, f }} props */
const Item = ({ v, k, f }) => f(v, k);
/**
* Like signal.value.map(fn), but doesn't re-render.
import { Context } from "https://edge.netlify.com/";
const DOMAIN = "macwright.com";
const USERS = new Map([
[
`acct:photos@macwright.com`,
{
subject: `acct:photos@${DOMAIN}`,
aliases: [],
@JoeGermuska
JoeGermuska / 00_README.md
Last active December 14, 2023 19:55
Read Census 2020 PL94-171 ("redistricting") files into Pandas DataFrames

Some quick work to facilitate reading data for the Census 2020 PL94-171 data release into Pandas dataframes.

Sample data for Providence County, RI can be downloaded from https://www.census.gov/programs-surveys/decennial-census/about/rdo/summary-files.html, as can auxiliary materials.

The file headers.py was created by parsing the SAS import scripts from the link above.

It seems as though the Census Bureau removed the sample data for Providence County, RI, against which this code was tested. You can get a copy of it from http://files.censusreporter.org/ri2018_2020Style.pl.zip

Note: The full data release is now available at https://www2.census.gov/programs-surveys/decennial/2020/data/01-Redistricting_File--PL_94-171/

@sindresorhus
sindresorhus / esm-package.md
Last active July 15, 2024 20:29
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.
@tkadlec
tkadlec / perf-diagnostics.css
Last active June 8, 2023 17:47
CSS used to highlight potential performance issues
:root {
--violation-color: red; /* used for clear issues */
--warning-color: orange; /* used for potential issues we should look into */
}
/* IMAGES */
/*
* Lazy-Loaded Images Check
* ====
@ache051
ache051 / combine_mbtiles.py
Created December 15, 2020 22:58
Combine MBTiles
#-------------------------------------------------------------------------------
# Name: combine_mbtiles.py
# Purpose: Processes multiple sqlite .mbtiles files into single file (or by level? or by degree grids?)
#
# Author: joshn. Modified by ache015
#
# Created: 18/11/2014
#
# Last Modified: 10/11/2018
#-------------------------------------------------------------------------------