Skip to content

Instantly share code, notes, and snippets.

View neuroticnerd's full-sized avatar

Bryce Eggleton neuroticnerd

View GitHub Profile
@neuroticnerd
neuroticnerd / twitchtv_rpi2.rst
Last active November 12, 2022 08:12
Streaming twitch.tv on your Raspberry Pi 2

Streaming twitch.tv on your Raspberry Pi 2

The following will explain the steps necessary to stream twitch.tv (as well as other media sites like YouTube) on the Raspbian (wheezy) distribution for the Raspberry Pi 2. While you should be able to accomplish the following instructions with Python 2.6.x, I recommend using 2.7.10+.

System Updates

@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 / 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',))
@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 / 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 / python-on-ubuntu.sh
Last active July 27, 2018 07:09
Python 2.7.9 on Ubuntu 14.04.2 (without overwriting original version)
#! /usr/bin/env bash
# http://smirnov-am.blogspot.com/2015/04/installation-of-python-279-in-ubuntu.html
# http://davebehnke.com/python-pyenv-ubuntu.html
# https://renoirboulanger.com/blog/2015/04/upgrade-python-2-7-9-ubuntu-14-04-lts-making-deb-package/
# install dependencies
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
@neuroticnerd
neuroticnerd / python-logging.rst
Created February 20, 2015 00:02
debunking the myth that using logging instead of print is too difficult!

python logging demystified!

disclaimer

This has been written with the latest version of Python 2 in mind (currently 2.7.9), and while the general premise holds true for

@neuroticnerd
neuroticnerd / README.rst
Created September 17, 2016 00:25
Convenience wrapper for Python packaging using twine

Twine wrapper script

Even once you've figured out the intricacies of Python packaging and figure out why its a good idea to use twine, its still nice to have a few convenience tools to make using it easier.

The pypackage.sh file should be placed in ~/.scripts as ~/.scripts/pypackage and then in your ~/.bash_profile you should have export PATH="$HOME/.scripts:$PATH" so that it

@neuroticnerd
neuroticnerd / fizzbuzz.py
Last active September 9, 2016 19:25
Using FizzBuzz as an exercise in coding
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
Sure, I had been aware that FizzBuzz existed, and had heard about it in
passing, but never had it actually been used in any interview I had been a
part of. Until now. The actual premise of the question is just as simple as
it was designed to be, but what if you wanted to improve upon it? This is
just a random exercise in improving the algorithm. For science.
FIZZBUZZ: