This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sort a list of dictionary objects by a key - case sensitive | |
from operator import itemgetter | |
mylist = sorted(mylist, key=itemgetter('name')) | |
# Sort a list of dictionary objects by a key - case insensitive | |
mylist = sorted(mylist, key=lambda k: k['name'].lower()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# this gist can be used to list all targets, or - more correctly - rules, | |
# that are defined in a Makefile (and possibly other included Makefiles) | |
# and is inspired by Jack Kelly's reply to a StackOverflow question: | |
# | |
# http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make/3632592#3632592 | |
# | |
# I also found this script - http://www.shelldorado.com/scripts/cmds/targets - which does | |
# something similar using awk, but it extracts targets from the "static" rules from a single | |
# Makefile, meaning it ignores any included Makefiles, as well as targets from "dynamic" rules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################# | |
# Import modules | |
################################################################################# | |
import os | |
import time | |
import sys | |
import socket | |
import string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Wide-open CORS config for nginx | |
# | |
location / { | |
if ($request_method = 'OPTIONS') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from boto.ec2.autoscale import AutoScaleConnection | |
from boto.ec2.autoscale import LaunchConfiguration | |
conn_as = AutoScaleConnection(AWS_ACCESS_KEY, AWS_SECRET_KEY) | |
#For a complete list of options see http://boto.cloudhackers.com/ref/ec2.html#boto.ec2.autoscale.launchconfig.LaunchConfiguration | |
lc = LaunchConfiguration(name='my-launch-config-name', image_id='ami-123456', | |
key_name='webserver-access-key', | |
security_groups=['webserver-security-group'], | |
instance_type='t1.micro', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#For a complete list of options see http://boto.cloudhackers.com/ref/ec2.html#boto.ec2.autoscale.group.AutoScalingGroup | |
ag = AutoScalingGroup(group_name='webserver-asg', load_balancers=['my-lb'], | |
availability_zones=['us-east-1a','us-east-1b', 'us-east-1c'], | |
launch_config='my-launch-config-name', min_size=2, max_size=20) | |
conn_as.create_auto_scaling_group(ag) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#For a complete list of options see http://boto.cloudhackers.com/ref/ec2.html#boto.ec2.autoscale.policy.ScalingPolicy | |
scalingUpPolicy = ScalingPolicy(name='webserverScaleUpPolicy', | |
adjustment_type='ChangeInCapacity', | |
as_name='webserver-asg', | |
scaling_adjustment=2, | |
cooldown=180) | |
scalingDownPolicy = ScalingPolicy(name='webserverScaleDownPolicy', | |
adjustment_type='ChangeInCapacity', | |
as_name='webserver-asg', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from boto.ec2.elb import ELBConnection | |
from boto.ec2.elb import HealthCheck | |
conn_elb = ELBConnection(AWS_ACCESS_KEY, AWS_SECRET_KEY) | |
#For a complete list of options see http://boto.cloudhackers.com/ref/ec2.html#module-boto.ec2.elb.healthcheck | |
hc = HealthCheck('healthCheck', | |
interval=20, | |
target='HTTP:80/index.html', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The MIT License (MIT) | |
Copyright (c) 2011 Numan Sachwani | |
Permission is hereby granted, free of charge, to any person obtaining a copy of | |
this software and associated documentation files (the "Software"), to deal in | |
the Software without restriction, including without limitation the rights to | |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | |
of the Software, and to permit persons to whom the Software is furnished to do | |
so, subject to the following conditions: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# virtualenv-auto-activate.sh | |
# | |
# Installation: | |
# Add this line to your .bashrc or .bash-profile: | |
# | |
# source /path/to/virtualenv-auto-activate.sh | |
# | |
# Go to your project folder, run "virtualenv .venv", so your project folder | |
# has a .venv folder at the top level, next to your version control directory. |
OlderNewer