Skip to content

Instantly share code, notes, and snippets.

View pat-dill's full-sized avatar

Pat Dill pat-dill

View GitHub Profile
import { Json } from "../types/json";
import doesThrow from "../doesThrow";
import { useEffect, useState } from "react";
type Target = "_replace" | "_blank" | "_self" | "_parent" | "_top";
type Dispatch<A> = (value: A, targetOrNewTab?: Target | boolean) => void;
type SetSearchParamStateAction<S> = S | ((prevState?: S) => S);
function encodeParam(obj: Json): string {
if (typeof obj === "string" && doesThrow(JSON.parse, obj)) {
import {useEffect, useRef, useState} from "react";
const getSeconds = () => new Date().valueOf() / 1000;
const EPSILON = 0.001;
interface Spring {
prevDisplacement: number,
prevVelocity: number,
goal: number,
@pat-dill
pat-dill / getCompareFn.ts
Last active May 9, 2024 15:39
Sort by keys. Keys can be a string property name or a function that extracts a value.
type SortKey<T> = string | ((v: T) => unknown);
type SortOrder = "asc" | "desc";
type NullMode = "start" | "end";
interface SortStep<T> {
key: SortKey<T>
order?: SortOrder,
nulls?: NullMode
}
export function getCompareFn<T>(...sortKeys: (SortKey<T> | SortStep<T>)[]) {
@pat-dill
pat-dill / features.py
Last active September 9, 2023 19:17
counts switches and crossovers in railway data from overpass turbo
from dataclasses import dataclass, field
from typing import Any
@dataclass
class Feature:
type: str
id: str
@pat-dill
pat-dill / alerts.tsx
Last active April 1, 2023 11:40
Alerts overlay for React.
import {v4 as uuidv4} from "uuid";
import React, {createContext, ReactNode, useContext, useEffect, useMemo, useRef, useState} from "react";
import clsx from "clsx";
import {ClipLoader} from "react-spinners";
import {useMap, useSet} from "../utils/hooks";
interface IAlert {
id: string,
content?: ReactNode, // Content to display, can be string or custom children
@pat-dill
pat-dill / threaddump.py
Last active July 21, 2020 02:40
indexes all images from an instagram thread
from selenium import webdriver
import requests
import figa
from redis import Redis
from pprint import pp
@figa.config
class Config:
default = "config.json"
{
"number": 12,
"string": "Hello, world!",
"fruits": ["apple", "pear"],
"person": {
"name": "Zach",
"age": 20
}
}
local url_query = {arg1="val1", arg2="val2"}
local post_json = {a=1, b=2, this="is json"}
local HttpService = game:GetService("HttpService")
local options = {
Url = ("https://httpbin.org/post?%s=%s&%s=%s"):format("arg1", url_query.arg1, "arg2", url_query.arg2),
Method = "POST",
Headers = {["Content-Type"] = "application/json"},
Body = HttpService:JSONEncode(post_json)
local rgb = Color3.fromRGB
local Color = {
Red = {
[50] = rgb(255, 235, 238);
[100] = rgb(255, 205, 210);
[200] = rgb(239, 154, 154);
[300] = rgb(229, 115, 115);
[400] = rgb(239, 83, 80);
@pat-dill
pat-dill / httpservice.lua
Created June 27, 2019 19:31
Some HttpService code
local HttpService = game:GetService("HttpService")
local options = {
Url = "https://httpbin.org/post?arg=value",
Method = "POST",
Headers = {["Content-Type"] = "application/json"},
Body = HttpService:JSONEncode( {this="json"} )
}
local r = HttpService:RequestAsync(options)