Skip to content

Instantly share code, notes, and snippets.

View stylerhall's full-sized avatar
🌌

Seth Hall stylerhall

🌌
View GitHub Profile
@laundmo
laundmo / ascii-table.py
Last active May 27, 2024 21:42
simple pretty print for tables
# This code is available under the MIT license: https://opensource.org/licenses/MIT
#
# 2022-07-29 Added from_dict helper, textwrapping, max_width, and typehinted to Sequence instead of list.
from itertools import zip_longest
import textwrap
from typing import Callable, List, Optional, Sequence
def text_width(text: str) -> int:
@laundmo
laundmo / to_from_dataclass.py
Created February 15, 2022 15:54
very basic roundtrip dataclass to json-serializeable dict using converters per exact type
# I often find myself wanting a easy way to define custom converters for
# converting dataclasses to and from dicts, but don't want to import
# another dependency (dataclass_factory). In this example i'm converting datetimes.
# published as MIT license: https://opensource.org/licenses/MIT
from dataclasses import dataclass, fields
from datetime import datetime
from typing import List
@laundmo
laundmo / lerp.py
Last active September 5, 2024 10:38
lerp, inverse lerp and remap in python
def lerp(a: float, b: float, t: float) -> float:
"""Linear interpolate on the scale given by a to b, using t as the point on that scale.
Examples
--------
50 == lerp(0, 100, 0.5)
4.2 == lerp(1, 5, 0.8)
"""
return (1 - t) * a + t * b
@jtmoon79
jtmoon79 / python-embedded-for-Win10.md
Last active November 5, 2024 20:33
fully configuring embedded Python on Windows 10

Update: use PowerShell script PythonEmbed4Win.ps1.

The instructions in this gist have some subtle problems and this gist will not be updated.

About


@rondreas
rondreas / unreal_menu.py
Created April 1, 2021 08:08
Example of extending a menu in Unreal using Python
"""
Example of extending a menu in Unreal using Python
"""
import unreal
def main():
@laundmo
laundmo / private.py
Last active March 8, 2023 00:36
Challenge where i tried to make something in python inaccessible, only edit the evaluate method. Rules at the bottom of the file.
class Private:
def __setattr__(self, name, value):
raise RuntimeError("Attribute setting disabled.")
def __call__(self, f):
super().__setattr__("f_code", f.__code__)
def wrapper(*args, **kwargs):
f.__code__ = self.f_code
if self.code == __import__("inspect").currentframe().f_back.f_code:
@laundmo
laundmo / traverse.py
Last active March 8, 2023 00:56
Recursively get values from a dict/list structure by either key or value
"""
Copyright 2020
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
@krzemienski
krzemienski / logging_subprocess.py
Created February 24, 2020 18:47 — forked from jaketame/logging_subprocess.py
Python subprocess logging to logger from stdout/stderr
#!/usr/local/bin/python3
import logging, select, subprocess
LOG_FILE = "test.log"
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO,filename=LOG_FILE,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
def logging_call(popenargs, **kwargs):
process = subprocess.Popen(popenargs, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
@theodox
theodox / UnrealQT.py
Last active February 3, 2023 02:46
Delegates UnrealEd draw ticks to a PySide2 Application, allowing non-blocking updates
"""
"""
import unreal
import PySide2.QtWidgets as widgets
import traceback
class UEQApplication (widgets.QApplication):
"""
Ensure that an application never tries to `exec_` inside of Unreal
@TJHeuvel
TJHeuvel / CustomPrefabImporterEditor.cs
Last active November 9, 2019 18:30
Custom inspector window for Unity prefabs that allows you to (multi) edit them.
using UnityEditor;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine;
using System.Reflection;
using System;
using System.Collections;
using System.Linq;
using Object = UnityEngine.Object;
using System.Collections.Generic;