Skip to content

Instantly share code, notes, and snippets.

View AstraLuma's full-sized avatar
🐍
snek snek snek snek

Jamie Bliss AstraLuma

🐍
snek snek snek snek
View GitHub Profile
import collections.abc
import pathlib
__all__ = ('root',)
class AttrsView(collections.abc.KeysView):
def __init__(self, root):
self._root = pathlib.Path(root)
@AstraLuma
AstraLuma / fails1.py
Created March 13, 2019 20:55
Gio Weirdness
import functools
from gi.repository import GObject
from gi.repository import Gio
from gi.repository import GLib
def runloop(func):
@functools.wraps(func)
def wrapped(*pargs, **kwargs):
func(None)
@AstraLuma
AstraLuma / README.md
Last active December 10, 2018 01:52
Python Async+SSH

Proof of Concept of using Python+Async to connect to a server over SSH.

Requires:

  • Python >= 3.6
  • msgpack
  • tornado<5

Run client.py, assumes you're running ssh-server on localhost and that you can log in to it.

@AstraLuma
AstraLuma / simplepyz.py
Created October 18, 2018 21:29
Simple zipapp maker
#!/usr/bin/env python3
"""
A little script to make minimal pyz packages for zipsafe programs.
NOTE: zip safe means:
* No package expects to be able to use open() to access data it shipped with
* No compiled modules
"""
import argparse
import os

Keybase proof

I hereby claim:

  • I am astronouth7303 on github.
  • I am astraluma (https://keybase.io/astraluma) on keybase.
  • I have a public key ASAryKyuDpM03VLlWyWLGP3dG8ItyZH0Q77LV0yyAKpuKwo

To claim this, I am signing this object:

@AstraLuma
AstraLuma / helloworld.py
Last active April 16, 2018 19:32
Async Talk Code Examples
import asyncio
async def say(what, when):
await asyncio.sleep(when)
print(what)
# print() is already buffered by Python, IPC Pipes, etc
# You should still async it, but it's only going to bite
# when other things go wrong.
@AstraLuma
AstraLuma / 7sea.py
Last active September 3, 2017 19:34
#!/usr/bin/python3
import random
import itertools
rand = random.SystemRandom()
def roll(num, *, reroll=False, explosions=False):
dice = [rand.randint(1, 10) for _ in range(num)]
### Keybase proof
I hereby claim:
* I am astronouth7303 on github.
* I am astronouth7303 (https://keybase.io/astronouth7303) on keybase.
* I have a public key ASDEQCONquDJhr5_YYK4Qf-mWqC1B7XxJcspUTIzW0lecQo
To claim this, I am signing this object:
@AstraLuma
AstraLuma / sse.py
Last active August 1, 2017 01:37
Quick SSE
import time
import requests
def _stream_raw_sse(*pargs, _last_event_id=None, headers=None, **kwargs):
"""
Streams Server-Sent Events, each event produced as a sequence of
(field, value) pairs.
Does not handle reconnection, etc.
"""
2017-07-19 17:12:49,055 [salt.minion ][INFO ][29846] Starting a new job with PID 29846
2017-07-19 17:12:49,713 [salt.state ][INFO ][29846] Loading fresh modules for state activity
2017-07-19 17:12:49,974 [salt.fileclient ][INFO ][29846] Fetching file from saltenv 'base', ** done ** 'test_state.sls'
2017-07-19 17:12:49,980 [salt.loaded.int.module.logmod ][ERROR ][29846] Start pillar
2017-07-19 17:12:49,980 [salt.loaded.int.module.logmod ][ERROR ][29846] {}
2017-07-19 17:12:49,981 [salt.loaded.int.module.logmod ][ERROR ][29846] End pillar