Skip to content

Instantly share code, notes, and snippets.

View neuroticnerd's full-sized avatar

Bryce Eggleton neuroticnerd

View GitHub Profile
@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 / 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 / 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 / supervisor.rst
Created February 19, 2015 04:52
tips for dealing with supervisor
@neuroticnerd
neuroticnerd / openssl-file-encryption.rst
Last active August 29, 2015 14:18
File encryption with OpenSSL

File Encryption Using OpenSSL RSA Key

Because of the way that the algorithm used works, you cannot encrypt an amount of information greater than the size of the key being used. That is, a key of size 2048 would allow you to encrypt 2048 bytes of information. This means that just using the key by itself, it cannot be used on arbitrarily large pieces of data such as files.

The solution is to generate a random key which can be used for

@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 / django-settings-utils.py
Created October 26, 2015 14:25
Utility functions for Django settings.py
import os
# utility for getting settings from the environment
NOT_PROVIDED = object()
def env(key, default=NOT_PROVIDED, coerce=str):
if default is NOT_PROVIDED:
val = os.environ.get(key)
@neuroticnerd
neuroticnerd / setup_adb_sideloading.rst
Last active May 24, 2016 22:19
Setting up ADB sideloading on FireTV (OS X)

Setting up ADB Sideloading for FireTV (OS X)

The first step is to download the .apk file of the app which you want to sideload into your 'Downloads' folder. Since Google only wants you to access apps via whatever methods they provide, you cannot just download it directly from the Google Play store. There are essentialy two methods to accomplish the task of downloading. You can either use one of the browser extensions available for the job, or one of the online sites which proxy the download for you.

@neuroticnerd
neuroticnerd / sublime-user-settings.json
Last active June 28, 2016 15:52
Sublime user settings for Python coding
{
"bold_folder_labels": true,
"close_windows_when_empty": true,
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"default_line_ending": "unix",
"drag_text": false,
"draw_white_space": "all",
"enable_telemetry": false,
"ensure_newline_at_eof_on_save": true,
"fade_fold_buttons": false,
@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: