Skip to content

Instantly share code, notes, and snippets.

View theY4Kman's full-sized avatar

Zach Kanzler theY4Kman

View GitHub Profile
from typing import Union
def resolve(d: dict) -> dict:
"""Helper which resolves references marked with ref(id)
>>> resolve({'frames': {'0': 'test'}, 'paths': {'0': [ref('0')]}})
{'frames': {'0': 'test'}, 'paths': {'0': ['test']}}
"""
frame_refs = d['frames']
import sys
import threading
import time
if sys.version_info < (3, 4):
def is_main_thread(thread):
return isinstance(thread, threading._MainThread)
else:
def is_main_thread(thread):
return threading.current_thread() == threading.main_thread()
# XXX######################################################################################
# XXX######################################################################################
import os
import linecache
import sys
import time
from trace import Trace
import pytest
def RecordResponse(title=None):
import pytest
class RecordResponse:
@pytest.mark.record_response(title=title)
def it_records_response(self):
pass
@theY4Kman
theY4Kman / django_postgres_arrays.py
Created October 4, 2018 04:55
A Django ORM Expression for Postgres ARRAY literals
from django.contrib.postgres.fields import ArrayField
from django.db.models import Expression, Value
from netfields import InetAddressField
class Array(Expression):
"""A Postgres ARRAY[] expression"""
def __init__(self, *items, output_field=None):
if output_field is None:
@theY4Kman
theY4Kman / django_subquery_only.py
Created October 4, 2018 04:56
A Django ORM Subquery Expression which only returns the specified fields
from django.db.models import Subquery
class SubquerySelect(Subquery):
"""Return only a subset of fields from a Subquery"""
template = '(SELECT %(fields)s FROM (%(subquery)s) AS %(subquery_alias)s)'
def __init__(self, queryset, output_field=None, fields=('*',), **extra):
self.fields = tuple(fields)
@theY4Kman
theY4Kman / django_rollback_transactions_middleware.py
Created October 4, 2018 04:59
A Django middleware which rolls back any DB changes at the end of the request. I found it useful when profiling SQL queries from POST/PUT requests, because I didn't have to find or generate so much test data
import logging
from contextlib import contextmanager
from django.db import transaction
from django.http import HttpRequest
from django.utils.deprecation import MiddlewareMixin
logger = logging.getLogger(__name__)
@theY4Kman
theY4Kman / camel_words_collector.py
Created October 12, 2018 16:24
pytest plugin to allow matching class names on word boundaries
"""
In pytest.ini, we configure python_classes with wildcard patterns that are
checked with fnmatch. This can produce some unintentional effects; for instance,
the pattern For* also matches ForbidsAnonymousUsers, which we don't wish.
This plugin extends the semantics of fnmatch for python_classes, so a dash '-'
in the pattern matches a CamelWords boundary.
- For* will match "ForbidsAnonymousUsers" as well as "ForCurrentUser"
- For-* will match "ForCurrentUser", but not "ForbidsAnonymousUsers"

Below are a list of the available Slack commands for Jukebot.

Command Description
/add track name Add a song to your Jukebot playlist
/album album name Search for an album
/artist artist name Search for an artist
/current playlist track
/delete Delete the currently playing track from your Jukebot playlist
/find track name Search for a track to add to your Jukebot playlist
@theY4Kman
theY4Kman / beanstalk-instance-linker.tamper.js
Last active June 8, 2020 23:31
Link instance IDs on Beanstalk's Health page to the EC2 Console
// ==UserScript==
// @name Linkify beanstalk instances
// @namespace https://perchsecurity.com
// @updateURL https://gist.githubusercontent.com/theY4Kman/9938a82b2176aa4ef3fb38fec564500c/raw/beanstalk-instance-linker.tamper.js
// @version 1.0
// @description Link instance IDs to EC2 console in Beanstalk
// @author theY4Kman
// @match https://console.aws.amazon.com/elasticbeanstalk/*
// @match https://*.console.aws.amazon.com/elasticbeanstalk/*
// @grant none