Skip to content

Instantly share code, notes, and snippets.

View stuaxo's full-sized avatar
💭
 

Stuart Axon stuaxo

💭
 
View GitHub Profile
@stuaxo
stuaxo / sys_path_via_dotenv.py
Created February 3, 2023 12:34
Update sys.path if PYTHONPATH is changed by dotenv
def update_paths():
import os
import sys
import dotenv
dotenv.load_dotenv(override=True)
new_paths = {*os.environ["PYTHONPATH"].split(":")} - set(sys.path)
sys.path.extend(new_paths)
@stuaxo
stuaxo / concat_non_null_fields.py
Created April 5, 2022 12:32
Django concatenate non null fields. #snippet
# Ended up not using this, as there was only one place in the codebase.
def concat_non_null_fields(fields, seperator):
"""
Build a case statement expression to concatenate the supplied fields where isnull is False.
:param fields: List of fields to concatenate.
:param seperator: Seperator to use between fields.
:return: Case statement expression.
@stuaxo
stuaxo / 70-snap.core.rules.d
Created August 31, 2021 17:06
70-snap.core.rules.d
# This file is automatically generated.
# Concatenation of all ModemManager udev rules
# do not edit this file, it will be overwritten on update
ACTION!="add|change|move", GOTO="mm_cinterion_port_types_end"
SUBSYSTEM!="tty", GOTO="mm_cinterion_port_types_end"
ENV{ID_VENDOR_ID}!="1e2d", GOTO="mm_cinterion_port_types_end"
SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="?*", ENV{.MM_USBIFNUM}="$attr{bInterfaceNumber}"
@stuaxo
stuaxo / cairo-svg-how-to-fill-and-stroke.ipynb
Last active March 24, 2021 01:26
OPERATOR_SOURCE and OPERATOR_CLEAR create images in SVGs
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stuaxo
stuaxo / shoebot design notes.md
Last active March 14, 2021 19:13
Shoebot design notes.
@stuaxo
stuaxo / aborting_transaction.py
Last active January 12, 2021 17:41
Aborting transaction context manager.
"""
Aborting transaction context manager, useful for when prototyping on Django.
"""
from contextlib import contextmanager
from django.db import transaction
class AbortTransaction(Exception):
pass
@contextmanager
@stuaxo
stuaxo / cairo-test-output-windows-vs-2017.txt
Last active November 19, 2020 19:00
Cairo tests - Windows x64 - (under meson dist) - VS2017
The Meson build system
Version: 0.55.3
Source dir: C:\Users\Stu\Desktop\projects\external\cairo\build\meson-private\dist-unpack\cairo-1.17.3
Build dir: C:\Users\Stu\Desktop\projects\external\cairo\build\meson-private\dist-build
Build type: native build
WARNING: Unknown options: "c_args, c_link_args, c_winlibs, cpp_args, cpp_eh, cpp_link_args, cpp_rtti, cpp_std, cpp_winlibs"
The value of new options can be set with:
meson setup <builddir> --reconfigure -Dnew_option=new_value ...
Project name: cairo
Project version: 1.17.3
@stuaxo
stuaxo / csv_to_xlsx.py
Created October 12, 2020 00:16
CSV to XLSX converter with XLSXWriter
# csv_to_xlsx [filename... [filename]]
import csv
import os
import sys
import xlsxwriter
from pathlib import Path
def main(csv_filenames):
if non_files:
@stuaxo
stuaxo / build-pycairo.sh
Created August 13, 2020 16:12
Script to attempt to build pycairo
set -ex
cd pycairo
PATH=$PATH:/c/ProgramData/chocolatey/bin:/c/ProgramData/chocolatey/tools
export CAIRO_VERSION=1.17.2
mkdir -p builds
function do_builds() {
bash -c .travis/runPyCairox64.sh
@stuaxo
stuaxo / class_repr.py
Created July 22, 2020 22:05
Python class repr that outputs class members.
def class_repr(self):
"""
Default class repr that outputs the content of a class.
Usage:
>>> class A:
... __repr__ = class_repr
...