Skip to content

Instantly share code, notes, and snippets.

@doppiomacchiatto
doppiomacchiatto / README.md
Created October 30, 2017 00:40 — forked from dergachev/README.md
Vagrant tutorial

Vagrant Setup

This tutorial guides you through creating your first Vagrant project.

We start with a generic Ubuntu VM, and use the Chef provisioning tool to:

  • install packages for vim, git
  • create user accounts, as specified in included JSON config files
  • install specified user dotfiles (.bashrc, .vimrc, etc) from a git repository

Afterwards, we'll see how easy it is to package our newly provisioned VM

@doppiomacchiatto
doppiomacchiatto / Vagrantfile
Created October 21, 2017 17:05 — forked from bergantine/Vagrantfile
Vagrant config for basic Python development
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
@doppiomacchiatto
doppiomacchiatto / gist:bcf879b09761fc4871bd623839b4cd52
Created August 27, 2017 18:29 — forked from dpapathanasiou/gist:2790864
Using lxml to parse the Microsoft API translation result from the xml
#!/usr/bin/python
from lxml import etree
def get_text_from_msmt_xml (xml):
"""Parse the xml string returned by the MS machine translation API, and return just the text"""
text = []
doc = etree.fromstring(xml)
for elem in doc.xpath('/foo:string', namespaces={'foo': 'http://schemas.microsoft.com/2003/10/Serialization/'}):
@doppiomacchiatto
doppiomacchiatto / deregister.sh
Created August 17, 2017 06:45 — forked from bpholt/deregister.sh
Stop tasks on ECS Container Instance and Deregister it from ECS Cluster
#!/bin/bash
cluster=default
container_instance= # container instance guid
tasks=$(aws --region us-west-2 ecs list-tasks --container-instance $container_instance --cluster $cluster | jq -r '.taskArns | map(.[40:]) | reduce .[] as $item (""; . + $item + " ")')
for task in $tasks; do
aws --region us-west-2 ecs stop-task --task $task --cluster $cluster
done
aws --region us-west-2 ecs deregister-container-instance --cluster $cluster --container-instance $container_instance
@doppiomacchiatto
doppiomacchiatto / gist:5af36f334c5cfe9f310db84282928224
Created August 14, 2017 22:34 — forked from tjcorr/gist:3baf86051471062b2fb7
CloudFormation to demo etcd-aws-cluster
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "An etcd cluster based off an auto scaling group",
"Mappings" : {
"RegionMap" : {
"eu-central-1" : {
"AMI" : "ami-840a0899"
},
"ap-northeast-1" : {
"AMI" : "ami-6c5ac56c"
## get sqs messages
for idx, item in enumerate(response['Messages']):
# create list of dictionaries to process
self.logger.debug('idx %d', idx)
messages.append(json.loads(item['Body']))
tmp_dict = {'Id': item['MessageId'], 'ReceiptHandle': item['ReceiptHandle']}
self.logger.debug('id: %s', item['MessageId'])
delete_list.insert(idx,tmp_dict)
try:
@doppiomacchiatto
doppiomacchiatto / sqs.js
Created August 9, 2017 00:48 — forked from riston/sqs.js
SQS recursive polling
var aws = require('aws-sdk');
var util = require('util');
var SQS = new aws.SQS({
accessKeyId: 'xxxx',
secretAccessKey: 'xxx',
region: 'xxx',
sslEnabled: false,
paramValidation: true,
convertResponseTypes: true,
@doppiomacchiatto
doppiomacchiatto / sample_sns_event.json
Created August 3, 2017 21:04 — forked from yyolk/sample_sns_event.json
AWS Lambda SNS Sample Event
{
"Records": [
{
"EventVersion": "1.0",
"EventSubscriptionArn": "arn:aws:sns:EXAMPLE",
"EventSource": "aws:sns",
"Sns": {
"SignatureVersion": "1",
"Timestamp": "1970-01-01T00:00:00.000Z",
"Signature": "EXAMPLE",
#count=0
for idx, item in enumerate(list):
print item
#count +=1
#if count % 10 == 0:
if idx % 10 == 0:
print 'did ten'
@doppiomacchiatto
doppiomacchiatto / gist:33e662bf2d7a72abc827defd09cfb670
Last active August 15, 2017 21:06 — forked from griggheo/gist:2698152
dynamodb batchwriteitem in boto
import os
import sys
import subprocess
import re
import optparse
import boto
dynamodb_conn = boto.connect_dynamodb(aws_access_key_id='MY_ACCESS_KEY_ID', aws_secret_access_key='MY_SECRET_ACCESS_KEY')
table_name = 'mytable'
dynamodb_table = dynamodb_conn.get_table(table_name)