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
from flask import Blueprint
shared_value = None
class RegisteringExampleBlueprint(Blueprint):
'''
Example showing how to access a value for routes
saved in flask's configuration section for all routes in
blueprint.
'''
Quick and dirty code to see if I could figure out the next
larger number with all the same digits of the number passed.
Note: After coming up with the solution I found the following
http://stackoverflow.com/questions/9368205/given-a-number-find-the-next-higher-number-which-has-the-exact-same-set-of-digi
'''
def get_next(the_num):
the_num = str(the_num)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import logging
import logging.handlers
import requests
class BufferingSlackWebHookHandler(logging.handlers.BufferingHandler):
# -*- 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!