Skip to content

Instantly share code, notes, and snippets.

View bskinn's full-sized avatar

Brian Skinn bskinn

View GitHub Profile
import panel as pn
script = """
<script>
function querySelectorDeep(selector, rootNode=document.body) {
const arr = []
const traverser = node => {
// 1. decline all nodes that are not elements
if(node.nodeType !== Node.ELEMENT_NODE) {
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nymous
nymous / README.md
Last active July 18, 2024 18:26
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom

@dawnmist
dawnmist / wine-doodly.md
Last active September 26, 2022 18:10
Installing Doodly with Wine/Winetricks on Linux

I have managed to get the 32bit Windows version of Doodly working in linux using wine and winetricks, and using vulkan as the renderer. This assumes that you have installed the vulkan driver packages for your video card - which is beyond the scope of this gist. I set it up with its own wine prefix, so it wasn't affecting any others. Documented here so other people can give it a try - you will need to remember to specify the path to where you downloaded the installer:

env WINEPREFIX="$HOME/wine-doodly" WINEARCH=win32 winetricks dotnet48 dxvk corefonts mf nuget 
env WINEPREFIX="$HOME/wine-doodly" WINEARCH=win32 winetricks renderer=vulkan
env WINEPREFIX="$HOME/wine-doodly" WINEARCH=win32 wine <path_to_installer>/DoodlySetup2.7.1_32bit.exe
@gvoze32
gvoze32 / ffmpeg GIF to MP4.MD
Last active July 15, 2024 08:59
Convert animated GIF to MP4 using ffmpeg in terminal.

To convert animation GIF to MP4 by ffmpeg, use the following command

ffmpeg -i animated.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video.mp4

Description

movflags – This option optimizes the structure of the MP4 file so the browser can load it as quickly as possible.

pix_fmt – MP4 videos store pixels in different formats. We include this option to specify a specific format which has maximum compatibility across all browsers.

@fnky
fnky / ANSI.md
Last active July 22, 2024 12:03
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@joeytwiddle
joeytwiddle / async-await-forEach-alternatives.md
Last active July 22, 2024 09:05
Do not use forEach with async-await

Do not use forEach with async-await

TLDR: Use for...of instead of forEach() in asynchronous code.

For legacy browsers, use for...i or [].reduce()

To execute the promises in parallel, use Promise.all([].map(...))

The problem

@CMCDragonkai
CMCDragonkai / matplotlib_interactive_mode.md
Last active December 1, 2023 05:39
Interactive Matplotlib (while in REPL) #python #matplotlib

Interactive Matplotlib (while in REPL)

Matplotlib can be used in an interactive manner either in the REPL or as part of a script. Let's assume you're using export MPLBACKEND='Qt4Agg'.

To do this you need to switch on interactive mode:

import matplotlib.pyplot as plt
plt.ion()
@pierrejoubert73
pierrejoubert73 / markdown-details-collapsible.md
Last active July 19, 2024 18:06
How to add a collapsible section in markdown.

How to add a collapsible section in markdown

1. Example

Click me

Heading

  1. Foo
  2. Bar
    • Baz
  • Qux
import os
def test_user_input(monkeypatch):
inputs = [10, 'y']
input_generator = (i for i in inputs)
monkeypatch.setattr('__builtin__.raw_input', lambda prompt: next(input_generator))
assert raw_input('how many?') == 10
assert raw_input('you sure?') == 'y'