Skip to content

Instantly share code, notes, and snippets.

View flyte's full-sized avatar
🎯
Focusing

Ellis Percival flyte

🎯
Focusing
  • London
View GitHub Profile
@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 / 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 / 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 / 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 / .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 / 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 / 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 / repocheck.py
Created April 17, 2014 19:51
Check all git repositories in a directory to see if they're clean or dirty.. Tested on: GitPython==0.1.7 argparse==1.2.1 prettytable==0.7.2
import argparse
import os
import git
from prettytable import PrettyTable
if __name__ == "__main__":
p = argparse.ArgumentParser()
p.add_argument("base_dir")
args = p.parse_args()
@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 / pluralise.py
Last active June 12, 2017 19:24
Pluralise word (add 's') when i != 1
In [1]: s = lambda i: "s"[i==1:]
In [2]: for i in range(0, 5):
...: print "I have %d apple%s" % (i, s(i))
...:
I have 0 apples
I have 1 apple
I have 2 apples
I have 3 apples
I have 4 apples