Skip to content

Instantly share code, notes, and snippets.

View tom-henderson's full-sized avatar
🇳🇿

Tom Henderson tom-henderson

🇳🇿
View GitHub Profile
import requests
from bs4 import BeautifulSoup as bs
locations = ['Devonport', 'Takapuna']
data = {}
for location in locations:
url = "https://www.tenancy.govt.nz/rent-bond-and-bills/market-rent/?location={}".format(location)
html = requests.get(url).text
soup = bs(html, "html.parser")
class Delta:
def __init__(self,old,new):
newset = set(new.rules)
oldset = set(old.rules)
self.deleted = list(oldset - newset)
self.added = list(newset - oldset)
self.retained = list(oldset & newset)
Get-ADDomainController -Filter * `
| Select Name, IsGlobalCatalog, Site, IPV4Address, `
@{N='SchemaMaster';E={'SchemaMaster' -in $_.OperationMasterRoles}}, `
@{N='DomainNamingMaster';E={'DomainNamingMaster' -in $_.OperationMasterRoles}}, `
@{N='PDCEmulator';E={'PDCEmulator' -in $_.OperationMasterRoles}}, `
@{N='RIDMaster';E={'RIDMaster' -in $_.OperationMasterRoles}}, `
@{N='InfrastructureMaster';E={'InfrastructureMaster' -in $_.OperationMasterRoles}} `
| FT -AutoSize
@tom-henderson
tom-henderson / pip.sh
Created August 25, 2017 04:09
Installing / uninstalling packages with pip
# Save current installed packages
pip freeze > requirements.txt
# Install packages from requirents.txt
pip install -r requirements.txt
# Remove packages not in requirements.txt
pip freeze | grep -v -f requirements.txt - | xargs pip uninstall -y
@tom-henderson
tom-henderson / show-computer-groups.ps1
Created August 24, 2017 03:55
Get computer's group membership without using the AD module
$searcher = [adsisearcher]"(&(objectCategory=computer)(cn=$env:COMPUTERNAME))"
$searcher.FindOne().Properties.memberof -replace '^CN=([^,]+).+$','$1'
@tom-henderson
tom-henderson / Get-AvailableUpdates.ps1
Created August 23, 2017 01:17
Get pending windows updates.
function Get-AvailableUpdates {
[CmdletBinding()]
Param()
$wu_session = New-Object -ComObject Microsoft.Update.Session
$wu_searcher = $wu_session.CreateUpdateSearcher()
$updates = $wu_searcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
return $updates.Updates `
| Select Title, RebootRequired, IsInstalled, IsDownloaded, IsHidden, IsPresent, `
@{Name='KbArticleIds';Expression={$_.KbArticleIds}}, `
@tom-henderson
tom-henderson / set-hostname.sh
Created August 8, 2017 07:05
Set hostname on OSX
#!/bin/bash -eux
hostname=$1
scutil --set HostName ${hostname}
scutil --set ComputerName ${hostname}
scutil --set LocalHostName ${hostname}
@tom-henderson
tom-henderson / plex_show_status.py
Created June 10, 2017 22:52
Show current status of TV shows on a Plex server
from plexapi.server import PlexServer
from plexapi.myplex import MyPlexAccount
from pytvdbapi import api as tvdbapi
API_KEY = 'TVDB API Key'
USERNAME = 'Plex Username'
PASSWORD = 'Plex Password'
SERVER_NAME = 'Plex Server Name'
@tom-henderson
tom-henderson / unifi-devices.py
Last active February 7, 2018 10:01
Get a list of connected devices from a Unifi controller
import sys
import json
import requests
def get_clients():
PORTAL_URL = 'https://0.0.0.0:8443/'
PORTAL_LOGIN_PARAMS = {
'username': '',
'password': '',
@tom-henderson
tom-henderson / requests.py
Created June 10, 2017 22:30
Python HTTP POST with JSON body using api.imgflip.com as example
import requests
url = 'https://api.imgflip.com/caption_image'
payload = {
'username': "imgflip_hubot",
'password': "imgflip_hubot",
'template_id': "101470",
'text1': 'Robots',