Skip to content

Instantly share code, notes, and snippets.

@sduff
sduff / rma.py
Created May 17, 2023 09:12
Rolling Moving Average
def r(new_value, old_values):
if len(old_values) > 10:
old_values.pop(0)
old_values.append(new_value)
average = sum(old_values) / len(old_values)
return average, old_values
history = []
for i in range(100):
@sduff
sduff / rules.py
Last active March 30, 2022 23:24
Simple rules engine in python using eval and exec
#!/usr/local/bin/python3
rules = [
[
# A required field and default value
'not "replication_factor" in configuration',
'configuration["replication_factor"] = 1'
],
[
# production environments require at least 6 partitions
@sduff
sduff / ccloud-resource-identifiers-after-terraform.txt
Created October 6, 2021 06:29
Accessing Confluent Cloud resource identifiers after running the terraform provider
# Use jq to read the terraform state file
# all id's
jq '.resources[].instances[].attributes.id?' terraform.tfstate
# all display names
jq '.resources[].instances[].attributes.display_name?' terraform.tfstate
# all environment id's
jq '.resources[].instances[].attributes.environment[]?.id'
@sduff
sduff / gist:f93e42795362552390482414b44dbb5e
Last active March 24, 2021 08:39
ANSI SQL Table joins and set operators - practice at https://livesql.oracle.com/
DROP table a;
DROP table b;
create table a (
aid NUMBER(10),
adiz VARCHAR2(10)
);
create table b (
bid NUMBER(10),
@sduff
sduff / 1001 Video Games You Must Play Before You Die (2011)
Created September 8, 2020 03:00
1001 Video Games You Must Play Before You Die (2011)
## Chapter 1: 1970s
The Oregon Trail
Pong
Breakout
Boot Hill
Combat
Space Invaders
Adventure
Asteroids
Galaxian
@sduff
sduff / surname.txt
Created July 28, 2020 01:51
List of 20 most common Australian surnames
mith
jones
williams
brown
wilson
taylor
johnson
white
martin
anderson
@sduff
sduff / elements.txt
Created July 28, 2020 01:48
List of all elements
Hydrogen
Helium
Lithium
Beryllium
Boron
Carbon
Nitrogen
Oxygen
Fluorine
Neon
@sduff
sduff / webhook.py
Created October 12, 2018 05:38
Splunk alert_webhook with proxy support
import sys
import json
import urllib2
import csv
import gzip
from collections import OrderedDict
def send_webhook_request(url, body, user_agent=None):
if url is None:
@sduff
sduff / .js
Last active October 3, 2017 04:09
Splunk Custom Visualisation code to convert data.fields and data.rows into a hash map
data.rows.map(function (row) {
var _row = {};
for (var f=0; f<data.fields.length; f++) {
fn = data.fields[f].name;
_row[fn] = row[f];
}
return(_row);
});
@sduff
sduff / splunk_modify_saved_search.py
Created September 5, 2017 07:16
Modify a Splunk Saved Search via Python, using Requests
import time # need for sleep
from xml.dom import minidom
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
base_url = 'https://localhost:8089'
username = 'admin'
password = 'changeme'