Skip to content

Instantly share code, notes, and snippets.

View aconz2's full-sized avatar

Andrew Consroe aconz2

View GitHub Profile
@aconz2
aconz2 / fifoleak.py
Created May 28, 2018 04:59
FIFO leak when using many processes under pypy
import multiprocessing
from subprocess import run, PIPE
import os
import gc
def worker(x):
return x * x
def n_files_open():
return len(files_open())
@aconz2
aconz2 / slack-redirect.js
Created May 7, 2018 15:49
slack redirect rewrite (tampermonkey)
// ==UserScript==
// @name Avoid Slack Redirect
// @namespace slackrediravoid
// @include https://*.slack.com/*
// @version 1
// @grant none
// ==/UserScript==
let si = window.setInterval(clearanchors, 2000);
function clearanchors(){
let anchors = document.querySelectorAll('a[href^="https://slack-redir"]');
@aconz2
aconz2 / s3-streaming-fileobj.py
Last active December 18, 2019 21:25
monkey patch s3 streamingbody to be streamable for csv for example
import boto3
import io
import csv
from functools import partial
s3c = boto3.client('s3')
def logging_read(read, amt):
print('READ {}'.format(amt))
return read(amt)
@aconz2
aconz2 / csv-to-xlsx.ps1
Created January 3, 2018 22:56
convert csv to xlsx with excel
param(
[parameter(mandatory=$true)]
[string]$infile,
[parameter(mandatory=$true)]
[string]$outfile
)
# https://msdn.microsoft.com/en-us/vba/excel-vba/articles/workbook-saveas-method-excel
@aconz2
aconz2 / winservicewith.py
Created October 19, 2017 17:17
with block for having a service stopped and then started on exit
import win32serviceutil
class StopStartService:
STARTED, STOPPED = 4, 1
def __init__(self, service_name, timeout=5):
self.service_name = service_name
self.timeout = timeout
def __enter__(self):
@aconz2
aconz2 / arg.py
Last active September 29, 2017 21:30
inspect example
def mystery_fun(sess : requests.Session):
pass
sess_arg = inspect.signature(mystery_fun).parameters['sess']
inspect.getmembers(sess_arg.annotation, inspect.isfunction)
@aconz2
aconz2 / noworks.py
Last active May 18, 2023 12:31
asyncio ssl get peercert
# WARNING: this doesn't work properly
import asyncio
import ssl
import socket
# included logging to try to figure out why this wasn't working...
import logging
logging.basicConfig()
logging.getLogger('asyncio').setLevel(logging.DEBUG)
@aconz2
aconz2 / search-py-docs.py
Created September 6, 2017 04:17
A program that launches a dmenu choice of index terms to open python docs; or lets you search for a term; works with multiple versions
#!/usr/bin/env python3.6
import re
from subprocess import run, PIPE
from pathlib import Path
import requests
import zipfile
import io
import pickle
import urllib
@aconz2
aconz2 / mk-firewall.sh
Created September 3, 2017 22:19
Add firewall rules for minidlna
firewall-cmd --permanent --new-service minidlna
firewall-cmd --permanent --service minidlna --add-port 8200/tcp
firewall-cmd --permanent --service minidlna --add-port 1900/udp
firewall-cmd --permanent --add-service minidlna
firewall-cmd --reload
firewall-cmd --list-services
@aconz2
aconz2 / pi-minimal-DE-install.sh
Last active September 3, 2017 20:15
Installs the PIXEL DE
sudo apt-get upgrade
sudo apt-get install lightdm
sudo apt-get install --no-install-recommends raspberrypi-ui-mods lxterminal gvfs gvfs-backends