Skip to content

Instantly share code, notes, and snippets.

@TimelessP
TimelessP / asynchello.py
Created November 26, 2023 12:05
FastAPI, terminal input, background task, all in one...
import asyncio
import os
import signal
import sys
import time
from fastapi import FastAPI
from aioconsole import ainput
from threading import Thread, Event
import uvicorn
@TimelessP
TimelessP / main.py
Last active January 22, 2023 20:30
A replit db example
"""
https://replit.com/@TimelessP/Replit-db-experiment#main.py
https://gist.github.com/TimelessP/72f4efa1e5b523df526ff9cf3c7de4da
"""
from replit import db
from dataclasses import dataclass
import bcrypt
import getpass
import re
import datetime

Keybase proof

I hereby claim:

  • I am TimelessP on github.
  • I am timelessp (https://keybase.io/timelessp) on keybase.
  • I have a public key whose fingerprint is 8242 8A57 CFA7 B9BD 3FDC 7BA0 7516 5F7D 53AC 145F

To claim this, I am signing this object:

@TimelessP
TimelessP / minimalmenu3.py
Last active August 7, 2022 07:41
In my side quest to find a concise and fun way to create menus, I have now created minimalmenu3.py
#!/usr/bin/env python3
"""
minimalmenu3.py by @TimelessP.
MIT Licence.
2022-08-04
https://gist.github.com/TimelessP/8d45006bab00ec634a474bf3453f1772
"""
import os
import subprocess
@TimelessP
TimelessP / telnet_echo.py
Created July 31, 2022 14:21
Twistd echo and shout example of a telnet service with a background task.
"""
telnet_echo.py by @TimelessP
https://gist.github.com/TimelessP/5abce3c64c4b671d79121d1e459aecb3
Run using:
`twistd -ny telnet_echo.py`
"""
from twisted.application.internet import TCPServer
from twisted.application.service import Application
from twisted.conch.telnet import TelnetProtocol, TelnetTransport
from twisted.internet.protocol import ServerFactory
@TimelessP
TimelessP / haversinehello.py
Created July 30, 2022 08:30
haversinehello.py is some slightly-edited code that was generated by openai after some prompting by me. The functionality is mainly around calculating vessel movement around a sphere. Caution, there are calculation bugs in this gist that need fixing.
import math
def calculate_new_coordinate(ship_coordinate, ship_heading, ship_speed, time_elapsed_seconds, heading_hold=False,
depth_metres=0):
"""
Calculates the new coordinates of the ship (lat, long), given the current heading, speed in knots,
and the time elapsed in seconds. A spherical Earth model is used, with no tides.
:param ship_coordinate: (lat, long) in range -90 <= lat <= 90, -180 <= long <= 180.
:param ship_heading: heading in degrees in range 0 <= heading <= 360.
@TimelessP
TimelessP / editquill.py
Last active February 5, 2022 19:30
editquill - a super-minimal, line-mode, sandboxed text editor utility
#!/usr/bin/env python3
"""
editquill - a super-minimal, line-mode, sandboxed text editor utility
created by @TimelessP, 2022-02-05
MIT licence
https://gist.github.com/TimelessP/c6b0c20b314f6213ced329286fa6d4bf
"""
import copy
import datetime
// myGetRoll(), myGetPitch(), myGetBearing(), mySetHorizonTexture()
// by Timeless Prototype
// Helps with attitude indicator (artificial horizon) display on a prim, plus a few other functions you will probably want for any flying vehicle instruments.
// Created 2009-12-01
// Please give credit to Timeless Prototype in documentation when using anything from this script.
key craftKey = NULL_KEY;
// Returns the roll relative to the horizon (0.0), ranging from 90.0 (right wing down) to -90.0 (left wing down). Assumes frame of reference is East-facing at zero rotation.
float myGetRoll(rotation rot)
@TimelessP
TimelessP / minimalmenu2.py
Last active November 13, 2021 13:09
minimalmenu2.py is more productive
"""
minimalmenu2.py by https://gist.github.com/TimelessP
(MIT Licence)
The primary requirement for minimalmenu2.py is to make it quick and easy to add new menu items.
Example usage:
```python
from minimalmenu2 import register_menu_action, menu
@TimelessP
TimelessP / fastapiexample.py
Created May 15, 2021 09:34
An example of how to use FastAPI whilst running a repeated function call from server start time.
import time
import fastapi
from fastapi.responses import HTMLResponse
import logging
import uvicorn
from fastapi_utils.tasks import repeat_every
# requirements.txt:
# fastapi~=0.65.1
# uvicorn~=0.13.4