Skip to content

Instantly share code, notes, and snippets.

@DeflateAwning
DeflateAwning / np_columns_to_polars_benchmark.py
Created March 25, 2025 21:05
Benchmark the conversion of Numpy to Polars vs. Numpy to Pandas to Polars
"""
Related to https://github.com/pydata/xarray/issues/10135
Result (in VS Code debugger):
Shape | NumPyPolars | NumPyPandasPolars
-----------------------------------------------------------------
10,000 x 10 | 0.003997 s | 0.033097 s
10,000 x 200 | 0.002424 s | 0.050915 s
100,000 x 10 | 0.000278 s | 0.021541 s
@DeflateAwning
DeflateAwning / np_to_polars_memory.py
Last active March 25, 2025 20:56
Benchmark Numpy to Polars
import numpy as np
import pandas as pd
import polars as pl
import time
from memory_profiler import memory_usage
# Array shapes to test
shapes = [
(10_000, 10),
(10_000, 200),
@DeflateAwning
DeflateAwning / Agilent_DSOX3012A_Scope_Repair.md
Last active December 12, 2024 05:21
Repair Agilent DSO-X 3012A Oscilloscope (Busted Power Supply)
@DeflateAwning
DeflateAwning / RP2040-Zero with MicroPython Setup Guide.md
Last active January 7, 2025 01:01
RP2040-Zero with MicroPython Setup Guide

RP2040-Zero with MicroPython Setup Guide

  1. Install VS Code.
  2. In VS Code, install the "MicroPico" extension.
  3. Download the MicroPython firmware from: https://micropython.org/download/RPI_PICO/RPI_PICO-latest.uf2
  4. Connect the RP2040-Zero to the computer. If a USB Drive doesn't appear, press: reset-down, boot-down, reset-up, boot-up.
  5. Open the USB Drive that appeared. Copy on the MicroPython uf2 file. Wait 30 seconds.
  6. Use Device Manager (or SerialTest) to see that a new USB Serial Device appeared.
  7. In VS Code with MicroPython, see that it's connected (see the status bar at the very bottom).
  8. Optional: Run pip install micropython-rp2-rpi_pico-stubs to install Python type checking helpers.
@DeflateAwning
DeflateAwning / PCB_Ordering_Checklist.md
Last active January 6, 2025 01:24
A KiCAD (or generic) PCB ordering checklist

PCB Ordering Checklist

Check list is tailored for KiCAD.

Main Checklist

  1. Pages are "US Letter" if printing in Canada/US
  2. Print PCB on paper to check footprints
  3. Check STM32 pin assignments with STM32CubeIDE, if applicable.
  4. Revision and date?
  5. Organization logo?
@DeflateAwning
DeflateAwning / polars_upgrade_regex_magic.md
Last active February 21, 2025 00:51
Polars Upgrade Regex Magic

Sometimes the Python Polars library upgrades.

The following are some codebase migrations I've used.

Pre-v0.20.x

  1. Find+Replace: pl.Utf8 -> pl.String

v0.20.31 to v1.x

@DeflateAwning
DeflateAwning / sympy_solve_example.py
Created March 29, 2024 22:19
An example of using Sympy
from sympy import symbols, Eq, solve
# Define symbols
k1, k2, k3 = symbols('incoming_slope normal_slope outgoing_slope')
# Define the equation
equation = Eq((k1 - k2) / (1 + (k1*k2)), (k2 - k3) / (1 + (k2*k3)))
# Solve the equation for k3
solution = solve(equation, k3)
@DeflateAwning
DeflateAwning / send_keyboard_to_virtualbox.py
Created March 6, 2024 22:48
Send text to a running VirtualBox instance via the keyboard. No Guest Additions required.
# pip install virtualbox
import virtualbox
vbox = virtualbox.VirtualBox()
machine = vbox.find_machine("Ubuntu 20")
session = machine.create_session()
session.console.keyboard.put_keys("Hello, world!")
# Source: https://github.com/sethmlarson/virtualbox-python/issues/142
@DeflateAwning
DeflateAwning / Set GitHub Page Title to the Filename.user.js
Created January 26, 2024 22:46
When browsing a GitHub project, set the <title> to the filename (instead of the whole folder path)
// ==UserScript==
// @name Set GitHub Page Title to the Filename
// @namespace https://gist.github.com/DeflateAwning
// @version v0.1
// @description When browsing a GitHub project, set the <title> to the filename and repo user/name.
// @author DeflateAwning
// @match https://github.com/*/*/blob/**
// @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant none
// ==/UserScript==
@DeflateAwning
DeflateAwning / Teams - AccountName.desktop
Created January 10, 2024 17:22
Teams for Linux - Multiple User Accounts
#!/usr/bin/env xdg-open
[Desktop Entry]
Name=Teams Account - AccountName
Exec=teams-for-linux --appTitle "Teams - AccountName" --customUserDir="/home/user/.teams-data/account_AccountName"
Terminal=false
PrefersNonDefaultGPU=false
Icon=teams-for-linux
Type=Application
# place this file in ~/Desktop and/or ~/.local/share/applications/ (to add to the start menu)