Skip to content

Instantly share code, notes, and snippets.

View iMilnb's full-sized avatar

iMil iMilnb

View GitHub Profile
@iMilnb
iMilnb / subspam.py
Created August 28, 2015 00:01
Automatic SpamCop report validation with python mechanize
import mechanize
br = mechanize.Browser()
br.set_handle_robots(False)
br.open("http://www.spamcop.net/")
br.select_form(nr=0)
br.form['username']='your@spamcop.registered.email'
br.form['password']='yourSpamCopPassword'
@iMilnb
iMilnb / snsread.py
Created August 2, 2015 20:20
Basic Flask snippet to handle AWS SNS messages and subscription
from flask import Flask, request
import requests
import json
app = Flask(__name__)
def msg_process(msg, tstamp):
js = json.loads(msg)
msg = 'Region: {0} / Alarm: {1}'.format(
js['Region'], js['AlarmName']
@iMilnb
iMilnb / boto3_hands_on.md
Last active October 19, 2022 09:15
Programmatically manipulate AWS resources with boto3 - a quick hands on

boto3 quick hands-on

This documentation aims at being a quick-straight-to-the-point-hands-on AWS resources manipulation with [boto3][0].

First of all, you'll need to install [boto3][0]. Installing it along with [awscli][1] is probably a good idea as

  • [awscli][1] is boto-based
  • [awscli][1] usage is really close to boto's
@iMilnb
iMilnb / userdata.sh
Last active October 11, 2016 15:45
Transform Debian Jessie AMI to `sysvinit`
# Simply add the following to the Userdata script so the
# instance bootstrap sequence transforms the debian jessie
# systemd init to good old sysvinit.
# initial method from
# http://without-systemd.org/wiki/index.php/How_to_remove_systemd_from_a_Debian_jessie/sid_installation
# but using a safer and actually working `cat ><<EOF` method
apt-get -y install sysvinit-core sysvinit sysvinit-utils
apt-get remove --purge --auto-remove systemd
cat >/etc/apt/preferences.d/systemd<<EOF
Package: systemd
@iMilnb
iMilnb / grub_default_kernel
Last active August 29, 2015 14:24
Change the default boot kernel with `grub` 2.0.2beta
mykern=3.14.43-foo-bar-0.1-baz
dpkg -i linux-image-${mykern}_amd64.deb
sed -i 's/^GRUB_DEFAULT=.*/GRUB_DEFAULT=saved/' /etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg
UUID=`blkid -s UUID -o value /dev/xvda1`
grub-set-default "gnulinux-advanced-$UUID>gnulinux-$mykern-advanced-$UUID"
@iMilnb
iMilnb / gist:ba7b46dfc854544bf3c8
Last active September 4, 2018 19:29
Dynamic ipsec and racoon configuration generation for AWS EC2 VPN using boto3 and Jinja2
#!/usr/bin/env python
# $ cat ipsec_conf.tmpl
# {#
#
# cgw_in_addr: customer_gateway tunnel_inside_address ip_address
# cgw_in_cidr: customer_gateway tunnel_inside_address network_cidr
# vgw_in_addr: vpn_gateway tunnel_inside_address ip_address
# vgw_in_cidr: vpn_gateway tunnel_inside_address network_cidr
# cgw_out_addr: customer_gateway tunnel_outside_address
@iMilnb
iMilnb / vpc_vpn_ec2.py
Last active June 16, 2018 09:23
Dynamic Troposphere + boto3 template that creates a complete and functional VPC through AWS CloudFormation
#!/usr/bin/env python
from troposphere import Join, Output
from troposphere import Parameter, Ref, Tags, Template
from troposphere.ec2 import PortRange
from troposphere.ec2 import NetworkAcl
from troposphere.ec2 import Route
from troposphere.ec2 import VPCGatewayAttachment
from troposphere.ec2 import SubnetRouteTableAssociation
from troposphere.ec2 import Subnet
@iMilnb
iMilnb / ec2.py
Created May 27, 2015 12:29
AWS EC2 simple manipulation script using python and boto3
#!/usr/bin/env python
# Simple [boto3](https://github.com/boto/boto3) based EC2 manipulation tool
#
# To start an instance, create a yaml file with the following format:
#
# frankfurt:
# - subnet-azb:
# - type: t2.micro
# image: image-tagname
@iMilnb
iMilnb / gist:b09f45e112b226b97a36
Last active December 4, 2017 12:46
Minimalistic jinja2-based page generator
import sys
import markdown
import yaml
import os
from jinja2 import Environment, FileSystemLoader
with open(sys.argv[2], 'r') as f:
content = yaml.safe_load(f.read())
for k in content:
@iMilnb
iMilnb / gist:7604f04223d44a3e13af
Last active June 17, 2023 16:14
Keep track of Twitter "unfollowers"
#!/bin/sh
# track unfollows on twitter using "t" https://github.com/sferik/t
# usage:
#
# to check if any of your followers has stopped following you since the last
# time the script wall called, use:
# $ this_script followers
#
# to check if YOU stopped following someone (it appears many of us witnessed