Skip to content

Instantly share code, notes, and snippets.

View pmdarrow's full-sized avatar

Peter Darrow pmdarrow

View GitHub Profile
@pmdarrow
pmdarrow / api_docs.py
Created October 26, 2022 20:12
flask-smorest private and public API docs helper
"""
flask-smorest does not support filtering out routes and schemas for public and internal docs.
This is a helper to support this use case.
* Ensure that you have no config values prefixed with `OPENAPI_` except `OPENAPI_VERSION`.
Setting these values enables flask-smorest's documentation routes which we do not want.
* Annotate an endpoint with the `@public_docs` decorator. Example:
```python
from my_project.api_docs import public_docs
@pmdarrow
pmdarrow / fields.py
Created June 17, 2020 17:39
Simple marshmallow enum field with support for apispec
# Loosely based on https://github.com/h/marshmallow_enum
from marshmallow.fields import Field
class EnumField(Field):
default_error_messages = {
'invalid': 'Invalid enum value {input}',
}
@pmdarrow
pmdarrow / inheritance.py
Created October 9, 2017 01:43
Python inheritance
class Base(object):
def __init__(self, foo='foo_text', bar='bar_text'):
self.foo = foo
self.bar = bar
class Child(Base):
def __init__(self, extra='extra_text', *arg, **kwargs):
self.extra = extra
super(Child, self).__init__(*arg, **kwargs)
================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/fh-dynoman/recipes/default.rb
================================================================================
NoMethodError
-------------
undefined method `time' for Chef::Resource::Cron
712145 function calls (702303 primitive calls) in 0.840 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.798 0.798 /Users/peter/.virtualenvs/drf-perf/lib/python3.4/site-packages/django/views/decorators/csrf.py:57(wrapped_view)
1 0.000 0.000 0.798 0.798 /Users/peter/.virtualenvs/drf-perf/lib/python3.4/site-packages/rest_framework/viewsets.py:69(view)
1 0.000 0.000 0.798 0.798 /Users/peter/.virtualenvs/drf-perf/lib/python3.4/site-packages/rest_framework/views.py:442(dispatch)
1 0.000 0.000 0.797 0.797 /Users/peter/.virtualenvs/drf-perf/lib/python3.4/site-packages/rest_framework/mixins.py:18(create)
1 0.000 0.000 0.414 0.414 /Users/peter/.virtualenvs/drf-perf/lib/python3.4/site-packages/rest_framework/serializers.py:198(is_valid)
@pmdarrow
pmdarrow / protobuf-py3.rb
Last active August 29, 2015 14:24
protobuf-py3 Homebrew formula
# Place in /usr/local/Library/Formula/, then
# brew install protobuf-py3
class ProtobufPy3 < Formula
url "https://github.com/GreatFruitOmsk/protobuf-py3/archive/2.5.1.tar.gz"
version "2.5.1"
sha256 "496484244288b6e9b7d94baac71a3c0ea19c2a381a8a8685f0ff4235e81b1b38"
conflicts_with "protobuf", :because => "protobuf-py3 is incompatible with protobuf"
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@pmdarrow
pmdarrow / iterm-launcher.js
Last active September 14, 2017 20:52
Launch iTerm 2 with a predefined tab & split configuration using Apple's "Javascript for Automation"
/**
* AppleScript to launch iterm2 terminals/tabs with configurable:
* ~ Name <name>
* ~ List of commands <cmds>
* ~ Split behavior horizontal(h) or vertical(v) <split> :: (h, v)
*
* Run from terminal with `osascript iterm-launcher.js`.
* Don't unfocus with the mouse/keyboard while executing the script.
*
* JS port of https://github.com/luismartingil/scripts/blob/master/iterm_launcher02.applescript
@pmdarrow
pmdarrow / gist:3427827
Created August 22, 2012 17:40
How to compile wkhtmltopdf static binary on Ubuntu 12.04
# These instructions were tested on Ubuntu 12.04 64bit
# Be prepared to wait a while...
sudo apt-get install openssl build-essential xorg libssl-dev libxrender-dev libxext-dev libpq-dev libx11-dev
git clone git://github.com/antialize/wkhtmltopdf.git
git clone git://gitorious.org/+wkhtml2pdf/qt/wkhtmltopdf-qt.git wkhtmltopdf-qt
cd wkhtmltopdf
mkdir static-build
ln -s ../wkhtmltopdf-qt static-build/qt
./scripts/static-build.sh
@pmdarrow
pmdarrow / views.py
Created May 12, 2011 01:39
GData OAuth in Django
from django.shortcuts import render_to_response
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
import gdata.gauth
import gdata.contacts.client
CONSUMER_KEY = 'nothx'
CONSUMER_SECRET = 'nothx'
SCOPE = ['https://www.google.com/m8/feeds/']
DOMAIN = 'nothx'