Skip to content

Instantly share code, notes, and snippets.

View tarkatronic's full-sized avatar

Joey Wilhelm tarkatronic

View GitHub Profile
@tarkatronic
tarkatronic / if_branches.py
Created May 9, 2024 15:02
Python Spelling Bee Solver
from dataclasses import dataclass
from typing import TextIO
@dataclass
class Solver:
center_letter: str
all_letters: set[str]
dictionary: TextIO
@tarkatronic
tarkatronic / logger.go
Created May 3, 2023 19:56
GitHub Ownership Collector
// Based on https://betterstack.com/community/guides/logging/zerolog/
package logger
import (
"io"
"os"
"runtime/debug"
"strconv"
"sync"
@tarkatronic
tarkatronic / Dockerfile
Created April 2, 2019 18:07
Basic Django app running in Docker
FROM python:alpine
RUN apk add --update \
build-base \
postgresql-dev
WORKDIR /source
ADD requirements.txt .
RUN pip install -r requirements.txt
ADD . /source
CMD python manage.py runserver
@tarkatronic
tarkatronic / exercise.go
Created February 17, 2019 15:25
Tour of Go: Equivalent Binary Trees
package main
import (
"fmt"
"golang.org/x/tour/tree"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
@tarkatronic
tarkatronic / base_test_case.py
Last active February 26, 2018 21:15
unittest.TestCase base class to automatically generate bindings
import distutils
import inspect
import os.path
import subprocess
import types
import unittest
class PyangBindTestCase(unittest.TestCase):
yang_files = None
@tarkatronic
tarkatronic / settings.py
Created February 6, 2018 19:24
django-auth-ldap settings
AUTH_LDAP_START_TLS = True
AUTH_LDAP_SERVER_URI = env('AUTH_LDAP_SERVER_URI', cast=str, default=None)
AUTH_LDAP_GLOBAL_OPTIONS = {
ldap.OPT_X_TLS_REQUIRE_CERT: ldap.OPT_X_TLS_NEVER
}
AUTH_LDAP_BIND_DN = env('AUTH_LDAP_BIND_DN', cast=str, default=None)
AUTH_LDAP_BIND_PASSWORD = env('AUTH_LDAP_BIND_PASSWORD', cast=str, default=None)
AUTH_LDAP_USER_SEARCH = LDAPSearchUnion(
LDAPSearch(
'OU=Company,DC=our,DC=domain,DC=com',
@tarkatronic
tarkatronic / pygments_filter.py
Created November 28, 2017 22:10
A Django jsonify template filter
import json
from django import template
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_by_name
register = template.Library()
@tarkatronic
tarkatronic / base.html
Last active June 25, 2017 20:35
Django Bootstrap Messages
{% if messages %}
{% for message in messages %}
<div class="alert{% if message.tags %}{% if message.tags == "error" %} alert-danger{% else %} alert-{{ message.tags }}{% endif %}{% endif %}" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
{{ message }}
</div>
{% endfor %}
{% endif %}
@tarkatronic
tarkatronic / filters.py
Created March 25, 2016 16:47
django-filters TimeSpanFilter
import re
import time
from datetime import datetime, timedelta
import django_filters
from django.utils import timezone
from .lookups import Now
@tarkatronic
tarkatronic / gist:b6d3f6036c13cd54d1a8
Created April 8, 2015 21:17
Mock Django database calls
"""
This is for a case where I was accessing the database connection/cursors directly,
and had need to mock up a result from a database call. The real trick here is
returning the cursor MagicMock object as a side effect of the initial patch.
"""
from unittest import mock
cursor = mock.MagicMock(