Skip to content

Instantly share code, notes, and snippets.

@alkasm
alkasm / dataclass_required_field.py
Created July 24, 2022 02:24
A pattern for "required" arguments in dataclasses, allowing for fields without defaults to follow fields with defaults.
from dataclasses import dataclass, field
from datetime import datetime
from typing import Optional, TypeVar
T = TypeVar("T")
def required() -> T:
f: T
@pthom
pthom / verbose_function_decorator.py
Last active December 15, 2022 14:19
Python decorator to log function call details (can include: input parameters, output parameters, return value)
import logging
import inspect
def verbose_function(dump_args: bool = True, dump_return: bool = False, dump_args_at_exit: bool = False):
"""
Decorator to print function call details.
This can include:
* input parameters names and effective values
* output parameters (if they were modified by the function)
@sts10
sts10 / rust-command-line-utilities.markdown
Last active December 20, 2024 19:41
A curated list of command-line utilities written in Rust

A curated list of command-line utilities written in Rust

Note: I have moved this list to a proper repository. I'll leave this gist up, but it won't be updated. To submit an idea, open a PR on the repo.

Note that I have not tried all of these personally, and cannot and do not vouch for all of the tools listed here. In most cases, the descriptions here are copied directly from their code repos. Some may have been abandoned. Investigate before installing/using.

The ones I use regularly include: bat, dust, fd, fend, hyperfine, miniserve, ripgrep, just, cargo-audit and cargo-wipe.

  • atuin: "Magical shell history"
  • bandwhich: Terminal bandwidth utilization tool
@jakebrinkmann
jakebrinkmann / .flake8
Last active December 10, 2024 23:08
Using the Python poetry tool to manage dependencies of an AWS Serverless (AWS-SAM-CLI) project.
##### https://flake8.pycqa.org/en/latest/user/configuration.html
[flake8]
ignore =
# D100: Missing docstring at top of file
D100,
# D104: Missing docstring in __init__.py
D104,
# D401: Docstring first line should be imperative
D401,
# D101 Missing docstring in public class
@sindresorhus
sindresorhus / esm-package.md
Last active December 20, 2024 10:06
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
"""Get import dependencies using PyInstaller.
The node types can be used to check for instances.
A brief description of the main ones are below:
MissingModule: An imported module that cannot be found.
Attributes:
identifier (str)
Example:
MissingModule('invalid.module',)
@Denbergvanthijs
Denbergvanthijs / donut.py
Last active November 9, 2024 08:09
3D spinning donut in Python. Based on the pseudocode from: https://www.a1k0n.net/2011/07/20/donut-math.html
import numpy as np
screen_size = 40
theta_spacing = 0.07
phi_spacing = 0.02
illumination = np.fromiter(".,-~:;=!*#$@", dtype="<U1")
A = 1
B = 1
R1 = 1
@Thong-Tran
Thong-Tran / README.md
Last active May 27, 2022 11:07
Run locust workers

Run locust workers

python .\locust-workers.py -h
usage: locust-workers.py [-h] [-p path] [-s num] [-f LOCUSTFILE]

Run locust workers

optional arguments:
 -h, --help show this help message and exit
@mnesarco
mnesarco / objects.py
Created July 23, 2020 16:54
Enhanced python properties with some metaprog.
# file: objects.py
# Copyright 2020 Frank David Martínez Muñoz (mnesarco)
# License: MIT
from typing import Union
__all__ = ('self_properties', 'properties')
def self_properties(self, scope: dict, exclude=(), save_args: bool = False):
@katef
katef / life-utf8.c
Last active September 8, 2024 05:59
XBM to UTF-8 braille image things
/*
* John Conway's Game of Life.
*
* This is written for POSIX, using Curses. Resizing of the terminal is not
* supported.
*
* By convention in this program, x is the horizontal coordinate and y is
* vertical. There correspond to the width and height respectively.
* The current generation number is illustrated when show_generation is set.
*