Skip to content

Instantly share code, notes, and snippets.

View glassresistor's full-sized avatar

Mikela glassresistor

View GitHub Profile
def seq_roles(role):
def attach_roles(func):
@wraps(func)
def inner_decorator(*args, **kwargs):
for host in env.roledefs[role]:
with settings(host_string = host):
func(*args, **kwargs)
return inner_decorator
return attach_roles
@glassresistor
glassresistor / gist:3409251
Created August 20, 2012 23:32
Explodign Watermelon
1) Cut whole in top of water melon.
2) Boar out fist sized whole for dry ice and liquer and possibly sugar/mixer of some form.
3) Use stick to puncter small hole in water melon
4) Alternate adding dry ice cubes(size description) and brown liquor(whiskey or tiquela)
5) Monitor reaction.
6) Close top.
7) Monitor reaction, maybe poke hole.
8) Add more alcohol throughout the day.
@glassresistor
glassresistor / gist:4230058
Created December 7, 2012 01:45
Fix for SmartDataCenter list_machines tag logic.
from fabric.api import env
def list_machines(*args, **kwargs):
"""
Wrapper for listing machines which match every tag. The current api behavior
is to return a list for any matching tags.
"""
tags = kwargs.get('tags')
lol_machines = [] # list of sets of machines
for key, value in tags.iteritems():
CONTEXT: start
USER: got resource
ITER: yielding 1
USER: yielding 1
GOT: 1
ITER: yielding 2
USER: yielding 2
GOT: 2
ITER: yielding 3
USER: yielding 3
@glassresistor
glassresistor / gist:5389800
Last active December 16, 2015 06:10
.bashrc
#custom stuff
function virtualenv_info {
[ $VIRTUAL_ENV ] && echo ''`basename $VIRTUAL_ENV`') '
}
PS1="\n\[\e[35;1m\]┌───=[ \[\e[37;0m\]\u \[\e[35;1m\]:: \[\e[37;1m\]\h \[\e[35;1m\]-( \[\e[37;1m\]\j\[\e[35;1m\] )-[ \[\e[37;0m\]\w\[\e[35;1m\] ]\n\[\e[35;1m\]└──(\$(virtualenv_info)\[\e[0m\]"
VIRTUAL_ENV_DISABLE_PROMPT=1
export WORKON_HOME=$HOME/.virtualenvs
class ContentField(models.ForeignKey):
def __init__(self, *args, **kwargs):
self.encodings = kwargs.pop('encodings')
self.required_fields = set(kwargs.pop('required_fields'))
args = list(args)
args.insert(0, 'basecontent.BaseContent')
super(ContentField, self).__init__(*args,**kwargs)
{
"description": "adsfasdfasdfasdfdasf",
"id": 1,
"members": [
{
"content": {
"body": {
"created": "2013-05-17T16:25:42.082347",
"data": "/media/data/change-the-conversation_4.md",
"encoding": "md",
@glassresistor
glassresistor / gist:5724431
Last active December 18, 2015 04:19
Polymorphic related fields for tastypie
class PolymorphicRelatedField(fields.ToOneField):
def get_related_resource(self, related_instance):
"""
Instaniates the related resource.
"""
to = {
models.Asset: AssetResource,
models.Content: ContentResource,
@glassresistor
glassresistor / gist:5862435
Created June 25, 2013 21:09
MultipartResource tastypie
class MultipartResource(object):
def deserialize(self, request, data, format=None):
if not format:
format = request.META.get('CONTENT_TYPE', 'application/json')
if format == 'application/x-www-form-urlencoded':
return request.POST
if format.startswith('multipart'):
data = request.POST.copy()
@glassresistor
glassresistor / ad.html
Last active December 19, 2015 07:59
Iframes that resize to fit content dynamically across domain. Its great for using 3rd party ads securely and quickly
<html>
<head>
</head>
<body style="margin: 0px;">
<script>
var resize = function(){
window.parent.postMessage(window.document.body.offsetHeight,"*");
}
window.document.body.onload = resize;
window.document.body.addEventListener("DOMNodeInserted", resize);