Skip to content

Instantly share code, notes, and snippets.

@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:
@numan
numan / django-crossdomainxhr-middleware.py
Created May 2, 2012 18:32 — forked from vicalejuri/django-crossdomainxhr-middleware.py
Middlware to allow's your django server to respond appropriately to cross domain XHR (postMessage html5 API).
import re
from django.utils.text import compress_string
from django.utils.cache import patch_vary_headers
from django import http
try:
import settings
XS_SHARING_ALLOWED_ORIGINS = settings.XS_SHARING_ALLOWED_ORIGINS
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
@numan
numan / tastypie_caching.py
Created July 28, 2013 00:33
customized cached_with for django-cache-machine to use with django-tastypie
from caching.base import cached_with as official_cached_with
def cached_with(obj, f, f_key, timeout=None):
"""Helper for caching a function call within an object's flush list."""
if hasattr(obj, "exists") and not obj.exists():
return f()
return official_cached_with(obj, f, f_key, timeout=timeout)
@numan
numan / resource.py
Last active May 17, 2016 21:00
Custom model resource for caching django-tastypie responses with django-cache-machine
from caching.invalidation import make_key
from functools import partial
def get_response_key(request):
smooshed = []
cache_keys = request.GET.keys()
cache_keys.sort()
for key in cache_keys:
@numan
numan / schema.json
Last active September 24, 2018 19:59
HRIS Webhook Data Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"users": {
"type": "array",
"items": {
"type": "object",
"properties": {
"hris_id": {