Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
from ruamel import yaml
with open("/node.yaml") as f:
config = yaml.safe_load(f)
@sidja
sidja / get_instance_tag_with_instance_id.py
Created May 17, 2017 08:45
Using Python and Boto3 to get Instance Tag information with instance id
import boto3
def get_instance_name(fid):
"""
When given an instance ID as str e.g. 'i-1234567', return the instance 'Name' from the name tag.
:param fid:
:return:
"""
ec2 = boto3.resource('ec2')
ec2instance = ec2.Instance(fid)
@sidja
sidja / pretty_print_dictionary.py
Created March 16, 2017 05:48
pretty print your dictionary values
def pretty(d, indent=0):
for key, value in d.iteritems():
print '\t' * indent + str(key)
if isinstance(value, dict):
pretty(value, indent+1)
else:
print '\t' * (indent+1) + str(value)
pretty(a, indent=3)
@sidja
sidja / Dockerfile
Created January 23, 2017 02:11
How to change time zone in docker container ubuntu
FROM ubuntu:16.04
ENV TZ=Australia/Melbourne
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN dpkg-reconfigure --frontend noninteractive tzdata
@sidja
sidja / run_shell.py
Created December 22, 2016 02:51
Run shell commands via python
import subprocess
def run(command):
my_env = os.environ.copy()
print(command)
return subprocess.check_output(command, shell=True, env=my_env)
@sidja
sidja / docker_multiple_exec.sh
Created December 21, 2016 00:40
Handy script to execute in all docker containers at once
function docker_exe {
d=($(docker ps | grep -v fluentd | grep -v nginx | grep befit | awk '{print $1}'))
for m in ${d[@]}
do
docker exec -it $m $1
done
}
@sidja
sidja / 0_reuse_code.js
Created December 12, 2016 23:03
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@sidja
sidja / send_mail.py
Created December 12, 2016 03:39
Simple send email script in python
import smtplib
server = smtplib.SMTP('mail.aws.something.local', '25')
#Next, log in to the server
server.login("befit-smtp-dev@aws.local", "DNUkWP3yrg3zEP4STLESGzDuejeW9wtZ")
msg = "Hello again !" # The /n separates the message from the headers
server.sendmail("sid@from_email.com", "siddarth.vijapurapu@to_eamil.com", msg)
@sidja
sidja / ssh_tunnel.sh
Created November 22, 2016 22:45
Tunnel through SSH
#### Port remote host to local tunnel
ssh -L <local_port>:<local_host>:<remote_port> <remote_host> -N
ssh -L 6677:localhost:5432 bishop -N
#or
ssh -L 55477:localhost:22 remotehost -N
@sidja
sidja / bash_replace_sed.sh
Created November 22, 2016 22:30
Bash - Replace line script via sed
find /file/or/directory/path -type f -exec sed -i "s/find_string/replacement_string/g" {} +
# Example
find /home/befitting1/code/befit_ecs/df/Dockerfile_locally -type f -exec sed -i "s/%%PROXY%%/$PROXY/g" {} +