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
@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
@AstraLuma
AstraLuma / .xonshrc.py
Last active November 28, 2017 23:24
work .xonshrc
$XONSH_SHOW_TRACEBACK = True
$PROJECT_DIRS = g`~/code` + g`~/src`
xontrib load vox prompt_ret_code avox z
xontrib load schedule salt
$PATH = g`~/.conda/bin` + g`~/.local/bin` + list($PATH)
${...}.pop('COLUMNS', None)
${...}.pop('ROWS', None)
class Top:
@property
def foo(self):
...
@foo.setter
def set_foo(self, value):
...
class Spam(Top):
@property
@AstraLuma
AstraLuma / wintest.py
Created March 17, 2017 18:01
Testing select-like with pipes on windows
import time
import os
import ctypes
import ctypes.wintypes
PeekNamedPipe = ctypes.windll.kernel32.PeekNamedPipe
PeekNamedPipe.restype = ctypes.wintypes.BOOL
def try_peek(pipe, desc=''):
lpTotalBytesAvail = ctypes.wintypes.DWORD(0)
from abc import ABC
from collections.abc import Set, Iterable
from itertools import count
class Base(Iterable, ABC):
def __iter__(self):
yield from []
def mk(klass):
return type('x', (klass,), {})()
from django import forms
from localflavor.us.forms import USPSSelect
class NoDefaultSelect(forms.Select):
def render_options(self, selected_choices):
opts = super().render_options(selected_choices)
if selected_choices:
opts = "<option disabled selected value style='display:none;'></option>\n" + opts
return opts
class ErrorCounter(collections.Counter):
"""
Repeatable context manager. Counts the types of errors when exiting.
Note that expected exceptions are surpressed.
Generally, replaces constructs like:
for egg in spam():
try:
import webview
import threading
from webview import OPEN_DIALOG, FOLDER_DIALOG, SAVE_DIALOG
import asyncio
# FIXME: Multiple window support
class WebviewThread(threading.Thread):
"""
Webview as a thread.
@AstraLuma
AstraLuma / bootshell
Last active October 26, 2019 17:14
Set up shellinabox and xonsh on ec2
#!/bin/sh -e
# EC2
#sudo yum install git zlib-devel autoconf automake libtool python35 python35-pip
# Scaleway - Ubuntu
sudo apt-get install git libpam0g-dev zlib1g-dev dh-autoreconf python3 python3-pip
# For some reason, the [ptk] doesn't work on Scaleway C1 with Ubuntu
sudo python3 -m pip install xonsh[ptk]
git clone https://github.com/shellinabox/shellinabox.git