Skip to content

Instantly share code, notes, and snippets.

# 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())
@pvdb
pvdb / list_targets.sh
Last active November 8, 2023 08:18
List all targets (sometimes incorrectly referred to as "goals") in a GNU Makefile
#
# 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
@liamf
liamf / autoscale_sample
Created May 6, 2011 12:05
Demonstrates using patched boto to create an autoscaling group of servers, scaled up/down by CPU Utilisation
#################################################################################
# Import modules
#################################################################################
import os
import time
import sys
import socket
import string
@michiel
michiel / cors-nginx.conf
Created July 5, 2011 10:41
Wide-open CORS config for nginx
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
@numan
numan / lc_boto.py
Created July 13, 2011 21:43
Setting up a launch configuration using boto
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',
@numan
numan / asg_boto.py
Created July 14, 2011 16:20
create an auto scaling group
#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)
@numan
numan / sp_boto.py
Created July 16, 2011 17:45
Setting up a scaling policy using boto
#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',
@numan
numan / lb_boto.py
Created July 16, 2011 21:29
Create a load balancer using the boto API
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',
@numan
numan / autoscaling_boto.py
Created July 17, 2011 00:42
Example of setting up AWS auto scaling using boto API
"""
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:
@robbles
robbles / virtualenv-auto-activate.sh
Last active November 7, 2023 14:01 — forked from codysoyland/virtualenv-auto-activate.sh
virtualenv-auto-activate with support for zsh and virtualenvwrapper
#!/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.