Skip to content

Instantly share code, notes, and snippets.

View JPrisk's full-sized avatar
🎧

Joe Prisk JPrisk

🎧
View GitHub Profile
@JPrisk
JPrisk / gist:436c93df4324629b843313f0b6b1d1a4
Created June 10, 2024 01:29
Extract Headings from AST
export type HeadingType = {
id: string;
depth: number;
label: string;
};
export function extractHeadings(content: any): HeadingType[] {
const headings: HeadingType[] = [];
for (const parent of content) {
import {
isSameDay,
isSameMonth,
format,
} from 'date-fns';
const evaluateDateRange = (
start: Date,
end: Date
): [string] | [string, string] => {
import { useState, useEffect } from 'react';
export function usePrefersReducedMotion() {
const [prefersReducedMotion, setPrefersReducedMotion] = useState(false);
useEffect(() => {
if (!window.matchMedia) {
setPrefersReducedMotion(false);
return;
}
/**
* An alternative to `Object.keys()` that avoids type widening.
*
* @example
* Object.keys({ foo: 1, bar: 2 }) // string[]
* typedKeys({ foo: 1, bar: 2 }) // ("foo" | "bar")[]
*/
export function typedKeys<T>(obj: T) {
return Object.keys(obj) as Array<keyof T>;
}
for file in directory
do
SUBSTR=$(echo $file | cut -d' ' -f 1)
SUBSTR="${SUBSTR}.csv"
mv -v "${file}" $SUBSTR
done
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<folders>
<folder>
<title>SCP</title>
<snippets>
<snippet>
<title>scp from server</title>
<content>scp your_username@remotehost.edu:foobar.txt /local/dir</content>
</snippet>
<snippet>
{
"Scaffold Sanity Schema": {
"prefix": "sanity schema",
"body": [
"export default {",
" name: '${1:${TM_FILENAME_BASE}}',",
" title: '${2:${TM_FILENAME_BASE/(^[a-zA-Z])/${1:/upcase}/}}',",
" type: 'document',",
" fields: [",
" $0",
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid