Skip to content

Instantly share code, notes, and snippets.

View flyte's full-sized avatar
🎯
Focusing

Ellis Percival flyte

🎯
Focusing
  • London
View GitHub Profile
import serial
import socket
import argparse
import sys
from time import sleep
NEWLINE = "\r\n"
def connect_tcp(sock, target):
@flyte
flyte / cb_versions.py
Created April 3, 2014 16:19
Loop through cookbook directories and find out which versions you've got.
import os
from distutils.version import LooseVersion as Version
if __name__ == "__main__":
cb_versions = {}
for cb_dir in os.listdir("."):
if cb_dir.startswith("cookbooks"):
print "Scanning %s" % cb_dir
for cb in os.listdir(cb_dir):
if not os.path.isdir(os.path.join(cb_dir, cb)):
@flyte
flyte / publish_input.py
Created August 14, 2014 14:16
Publish the changes of an input from a Raspberry Pi with PiFace digital IO board over ZeroMQ
import zmq
import pifacedigitalio
import argparse
from time import sleep
if __name__ == "__main__":
p = argparse.ArgumentParser()
p.add_argument("input", type=int)
p.add_argument("prefix", type=str)
p.add_argument("port", type=int)
@flyte
flyte / vagrant_status.py
Created November 11, 2014 12:38
Find all Vagrantfiles and check their status
from subprocess import check_output
import argparse
import os
import re
BASE_DIR = os.path.abspath(".")
STATUS_LINE_RE = r"^(\w+?)\s+?(\w.+?)\s\((.+?)\)$"
if __name__ == "__main__":
p = argparse.ArgumentParser()
@flyte
flyte / .bashrc
Last active August 29, 2015 14:17
Add this to .bashrc to make functions to create and enable virtualenvs based on the current directory name.
mkenv() {
mkvirtualenv $(basename $(pwd))
}
wkon() {
workon $(basename $(pwd))
}
rmenv() {
rmvirtualenv $(basename $(pwd))
@flyte
flyte / delete_merge_normal_attr.sh
Created March 31, 2015 13:18
Knife code for deleting a specific persistent 'normal' attribute from a specific node.
knife exec -E "nodes.transform('name:ss-virtualserver03') {|n| n.normal_attrs[:vccs_v3][:override_settings].delete(:merge) rescue nil}"
@flyte
flyte / listenudp.py
Created May 14, 2015 13:37
Listen for and print out the contents of UDP packets received on a specific port.
import socket
import argparse
if __name__ == "__main__":
p = argparse.ArgumentParser()
p.add_argument("port", type=int)
args = p.parse_args()
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@flyte
flyte / new_gist_file_0
Created May 15, 2015 15:39
Remove a passphrase from an openssl private key with correct permissions, supplying the password on the command line
(umask 077; openssl rsa -in private.key.secure -out private.key -passin pass:yourpassword)
@flyte
flyte / jenkins_plugins_enabled.py
Created May 22, 2015 16:32
Returns a JSON list of Jenkins plugins as keys and a boolean value representing their enabled status.
import json
import os
import argparse
PLUGIN_EXTENSIONS = ("hpi", "jpi")
def plugin_name(path):
file_name = os.path.basename(path)
@flyte
flyte / log_function_call.py
Created November 3, 2015 12:32
Function decorator to output the function name and arguments to logger.debug
def log_function_call(func):
"""
Function decorator to output the function name and arguments to logger.debug
"""
def inner(*args, **kwargs):
args_str = ", ".join([str(x) for x in args]) if args else ""
kwargs_str = ", ".join(
["%s=%s" % (str(key), str(value)) for key, value in kwargs.items()]) if kwargs else ""
all_args_str = args_str
if all_args_str and kwargs_str: