Skip to content

Instantly share code, notes, and snippets.

@eliotk
eliotk / gist:50a73a50d718818dec18
Created May 22, 2015 15:17
Install ansible on Ubuntu. Useful in a sh script for packer setup pre Ansible runs
sudo apt-get install software-properties-common -y
sudo apt-add-repository ppa:ansible/ansible -y
sudo apt-get update -y
sudo apt-get install ansible -y
@eliotk
eliotk / gist:aeb44b510325aa7378fe
Last active August 29, 2015 14:16
centos openstack image changes to auto grow disk
sudo yum install cloud-utils -y
@eliotk
eliotk / gist:93f6b49a208b1e7d6999
Created February 6, 2015 22:20
ansible: iterate through list of values in a jinja template
{% for k,v in hostvars[inventory_hostname].iteritems() %}
{{ k }}: {{ v }}
{% endfor %}
@eliotk
eliotk / gist:e2449b69221b79c67320
Last active August 29, 2015 14:14
facter custom external facts dir
/etc/facter/facts.d/ # when admin/root
<HOME DIRECTORY>/.facter/facts.d/ # when not running facter as admin
# why is it so hard to google for that!?
@eliotk
eliotk / gist:6ce8ff5a6a6ed6b45876
Created January 23, 2015 18:01
List files and directories showing chmod numerical format. Add to ~/.bashrc or ~/.bash_profile or ~/.zshrc ...
alias cls="ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr(\$1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(\"%0o \",k);print}'"
@eliotk
eliotk / gist:f0a65984010a84559d5f
Created January 23, 2015 15:39
Set secret environment variable on the fly while hiding it from history and from the console output
read -s; export OS_PASSWORD=$REPLY
@eliotk
eliotk / gist:7744806
Last active October 6, 2020 13:00
A ruby script to parse My Tracks kml files and aggregate the summary data into one CSV file to chart changes in time series (or otherwise)
require 'nokogiri'
require 'csv'
kml_path = '/path/to/Google Drive/My Tracks/'
def kml_file_paths path
Dir.glob(path + "*.kml")
end
csv = CSV.open('mytracks.csv', "wb")
@eliotk
eliotk / exim_queue_email_alerts.py
Last active December 15, 2015 23:19
A simple script for triggering an email alert to an administrator when the exim mail queue count exceeds a certain threshold
import subprocess
import string
# import smtplib for sending email
import smtplib
# execute exim queue count command
proc = subprocess.Popen(['/usr/sbin/exim','-bpc'], stdout=subprocess.PIPE)
mail_count = int(proc.stdout.read())
@eliotk
eliotk / basic-gae-template-rendering.py
Created November 19, 2011 23:49
Code snippets for Django-powered layouts in Python blog post at eliotk.net
template_values = {
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
@eliotk
eliotk / main.py
Created November 19, 2011 23:00
A Python function to render a django view file with optional template dict of parameters passed in. This output could then be passed to a more general layout file using template again. Based on Usage in Google App Engine
import os
from django.template import Template, Context
from google.appengine.ext.webapp import template
def render_view(view_name, template_dict = {}):
path = os.path.join(os.path.dirname(__file__), view_name)
f = open(path, 'r')
view_str = f.read()
t = Template(view_str)
return t.render(Context(template_dict))