Skip to content

Instantly share code, notes, and snippets.

View vsajip's full-sized avatar

Vinay Sajip vsajip

View GitHub Profile
@vsajip
vsajip / push-to-someone-elses-pr.md
Created March 13, 2024 14:48 — forked from wtbarnes/push-to-someone-elses-pr.md
Brief instructions for how to modify and push to someone else's PR on github

How to Push to Someone Else's Pull Request

Let's say contributor has submitted a pull request to your (author) project (repo). They have made changes on their branch feature and have proposed to merge this into origin/master, where

origin -> https://github.com/author/repo.git

Now say you would like to make commits to their PR and push those changes. First, add their fork as a remote called

@vsajip
vsajip / example.html
Created June 30, 2023 10:52 — forked from croxton/example.html
Adds a `hx-history-preserve` attribute to preserve the initial dom state of an element's children for history (before it has been manipulated by JS).
<div id="my-unique-id" hx-history-preserve>
<p>Markup here wil be returned to it's original state on history restore.</p>
</div>
@vsajip
vsajip / htmx-metadata.js
Created June 25, 2023 05:02 — forked from croxton/htmx-metadata.js
Htmx swapping metadata
htmx.on('htmx:beforeSwap', (htmxEvent) => {
let incomingDOM = new DOMParser().parseFromString(htmxEvent.detail.xhr.response, "text/html");
// Transpose <meta> data, page-specific <link> tags and JSON-LD structured data
// Note that hx-boost automatically swaps the <title> tag
let selector = "head > meta:not([data-revision]), head *[rel=\"canonical\"], head *[rel=\"alternate\"], body script[type=\"application/ld+json\"]";
document.querySelectorAll(selector).forEach((e) => {
e.parentNode.removeChild(e);
});
incomingDOM.querySelectorAll(selector).forEach((e) => {
if (e.tagName === 'SCRIPT') {
@vsajip
vsajip / debounce.py
Created December 16, 2022 21:26 — forked from walkermatt/debounce.py
A debounce function decorator in Python similar to the one in underscore.js, tested with 2.7
from threading import Timer
def debounce(wait):
""" Decorator that will postpone a functions
execution until after wait seconds
have elapsed since the last time it was invoked. """
def decorator(fn):
def debounced(*args, **kwargs):
def call_it():
@vsajip
vsajip / msg373145.rst
Created October 22, 2022 12:36 — forked from zzzeek/msg373145.rst
asyncio support for SQLAlchemy (and Flask, and any other blocking-IO library)

This is a cross post of something I just posted on the Python bug tracker at https://bugs.python.org/msg373145.

I seem to have two cents to offer so here it is. An obscure issue in the Python bug tracker is probably not the right place for this so consider this as an early draft of something that maybe I'll talk about more elsewhere.

> This basically divides code into two islands - async and non-async

@vsajip
vsajip / log_test11.py
Created August 26, 2022 22:28 — forked from anonymous/log_test11.py
Test script showing usage of a buffering SMTP handler.
#!/usr/bin/env python
#
# Copyright 2001-2002 by Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of Vinay Sajip
# not be used in advertising or publicity pertaining to distribution
@vsajip
vsajip / Server.kt
Created June 9, 2022 15:56 — forked from Silverbaq/Server.kt
A simple socket-server written in Kotlin
package dk.im2b
import java.io.OutputStream
import java.net.ServerSocket
import java.net.Socket
import java.nio.charset.Charset
import java.util.*
import kotlin.concurrent.thread
aahed
aalii
aargh
aarti
abaca
abaci
abacs
abaft
abaka
abamp
@vsajip
vsajip / wordle-answers-alphabetical.txt
Created April 6, 2022 20:00 — forked from cfreshman/wordle-answers-alphabetical.txt
Wordle answers from source code in alphabetical order. And if you write a solver, here's a leaderboard! https://freshman.dev/wordle/#/leaderboard NYTimes version: https://gist.github.com/cfreshman/a7b776506c73284511034e63af1017ee
aback
abase
abate
abbey
abbot
abhor
abide
abled
abode
abort
@vsajip
vsajip / README.md
Created March 23, 2022 09:04 — forked from avoidik/README.md
Compile vaultwarden (ex. bitwarden_rs) on Raspberry Pi

How to build and install vaultwarden (ex. bitwarden_rs) on Raspberry Pi

Steps

Prepare prerequisites

sudo apt-get update
sudo apt-get install -y --no-install-recommends build-essential libmariadb-dev-compat libpq-dev libssl-dev pkgconf