Skip to content

Instantly share code, notes, and snippets.

View jathanism's full-sized avatar
🍕
See below.

Jathan McCollum jathanism

🍕
See below.
View GitHub Profile
@jathanism
jathanism / bulk_save.py
Created March 3, 2025 20:00 — forked from crucialfelix/bulk_save.py
Django BulkSave - batches insert, updates, deletes and m2m into the minimum number of queries
import contextlib
import hashlib
import logging
from collections import defaultdict
from decimal import Decimal
from django.db.models import DecimalField, ForeignKey
log = logging.getLogger(__name__)
@jathanism
jathanism / README.md
Created October 10, 2023 16:43 — forked from koshatul/README.md
use Apple Keychain to store GPG Passphrases

gpg-agent setup

Need to setup gpg-agent first, on OSX I use keychain (it also does ssh-agent)

$ brew info keychain
keychain: stable 2.8.5
User-friendly front-end to ssh-agent(1)
https://www.funtoo.org/Keychain
/usr/local/Cellar/keychain/2.8.5 (7 files, 108.5KB) *
@jathanism
jathanism / merge_dicts.py
Created September 20, 2022 19:47 — forked from rmax/merge_dicts.py
using itertools's chain and groupby to merge a list of dictionaries
def merge_dicts(dict_list):
"""Merge all values from dict list into a single dict
>>> d1 = {'a': 1, 'b': 2}
>>> d2 = {'a': 2, 'b': 3}
>>> merge_dicts([d1, d2])
{'a': [1, 2], 'b': [2, 3]}
"""
kviter = chain.from_iterable(d.iteritems() for d in dict_list)
@jathanism
jathanism / testjob.py
Created April 13, 2022 21:20 — forked from wvandeun/testjob.py
Nautobot test job
from nautobot.dcim.models import Device
from nautobot.dcim.models import Interface
from nautobot.dcim.choices import InterfaceTypeChoices
from nautobot.ipam.models import VLAN
from nautobot.extras.jobs import Job
class TestJob(Job):
class Meta:
description = "Some job jo!"
@jathanism
jathanism / select_option_for_select2.py
Created October 22, 2021 17:49 — forked from Alireza2n/select_option_for_select2.py
a function to interact with select2 element using Selenium and Python (inspired by https://stackoverflow.com/a/17757761/8504344 and tested on firefox)
def select_option_for_select2(driver, id, text=None):
element = driver.find_element(By.XPATH, '//*[@id="{}"]/following-sibling::*[1]'.format(id))
element.click()
if text:
element = driver.find_element(By.CSS_SELECTOR, "input[type=search]")
element.send_keys(text)
try:
element.send_keys(Keys.ENTER)
@jathanism
jathanism / README.md
Created February 22, 2021 21:57 — forked from bruth/README.md
Django command that gives a set of subcommands a namespace. For example, a command named after an app can be defined with a set of subcommands, e.g. `python manage.py command subcommand`.

Subcommander

Managment commands are assumed to be unique across all apps in a Django project. This can lead to long or obscure command names in attempt to namespace those commands.

Subcommander acts as a proxy command giving the real commands a namespace. The subcommander module can be named after the app name or some derivation. The structure looks as follows:

myapp/
    management/
        commands/
@jathanism
jathanism / party.py
Last active November 21, 2016 23:31 — forked from tcuthbert/party.py
party.py
import sys
import string
from trigger.cmds import Commando
from twisted.python import log
log.startLogging(sys.stdout, setStdout=False)
devices = ["pe1.demo.localdomain", "pe2.demo.localdomain"]

NSoT Installation Options & Instructions

Network Server of Truth, or NSoT, is designed to run on multiple architectures and environments that support Python. Provided the host is properly configured, NSoT can be installed with a single command line entry.

$ pip install nsot
@jathanism
jathanism / ssh-proxy.py
Last active September 16, 2015 19:15 — forked from hiboma/ssh-proxy.py
twisted - ssh proxy スケッチ
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
import base64, os, fcntl, tty, struct
from twisted.enterprise import adbapi
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite