Skip to content

Instantly share code, notes, and snippets.

View theacodes's full-sized avatar
🎛️
Bleep bloop

Stargirl Flowers theacodes

🎛️
Bleep bloop
View GitHub Profile
@theacodes
theacodes / gist:6753923
Created September 29, 2013 16:17
Memory profiling WSGI middleware
from collections import defaultdict
import gc
class MemoryProfilingMiddleware(object):
def __init__(self, app):
self.app = app
#gc.set_debug(gc.DEBUG_LEAK)
self.last_count = 0
@theacodes
theacodes / appengine_config.py
Created September 2, 2014 22:28
appengine_config.py demonstrating how to properly add vendor packages to sys.path
"""
`appengine_config.py` gets loaded every time a new instance is started.
Use this file to configure app engine modules as defined here:
https://developers.google.com/appengine/docs/python/tools/appengineconfig
"""
def add_vendor_packages(vendor_folder):
"""
@theacodes
theacodes / echo.py
Created September 6, 2014 17:58
Non-blocking gevent stdin read
#!/usr/bin/env python
from gevent import monkey
monkey.patch_all()
monkey.patch_sys(stdin=True, stdout=False, stderr=False)
import gevent
from gevent.queue import Queue
import sys
import signal
@theacodes
theacodes / logserver.py
Created September 6, 2014 18:29
Gevent based log server
#!/usr/bin/env python
from gevent import monkey
monkey.patch_all()
monkey.patch_sys(stdin=True, stdout=False, stderr=False)
import gevent
from gevent.queue import Queue
import signal
import sys
from socketio.namespace import BaseNamespace
@theacodes
theacodes / index.html
Created September 6, 2014 18:39
Simple socket.io log viewer
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="/static/socket.io.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<script>
angular.module('app', [])
.controller('logs', function($scope){
@theacodes
theacodes / script.js
Created October 5, 2014 04:36
Generic protorpc containers
function flatten_generic_value(val){
if(val.type === 'container'){
return flatten_generic(val['container_value']);
} else if(val.type === 'list'){
return val.list_value.map(flatten_generic_value);
} else {
return val[val.type + '_value'];
}
};
@theacodes
theacodes / logging_setup.py
Created October 7, 2014 20:30
Sentry/Raven simple global logging setup
from raven.handlers.logging import SentryHandler
from raven.conf import setup_logging
import logging
handler = SentryHandler('sentry dsn here')
setup_logging(handler)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)-12s: %(levelname)-8s: %(message)s', datefmt='%m-%d %H:%M')
@theacodes
theacodes / main.py
Created October 7, 2014 20:33
Simple top-level exception catch
import logging_config
if __name__ == '__main__':
try:
do_stuff()
except Exception as e:
logging.exception(e)
raise
@theacodes
theacodes / app.yaml
Last active August 29, 2015 14:07
Cloud Endpoints - Issue with resources & multiclass.
application: your-app-id
version: 1
runtime: python27
threadsafe: true
api_version: 1
module: api
handlers:
# Endpoints handler
- url: /_ah/spi/.*
@theacodes
theacodes / Dockerfile
Created October 14, 2014 14:21
Example python dockerfile (managed vms)
# Dockerfile extending the generic Python image with application files for a
# single application.
FROM google/appengine-python27
ADD requirements.txt /app/
RUN pip install -r requirements.txt
ADD . /app