Skip to content

Instantly share code, notes, and snippets.

View simonpainter's full-sized avatar
:atom:
Solve problems & build things

Simon Painter simonpainter

:atom:
Solve problems & build things
View GitHub Profile
@simonpainter
simonpainter / code-review-network-automation-frame.md
Created March 28, 2026 01:45
Code review: network-automation-frame

Code network-automation-frameReview

actions/greet/greet.sh

  • Inconsistent input name is trimmed of whitespace via xargs but greeting is not. Either both inputs should be trimmed or neither should, and the choice should be documented.sanitisation
  • xargs trimming is echo "${name}" | xargs can silently collapse multi-word names with special characters (e.g. "O'Brien" will cause a parse error). Prefer parameter expansion or sed, both of which are quote-safe.fragile
  • Stdout echo is redundant echo "${message}" at the end writes to stdout as well as $GITHUB_OUTPUT. This is harmless but callers should not rely on stdout. Document the intent or remove it.misleading noise
  • No validation of an empty string is accepted and produces, World!. Add a guard consistent with the name check, or document explicitly that an empty greeting is valid.greeting

"""DNS proxy server that resolves Pokemon type queries via the PokeAPI."""
import socketserver
import requests
from dnslib import DNSHeader, DNSRecord, QTYPE, RR, TXT
# Configuration
API_URL = "https://pokeapi.co/api/v2"
DNS_DOMAIN_SUFFIX = ["pokemon", "api2dns", "simonpainter", "com"]
provider "azurerm" {
features {}
subscription_id = var.subscription_id
client_id = var.client_id
client_secret = var.client_secret
tenant_id = var.tenant_id
}
# Bootstrap scripts for VMs
locals {
@simonpainter
simonpainter / gist:d0867ed32c051cb1877d4919bee9f8ad
Created July 17, 2020 12:36
Inserting unique value into DynamoDB list.
$marshaler = new Marshaler();
$UpdateExpression = "
SET #subscribers = list_append(if_not_exists(#subscribers, :empty_list), :subscriber)
";
$ConditionExpression = "
NOT contains (#subscribers,:subscriberStr)
";
from netaddr import IPNetwork, cidr_merge
import re, sys
try:
filename = sys.argv[1]
except:
print("Please specify a file name for input")
sys.exit()
with open (filename, "r") as file:
table = file.read().replace('\n', '')
import json,uuid,time
import boto3
zone = 'XXXXXXXXXXXX'
def lambda_handler(event, context):
if ((event['name'] == "api") or (event['name'] == "www") or (event['name'] == "")):
return {
"statusCode": 403,
import json, uuid, time
import boto3
zone = 'XXXXXXXXXXXXX'
def lambda_handler(event, context):
dynamodb = boto3.client('dynamodb')
if ((event['name'] == "api") or (event['name'] == "*") or (event['name'] == "www") or (event['name'] == "")):
return {
import requests, urllib
class Forecast:
def __init__(self,apikey):
self.apikey=apikey
self.parameters={}
self.timeparam=""
def get(self,latitude,longitude):
self.latitude = latitude
self.longitude = longitude
self.encodedparameters = urllib.urlencode(self.parameters)
@simonpainter
simonpainter / IFTTT.py
Created August 3, 2017 18:38
Trigger IFTTT from Python
class MakerTrigger(object):
def __init__(self,key,trigger):
self.key = key
self.trigger = trigger
self.maker = “https://maker.ifttt.com/trigger/” + self.trigger + “/with/key/” + self.key
def alert(self,value1=0,value2=0,value3=0):
self.value1 = value1
self.value2 = value2
self.value3 = value3
self.json={“value1”: self.value1, “value2”: self.value2, “value3”: self.value3}