Skip to content

Instantly share code, notes, and snippets.

View fermayo's full-sized avatar

Fernando Mayo fermayo

View GitHub Profile
@fermayo
fermayo / gist:7442963
Created November 13, 2013 03:00
Extend django-registration to send HTML emails for activation
class HtmlRegistrationProfile(RegistrationProfile):
class Meta:
proxy = True
def send_activation_email(self, site):
"""Send the activation mail"""
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
ctx_dict = {'activation_key': self.activation_key,
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
@fermayo
fermayo / generate_docker_cert.sh
Last active August 29, 2015 14:01
Generate a key pair for Docker
#!/bin/sh
CERT_PATH="$HOME/.docker"
mkdir -p ${CERT_PATH}
if [ ! -f "$CERT_PATH/key.pem" ]; then
echo "Generating a new certificate in $CERT_PATH..."
openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -subj "/C=US/ST=NewYork/L=NYC/O=Tutum/CN=tutum.user" -keyout ${CERT_PATH}/key.pem -out ${CERT_PATH}/cert.pem >/dev/null 2>&1
echo "This is your new public certificate which you can add to your Tutum account:"
else
echo "WARNING: An existing certificate has been found in $CERT_PATH"
echo "This is your existing public certificate which you can add to your Tutum account:"

Keybase proof

I hereby claim:

  • I am fermayo on github.
  • I am fermayo (https://keybase.io/fermayo) on keybase.
  • I have a public key whose fingerprint is 0B8B 21B9 B16D BE84 04C3 AB8D 66D5 CB05 666D AA4A

To claim this, I am signing this object:

@fermayo
fermayo / ixgbevf-upgrade.sh
Last active August 29, 2015 14:25 — forked from vdm/ixgbevf-upgrade.sh
ixgbevf 2.16.1 upgrade for AWS EC2 SR-IOV "Enhanced Networking" on Ubuntu 14.04 (Trusty) LTS
#/bin/sh
# Run as root!
set -e
apt-get update -q
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enhanced-networking-ubuntu
DEBIAN_FRONTEND=noninteractive apt-get install -y dkms linux-headers-generic
wget "http://sourceforge.net/projects/e1000/files/ixgbevf stable/2.16.1/ixgbevf-2.16.1.tar.gz"
tar zvxf ixgbevf-2.16.1.tar.gz
@fermayo
fermayo / patch-ubuntu_14.04.1-ixgbevf-2.16.1-kcompat.h.patch
Last active December 3, 2015 18:46 — forked from defila-aws/patch-ubuntu_14.04.1-ixgbevf-2.16.1-kcompat.h.patch
patch-ubuntu_14.04.1-ixgbevf-2.16.1-kcompat.h.patch
--- /usr/src/ixgbevf-2.16.1/src/kcompat.h.orig 2015-02-03 18:34:22.901474028 +0000
+++ /usr/src/ixgbevf-2.16.1/src/kcompat.h 2015-02-03 18:35:32.577440102 +0000
@@ -3219,8 +3219,6 @@
#define u64_stats_update_begin(a) do { } while(0)
#define u64_stats_update_end(a) do { } while(0)
#define u64_stats_fetch_begin(a) do { } while(0)
-#define u64_stats_fetch_retry_bh(a) (0)
-#define u64_stats_fetch_begin_bh(a) (0)
#if (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,1))
@fermayo
fermayo / hello-world.yml
Last active November 18, 2015 14:23
training
lb:
image: tutum/haproxy
ports:
- "80:80"
links:
- helloworld
roles:
- global
helloworld:
image: tutum/hello-world
REPO="dockercloud/client-proxy"
alias notary='notary -s https://notary.docker.io -d ~/.docker/trust'
# First you need to import the root key for Docker Cloud
notary key import 70340602d65cb8b39db81ca680269d93272b0925e279ec171c0f33d165977405.key
# Create target key for $REPO
notary init docker.io/$REPO
notary key rotate docker.io/$REPO snapshot -r
@fermayo
fermayo / middleware.py
Created January 18, 2018 18:50
nginx-like access logging middleware for Django 2.0
import logging
import datetime
def access_logging(get_response):
logger = logging.getLogger("access_logging")
def middleware(request):
response = get_response(request)
log_format = '{remote_addr} - {remote_user} [{time_local}] "{request}" {status} {body_bytes_sent} ' \
@fermayo
fermayo / lambda_function.py
Last active February 9, 2023 09:23
Lambda function to trigger a one-off ECS Fargate task
# Adapted from https://lobster1234.github.io/2017/12/03/run-tasks-with-aws-fargate-and-lambda/
import boto3
import os
def lambda_handler(event,context):
client = boto3.client('ecs')
response = client.run_task(
cluster=os.getenv('CLUSTER'),
launchType=os.getenv('LAUNCH_TYPE', 'FARGATE'),
@fermayo
fermayo / lambda_function.py
Last active April 1, 2020 10:37
Lambda function to be called from CodePipeline to start and wait for a one-off ECS task
# Required env vars:
# $CLUSTER: name of the ECS cluster (i.e. `myapp-prod`)
# $TASK_DEFINITION: name and revision of the task definition (i.e. `mytask:1`)
# $SUBNETS: comma-separated list of subnets to place the new task (i.e. `sg-12345678,sg-abcdef12`)
# $SECURITY_GROUPS: comma-separated list of security groups to be used for the new task (i.e. `subnet-12345678`)
import boto3
import os
import traceback