Skip to content

Instantly share code, notes, and snippets.

View KyleJamesWalker's full-sized avatar
😃
Hello!

Kyle James Walker (he/him) KyleJamesWalker

😃
Hello!
View GitHub Profile
# -*- coding: utf-8 -*-
import argparse
import gzip
import logging
import logging.config
import os
import sys
import zipfile
logger = logging.getLogger(__name__)
@KyleJamesWalker
KyleJamesWalker / rangecounter.py
Created February 7, 2015 01:07
rangecounter.py
'''
Simple class for counting number of occurances in each of the given ranges.
'''
class RangeCounter(object):
def __init__(self, range_list):
# Verify range is sorted
self.range_list = sorted(range_list)
self.counter = [0] * (len(range_list) + 1)
def add(self, view_count):
@KyleJamesWalker
KyleJamesWalker / quick_rename.py
Last active August 29, 2015 14:15
Batch Rename as Parent Directory
import os
def main():
'''Stupidly simple script to rename all files to the name of their
parent_dir directory.
Warning: Be careful when running, this could be bad... Also
make sure your current directory doesn't have anything in
it but folders. Otherwise they'll get renamed to ..extention
@KyleJamesWalker
KyleJamesWalker / Readme_with_items_sequence.md
Last active August 29, 2015 14:15
Ansible with_items_sequence

Very quick with_items_sequence lookup plugin. I needed the ability to create a list of workers on a remoter server, based on the structure these workers could be on differrent autoscale groups, and based on size different worker counts per instance. My playbook creates docker containers that are run via supervisor, but you have to have unique names for each of the containers if you want to have more instances, and I couldn't find a clean way to do this without a new lookup plugin.

Run the playbook to test with: ansible-playbook -i localhost, playbook.yml

Note: This was thrown togehter very quickly, I'll hopfully have some time to expand this plugin with proper documention and error handling.

Very quick with_dict_subelements lookup plugin. This is a cross between with_dict and with_subelements The plugin takes a list of two values, First a dictionary, a string with the path in the dictionary to expand (expects a list).

Run the playbook to test with: ansible-playbook -i localhost, playbook.yml

Note: This was thrown togehter very quickly, I'll hopfully have some time to expand this plugin with proper documention and error handling.

@KyleJamesWalker
KyleJamesWalker / Readme_docker_envs.md
Last active August 29, 2015 14:16
Ansible Docker Environment Lookup Plugin

Quick lookup plugin for ansible. I needed a clean way to pass an unknown amount of local envs via params when creating a docker container, based on the env vars on the CI server.

Run the playbook to test with: ansible-playbook -i localhost, playbook.yml

Note: This was thrown together very quickly, I'll hopfully have some time to expand this plugin with proper documention and error handling.

Note original (non plugin route was) ugly and hacky:

---
@KyleJamesWalker
KyleJamesWalker / packages.md
Created May 22, 2015 16:41
Extra DataDog Agent Libraries (Windows)

If you need an agent check that requires an extra python package one windows simply do the following:

  1. pip/easy install your python package to the core python install.
  2. Add the results of the pip install folders to C:\Program Files (x86)\Datadog\Datadog Agent\files\library.zip
  3. Enjoy!
@KyleJamesWalker
KyleJamesWalker / boot2docker-use-nfs.md
Last active August 29, 2015 14:22
Boot2Docker Please use NFS
@KyleJamesWalker
KyleJamesWalker / multipart.py
Last active October 20, 2016 21:58
Simple Multipart CVS Writer / Multipart S3 Uploader Examples
import csv
import gzip
import sys
import humanfriendly
class MultipartCSVWriter:
def __init__(self, dest_format, fieldnames, max_size,
@KyleJamesWalker
KyleJamesWalker / DecoratedContextManager.py
Created October 30, 2016 17:58
Simple Example of a class with decorator support, context manager support
class DecoratedContextManager:
def __init__(self):
pass
def start(self):
"""Starts, for example opens file.
"""
pass