Skip to content

Instantly share code, notes, and snippets.

View rikwatson's full-sized avatar

Rik Watson rikwatson

View GitHub Profile
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
import os
import git
'''
pip install azure-devops
pip install gitpython
'''
@rikwatson
rikwatson / Approve-PowershellScripts.ps1
Last active April 1, 2019 13:22
Approve a Powershell script for deployment
# Approve-PowershellScripts.ps1
#
# requires -version 3
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$powershellFiles = Get-ChildItem -Recurse $here -Include '*.ps*'
$nonTestFiles = $powershellFiles | Where-Object { -Not ($_.Name.EndsWith('.Tests.ps1')) }
$testFiles = $powershellFiles | Where-Object { $_.Name.EndsWith('.Tests.ps1') }
$functions = Get-ChildItem -Recurse $here -Include *.ps1 | Where-Object { $_ -notmatch ".Tests.ps1" }
@rikwatson
rikwatson / pester-example.ps1
Created April 1, 2019 13:18
Pester Powershell Example of structure
Describe "Description Name" `
{
Context "Context Name #1" `
{
It "..." { ... }
}
Context "Context Name #2" `
{
It "..." { ... }
@rikwatson
rikwatson / powershell-101.ps1
Created April 1, 2019 13:06
Powershell 101
#requires -version 4
get-childitem variable:
get-module -ListAvailable
get-module psake
<#
Powershell 101
@rikwatson
rikwatson / chafifi.py
Created April 1, 2019 12:57
This could be good for detecting bit rot in file systems.
#! /usr/bin/env python
# 2012-01-15: Modified by Adam Porter <adam@alphapapa.net>
# Based on md5verify.py by Wil Clouser
# <http://micropipes.com/blog/2011/01/30/md5verify-a-script-to-automatically-verify-file-integrity/>
# <https://github.com/clouserw/scripts/blob/master/md5verify.py>
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
@rikwatson
rikwatson / httpProxy.py
Created April 1, 2019 12:48
HTTP Proxy in Python
"""
From: http://wiki.python.org/moin/Twisted-Examples
Via: http://stackoverflow.com/questions/4412581
"""
from twisted.web import proxy, http
from twisted.internet import reactor
from twisted.python import log
import sys
log.startLogging(sys.stdout)
@rikwatson
rikwatson / flatten.py
Created April 1, 2019 12:46
How to flatten a tuple in Python
# Basically the problem was that I wanted to create a flat tuple from a tuple and a single value like such:
#
val = 3
tup = ( 'a', 3.14, "zzz" )
# I wanted this:
#
# ( 3, 'a', 3.14, "zzz" )
#
# not this:
@rikwatson
rikwatson / thumbnail.py
Created April 1, 2019 12:45
Python Image / Thumbnail Resizer
import os, sys
import Image
size = 128, 128
for infile in sys.argv[1:]:
outfile = os.path.splitext(infile)[0] + ".thumbnail"
if infile != outfile:
try:
im = Image.open(infile)
@rikwatson
rikwatson / domParser.py
Created April 1, 2019 12:44
Basic XML DOM parsing
from xml.dom.minidom import parse
dom = parse("foo.xml") # or dom = parseString( "<myxml>Some data <empty/> some more data</myxml>" )
for node in dom.getElementsByTagName('bar'): # visit every node <bar />
print node.toxml()
@rikwatson
rikwatson / common.py
Created April 1, 2019 12:43
Common code for V2 & v3
if sys.version_info[0] == 3:
# Python 3 imports.
from urllib.parse import urlparse, parse_qs
else:
# Python 2 imports.
from urlparse import urlparse, parse_qs