Skip to content

Instantly share code, notes, and snippets.

View neuroticnerd's full-sized avatar

Bryce Eggleton neuroticnerd

View GitHub Profile
@neuroticnerd
neuroticnerd / supervisor.rst
Created February 19, 2015 04:52
tips for dealing with supervisor
@neuroticnerd
neuroticnerd / mac_dotbash_profile
Last active October 8, 2015 18:09
Useful Bash profile aliases and functions
#!/usr/local/env bash
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
###############################################################################
### use local directories for homebrew and python
export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
###############################################################################
### virtualenv setup and shortcuts
@neuroticnerd
neuroticnerd / landrush.rst
Last active February 2, 2020 22:14
Vagrant landrush DNS plugin tips and troubleshooting

landrush

landrush is an excellent Vagrant plugin if you are trying to develop or test in a multi-machine VM environment. It works by spinning up a small local DNS server and registering the private network IPs of each machine during vagrant up so that they can be accessed via their hostname in both the host machine as well as the other guest machines. A great bonus of using landrush is that the VMs can be defined in separate Vagrantfiles (e.g. if you have separate git repos for building different machines).

useful commands

  • vagrant landrush status - show whether the DNS server
@neuroticnerd
neuroticnerd / responsejson.py
Last active December 22, 2021 16:36
Unify the format of JSON returned from a REST API
"""
Author: Bryce Eggleton
License: MIT
"""
import json
import traceback
def _get_container():
"""
@neuroticnerd
neuroticnerd / sslpatches.py
Last active August 29, 2015 14:10
SSL and Requests workarounds for some annoying SSL/HTTPS errors
# NOTE: these workarounds are collected here, but are NOT my work,
# credit goes to the original authors for finding the workarounds!
# TODO: add links to articles crediting original authors
try:
"""
if you don't want to patch the ssl library and are just using
requests, then you can use an adapter to force TLS on HTTPS;
"""
import requests
@neuroticnerd
neuroticnerd / utils-unicode-xml.py
Created September 15, 2014 18:07
Unicode and XML helpers
import re
import htmlentitydefs
from lxml import etree as ET
from bs4 import UnicodeDammit
def resolve_entities(entitystring):
"""
Credits for this function go to Fredrik Lundh
@neuroticnerd
neuroticnerd / gpg-overview.rst
Last active September 24, 2019 20:43
GPG setup and overview

Introduction to GPG

GPG can be a bit difficult to wrap your head around at first since its slightly more complex than using asymmetric encryption through SSH or OpenSSL. It can be extremely useful, however, for encrypting files, communications, or verifying digital signatures.

@neuroticnerd
neuroticnerd / apikey.py
Last active August 29, 2015 14:04
API key Django model for use with Oauth Client
from uuidfield import UUIDField
from django.contrib import admin
class APIKey(models.Model):
apikey = UUIDField(auto=True)
url = models.CharField(max_length=255, blank=True, null=True)
client = models.ForeignKey(Client, related_name='apikeys')
scope = models.CharField(max_length=64, blank=True, null=True)
active = models.BooleanField(default=True)
@neuroticnerd
neuroticnerd / relatedmanager.py
Last active May 23, 2020 19:46
Django relation manager for querysets
from django.db import models
class SelectPrefetchManager(models.Manager):
"""
This allows you to initialize a manager with 'select' or 'prefetch'
parameters whose values are tuples of fields to be automatically applied
to the queryset via select_related() or prefetch_related(), respectively.
objects = RelatedManager(select=('field1',), prefetch=('m2mfield',))