Skip to content

Instantly share code, notes, and snippets.

@mattupstate
mattupstate / helpers.py
Last active January 4, 2016 03:09
A helper function for grabbing pseudo-namespaced configuration options from a Flask application
def namespaced_config_options(app, prefix):
"""Returns a dictionary of configuration options built from
the specified Flask application and string prefix. Keys in the
resulting dictionary will be lowercase.
:param app: a Flask application
:param prefix: a configuration namespace prefix. e.g. `IMAGE_STORE`
"""
rv = {}
for key, value in app.config.iteritems():
@mattupstate
mattupstate / windowResize.coffee
Created December 4, 2013 22:07
A generic window resize directive to which you can add to any element to call a function on your controller
angular.module('something')
.directive 'windowResize', ($window, $parse) ->
restrict: 'A'
link: (scope, element, attrs) ->
w = angular.element($window)
fn = $parse(attrs['windowResize'])
handler = (event) ->
@mattupstate
mattupstate / gist:7010498
Created October 16, 2013 16:11
Flask-Mail Log Handler
import logging
from flask_mail import Message
class FlaskMailLogHandler(logging.Handler):
def __init__(self, mail, sender, recipients, subject, *args, **kwargs):
super(FlaskMailLogHandler, self).__init__(*args, **kwargs)
@mattupstate
mattupstate / virtualbox.json
Created September 3, 2013 20:45
Ubuntu 12.04 VirtualBox Packer example
{
"provisioners": [
{
"type": "shell",
"scripts": [
"scripts/base.sh",
"scripts/vagrant.sh",
"scripts/virtualbox.sh",
"scripts/ruby.sh",
"scripts/chef.sh",
@mattupstate
mattupstate / module.sublime-snippet
Created July 19, 2013 13:55
A simple Python module header snippet for Sublime Text
<snippet>
<tabTrigger>module</tabTrigger>
<scope>source.python</scope>
<description>Module</description>
<content><![CDATA[# -*- coding: utf-8 -*-
"""
${1:name}
${1/./~/g}
@mattupstate
mattupstate / helpers.py
Created June 25, 2013 15:04
Register all Blueprint instances on the specified Flask application found in all modules for the specified package
# -*- coding: utf-8 -*-
"""
helpers
~~~~~~~
helpers module
"""
import pkgutil
import importlib
@mattupstate
mattupstate / Vagrantfile
Last active December 13, 2015 21:48
RabbitMQ cluster with Vagrant and Chef
Vagrant::Config.run do |vagrant|
vagrant.vm.define :vm1 do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :hostonly, "192.168.0.80"
config.vm.host_name = 'rabbit1'
config.vm.provision :chef_solo do |chef|
chef.add_recipe "apt"
chef.add_recipe "hostsfile"
@mattupstate
mattupstate / Scale to Fit.jsx
Created August 22, 2012 00:30
Photoshop script to scale an image to fill a specified rectangle and preserve aspect ratio. Save this in <Photoshop Install Folder>/Presets/Scripts and restart Photoshop.
#target photoshop
main ();
function cloneRectangle(rect) {
return { x:rect.x, y:rect.y, width:rect.width, height:rect.height };
}
function rectangle(x, y, width, height) {
return { x:x, y:y, width:width, height:height };
@mattupstate
mattupstate / configure_nginx.yml
Created July 31, 2012 21:51
pseudo nginx playbook
---
- hosts: testing
user: ubuntu
sudo: True
vars_files:
- software/nginx/vars/default.yml
tasks:
@mattupstate
mattupstate / supervisord.sh
Created April 19, 2012 18:50
Super simple supervisor init.d script
# Supervisord auto-start
#
# description: Auto-starts supervisord
# processname: supervisord
# pidfile: /var/run/supervisord.pid
PATH=/sbin:/usr/sbin:/bin:/usr/bin
NAME=supervisord
DESC="supervisod is a system for controlling process state"
SUPERVISORD=/usr/local/bin/supervisord