Skip to content

Instantly share code, notes, and snippets.

@albal
albal / livingroom.yaml
Last active January 15, 2023 18:46
MAX7219 Display with ESPHome
esphome:
name: livingroom
esp8266:
board: esp01_1m
# Enable logging
logger:
# Enable Home Assistant API
@albal
albal / github_latest_download.sh
Created September 3, 2022 17:19
Download the latest version of an artifact from github
#!/bin/bash
ARTIFACT="PocketMine-MP.phar"
ACCOUNT="pmmp"
PROJECT="PocketMine-MP"
LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/${ACCOUNT}/${PROJECT}/releases/latest)
LATEST_VERSION=$(echo ${LATEST_RELEASE} | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
ARTIFACT_URL="https://github.com/${ACCOUNT}/${PROJECT}/releases/download/${LATEST_VERSION}/${ARTIFACT}"
if [ -f version.txt ]; then
CURRENT_VERSION=$(<version.txt)
else
@albal
albal / third.py
Created January 19, 2021 18:25
Make a third from the numbers 1 - 9
# You have the numbers 1 - 9, arrange them to make a third
from itertools import permutations
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]
top = permutations(nums, 4)
bottom = permutations(nums, 5)
top_vals = list(top)
bottom_vals = list(bottom)
count = 0
@albal
albal / scramble.py
Created April 5, 2020 01:09
Scramble Name
import sys, time, random, string
name = "Daniel Michael Blake Day-Lewis"
length = len(name)
output = ""
def randomString(stringLength=10):
"""Generate a random string of fixed length """
letters = string.ascii_lowercase
@albal
albal / trx-to-junit.xslt
Created June 18, 2019 11:28 — forked from cdroulers/trx-to-junit.xslt
Transform dotnet test output (TRX) to jUnit format for CI purposes.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a ="http://microsoft.com/schemas/VisualStudio/TeamTest/2006" xmlns:b ="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" >
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<testsuites>
<xsl:variable name="buildName" select="//a:TestRun/@name"/>
<xsl:variable name="numberOfTests" select="count(//a:UnitTestResult/@testId) + count(//b:UnitTestResult/@testId)"/>
<xsl:variable name="numberOfFailures" select="count(//a:UnitTestResult/@outcome[.='Failed']) + count(//b:UnitTestResult/@outcome[.='Failed'])" />
<xsl:variable name="numberOfErrors" select="count(//a:UnitTestResult[not(@outcome)]) + count(//b:UnitTestResult[not(@outcome)])" />
<xsl:variable name="numberSkipped" select="count(//a:UnitTestResult/@outcome[.!='Passed' and .!='Failed']) + count(//b:UnitTestResult/@outcome[.!='Passed' and .!='Failed'])" />
@albal
albal / evac_maint.ps1
Created November 23, 2018 14:36
VMware PowerCLI PowerShell script to shutdown VMs that would be left running on an ESX host entering maintenance mode
# Connect to vCenter
Connect-VIServer -Server 192.168.0.10 -user administrator@vsphere.local -password <password>
# Get the HostId of the VM Host entering maintenance mode - assuming only one Host in a Data Center at a time
$hostid = Get-Task Running | where {$_.name -eq "EnterMaintenanceMode_Task"} | select ObjectId
# If there is a result then shutdown all the VMs that match the name given
if (-not ([string]::IsNullOrEmpty($hostid)))
{
# Get the VM Host name by the ObjectId
$esxhost = Get-VMHost | where {$_.Id -eq $hostid.ObjectId}
# Shutdown the VM given by the wildcard - in this case any machine begninning with Gluster running on that host
@albal
albal / apt-check
Created July 16, 2018 10:09
Ubuntu compatible update scripts for Centos
#!/bin/bash
# /usr/lib/update-notifier/apt-check
val=$(yum check-update --quiet | grep '^[a-Z0-9]' | wc -l)
echo "${val};${val}"
#!/usr/bin/env python
import datetime
import holidays
import calendar
workingdays_year = 0
uk_holidays=holidays.UK()
this_year=datetime.datetime.now().year
for month in range (1, 13):
weekdays = []
apt-get install build-essential libssl-dev
wget "https://downloads.sourceforge.net/project/ibmtpm20tss/ibmtss1119.tar.gz?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fibmtpm20tss%2Ffiles%2Flatest%2Fdownload&ts=1527166281"
mv ibmtss1119.tar.gz\?r\=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fibmtpm20tss%2Ffiles%2Flatest%2Fdownload\&ts\=1527166281 ibmtss1119.tar.gz
mkdir ibm-tss
cd ibm-tss
cp ../ibmtss1119.tar.gz .
tar -zxvf ibmtss1119.tar.gz
cd utils
make
find . -newermt `date +"%Y-%m-%d"` -print0 | xargs -0 -I {} mv {} /usr/local/sbin
@albal
albal / random_date.py
Created May 23, 2018 09:34
Python random past date
#!/usr/bin/env python
import random
import time
import datetime
def strTimeProp(format, prop):
stime = time.mktime(time.strptime((datetime.datetime.now()+datetime.timedelta(-3650)).strftime(format), format))
etime = time.mktime(time.strptime(datetime.datetime.now().strftime(format), format))
ptime = stime + prop * (etime - stime)
return time.strftime(format, time.localtime(ptime))