Skip to content

Instantly share code, notes, and snippets.

<script lang="ts">
import { applyAction, enhance } from '$app/forms';
import { page } from '$app/stores';
import { RoofGraphic } from '$lib/graphics';
import { fade } from 'svelte/transition';
import type { ActionUpdate, Result } from './form.svelte.d';
import Button from './button.svelte';
import Field from './field.svelte';
import { EmailIcon, MessageIcon, NameIcon, PhoneIcon } from './icons';
@jonshipman
jonshipman / resize.svelte
Last active February 4, 2024 22:24
Media size dispatcher
<script lang="ts">
import { createEventDispatcher } from 'svelte';
import { ResizeStore } from './window-events';
import type { ResizeDetail } from './resize.svelte.d';
export let debounce = 0;
export let mobile: boolean | null = null;
const dispatch = createEventDispatcher<{ resize: ResizeDetail }>();
let timeout: ReturnType<typeof setTimeout>;
@jonshipman
jonshipman / custom_post_type_boilerplate.php
Created October 27, 2023 16:58
custom_post_type_boilerplate.php
<?php
/**
* Your custom post type
*
* @package Pacakge_Name
*/
/**
* Post Type.
*/
@jonshipman
jonshipman / docker-compose.yml
Last active November 11, 2023 13:00
Nginx Reverse Proxy with Acme Companion
version: '3.9'
services:
reverse-proxy:
container_name: 'reverse-proxy'
restart: 'always'
image: 'nginxproxy/nginx-proxy'
ports:
- 80:80
- 443:443
volumes:
@jonshipman
jonshipman / styles.csv
Created May 5, 2023 20:03
Stable Diffusion Artist Styles
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 5 columns, instead of 3 in line 1.
____Artists____,,,,
Aaron Horkey,"style of Aaron Horkey",""
Abbott Handerson Thayer,"style of Abbott Handerson Thayer",""
Abigail Larson,"style of Abigail Larson",""
Adam Hughes,"style of Adam Hughes",""
Adrian Ghenie,"style of Adrian Ghenie",""
Adrian Tomine,"style of Adrian Tomine",""
Adrianus Eversen,"style of Adrianus Eversen",""
Agnes Cecile,"style of Agnes Cecile",""
Agostino Arrivabene,"style of Agostino Arrivabene",""
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jonshipman
jonshipman / map-usa.js
Created December 14, 2022 15:38
USA Contiguous GeoJSON Formatted features.
/**
* Simple map of the USA.
* Merged from johan/world.geo.json countries\USA folder.
*
* @see https://github.com/johan/world.geo.json
*/
const MapPolygon = {
type: 'FeatureCollection',
features: [
@jonshipman
jonshipman / sudo.ps1
Created December 9, 2022 19:43
sudo implementation for powershell
# Place this function in you $Env:Profile
# Has worked with most of what I've thrown at it.
# E.g. `sudo cmd.exe /C mklink /J C:\Test C:\Windows`
function Sudo {
[string] $Location = (Get-Location)
$NewArgs = @()
For ( $i = 0; $i -Lt $args.Length; $i++) {
$NewItem = "$($args[$i])".Replace(" ","`` ").Replace("'","``'").Replace('"','``"')
@jonshipman
jonshipman / Mongoose Async Virtuals.md
Created October 31, 2022 20:33
A no-plugins approach to implementing virtuals that use a promise.

Mongoose Async Virtuals

Demo of Async Virtuals in Monoose 6.2.7. Using no plugins, it's three steps.

  1. Declare an instance method (it's loadChildren in the example). The instance method should store the results into a this._variable (variable name is not relevant, just be sure not to use one that's already in use).

  2. In schema.post('find'), run an Promise that fires your instance method in a loop using await Promise.all().

NodeJS static class override example

Mongoose model replacment for .watch()

Just a gist from a larger project. Worker.runonce is a function that will ask the primary process for permission to proceed. The primary process will track what activites are run where (through the unique key) and pass down the approved pid. If the worker's pid doesn't match what prime messages out, it will not run the callback.

The purpose of overriding watch is that having so many watch actions on the prime process was causing OOM Errors in Heroku. Model.watch().on() can be called as normal.