Skip to content

Instantly share code, notes, and snippets.

View EronHennessey's full-sized avatar

Eron Hennessey EronHennessey

View GitHub Profile
@EronHennessey
EronHennessey / amazon-ec2-ftp.md
Last active August 22, 2016 02:58 — forked from gunjanpatel/amazon-ec2-ftp.md
amazon ec2 LAMP and FTP installation and setup
@EronHennessey
EronHennessey / analyze_dir.py
Created January 26, 2016 08:22
An investigation of file system entries in python.
#!/usr/bin/env python
import sys, os, shutil
# Check to see what entities are in the file system and categorize them by
# type.
def analyze_path(path):
"""Get the file system entries in a path and categorize them."""
@EronHennessey
EronHennessey / mobi.py
Last active August 29, 2015 14:09 — forked from kroger/mobi.py
# -*- coding: utf-8 -*-
"""
sphinx.builders.mobi
~~~~~~~~~~~~~~~~~~~~
Build mobi files.
Originally derived from epub.py.
:copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
@EronHennessey
EronHennessey / camel2snake.py
Last active August 29, 2015 13:57
Convert CamelCase (or camelCase) to snake_case in Python
#!/usr/bin/env python
import sys
import re
def camel2snake(text, sep=r'_'):
"""Convert *text* from CamelCase (or camelCase) into snake_case."""
rebounds = [r'([a-z])([A-Z])', r'([A-Z])([A-Z])']
underscored_text = str(text)
for b in rebounds:
underscored_text = re.sub(b, (r'\g<1>'+ sep + r'\g<2>'), underscored_text)
@EronHennessey
EronHennessey / publish_to_s3.rb
Created October 27, 2013 03:09
Publish a local file to an AWS S3 bucket (make it public, give it a URL).
require 'aws-sdk'
require 'yaml'
CONFIG_FILE_NAME = 'aws-config.txt'
def do_confirm(phrase)
print "#{phrase} (Y/N): "
# you *must* use $stdin with gets if you have command-line arguments.
# Otherwise, gets receives streaming input and doesn't wait for the terminal.
a = $stdin.gets.strip.downcase
@EronHennessey
EronHennessey / list_buckets_contents_s3.rb
Last active December 26, 2015 15:49
List the S3 buckets for your AWS account/region. Can also list the contents of a bucket or the contents of a file, depending on how many command-line arguments you supply. ;) Uses the AWS SDK for Ruby.
# List the S3 buckets that are available for the user identified by either
# `aws-config.txt` or in the environment.
require 'aws-sdk'
require 'yaml'
CONFIG_FILE_NAME = 'aws-config.txt'
# Load aws-config.txt to see if there are AWS credentials there.
#
# We're expecting a YAML-formatted file like this:
@EronHennessey
EronHennessey / json2xml.rb
Created October 26, 2013 22:51
Converts JSON to XML. Can use either filenames passed as arguments, or operates on standard input. Uses the 'xmlsimple' library for XML output.
require 'json'
require 'xmlsimple'
json_file, xml_file = ARGV
json_text = nil
unless json_file.nil?
if File.exist?(json_file)
json_text = File.new(json_file, 'r').read
@EronHennessey
EronHennessey / json2yaml.rb
Created October 26, 2013 22:49
Converts JSON to YAML. Works either with filenames passed in as arguments, or by piping standard input.
require 'json'
require 'yaml'
json_file, yaml_file = ARGV
json_text = nil
unless json_file.nil?
if File.exist?(json_file)
json_text = File.new(json_file, 'r').read
@EronHennessey
EronHennessey / cleanjson.rb
Created October 26, 2013 22:46
Clean JSON. Takes messy JSON and makes it much nicer looking. Use it with a json file passed in as a command-line argument or via standard input, thanks to the magic of Ruby's built-in 'json' library and pretty_generate
# Clean JSON. Takes messy JSON and makes it much nicer looking.
#
# Usage:
#
# ruby cleanjson.rb <infile> <outfile>
#
# Reads the JSON-formatted text in <infile> and outputs the cleaned JSON to
# <outfile>.
#
# Both arguments are optional, but you cannot specify an <outfile> without
@EronHennessey
EronHennessey / check4siteupdate.py
Created October 15, 2013 18:21
A Python script that checks the last-modified date of a URL against the last-modified date of a previous look at it. If the last-modified date has changed, it emails the designated address, saying so. This could be used as a cron job to periodically check for updates of any page on the internet.
# check for an update on a web-page, and email the user
import httplib
import sys
import pickle
from datetime import datetime
import smtplib
from email.mime.text import MIMEText
import yaml
def email_user(cur_data, email_from, email_to):