Skip to content

Instantly share code, notes, and snippets.

View f-steff's full-sized avatar

Flemming Steffensen f-steff

View GitHub Profile
@f-steff
f-steff / install_packages.py
Created July 21, 2023 09:51
Install Python package at runtime
import pkg_resources
import subprocess
import sys
import importlib
import pprint
def install(package):
print(f'\n=======> Checking status of {package}:', flush=True)
try:
dist = pkg_resources.get_distribution(package)
@f-steff
f-steff / GoogleSheetsDisableF1.user.js
Last active January 2, 2025 23:25
Userscript to intercept F1 on Google Sheets, so that the annoying Help popup can be suppressed.
// ==UserScript==
// @name Google Sheets Suppress F1 Key Preventing Help-Popup
// @namespace https://gist.github.com/f-steff
// @version 1.1
// @description Interception of F1 keypress on Google Sheets and replaces default behavior with nothing.
// @author Flemming Steffensen
// @license MIT
// @match http://docs.google.com/spreadsheets/*
// @match https://docs.google.com/spreadsheets/*
// @include http://docs.google.com/spreadsheets/*
@f-steff
f-steff / PARTS
Created December 3, 2021 12:46
UrJTAG with IRMCK343 on Raspberry Pi
#
# $Id$
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@f-steff
f-steff / swap_bytes.py
Last active November 4, 2021 09:27
Python binary manipulation
def swap_bytes(byte_string):
"""
Swaps every second byte in an string. If string is uneven, the last byte is untouched.
1 2 3 4 becomes 2 1 4 3
1 2 3 4 5 becomes 2 1 4 3 5
"""
return b"".join([(byte_string[i:i + 2])[::-1] for i in range(0, len(byte_string), 2)])
@f-steff
f-steff / RFC5424_Syslog_test.py
Created April 19, 2021 14:14
Python logger to remote RFC 5424 syslog server - with structured data
#!/usr/bin/python
# -*- coding: utf-8 -*-
# https://github.com/jobec/rfc5424-logging-handler
# Documentation: https://rfc5424-logging-handler.readthedocs.io/en/latest/
import sys
import logging
from rfc5424logging import Rfc5424SysLogHandler, Rfc5424SysLogAdapter
logger = logging.getLogger('RFC5424_Syslog_test_ApplicationName')
@f-steff
f-steff / Get_MSbuild_Path.cmd
Created April 14, 2021 07:02
Get path ot installed MSBuild
@echo off
::With MSBuild 2017 and later installed, this command will always provide the correct path to msbuild.exe
FOR /F "tokens=* USEBACKQ" %%F IN (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe`) DO (
SET "msbuild.exe=%%F"
)
set msbuild.exe
@f-steff
f-steff / KeiluVisionBuilder.cmd
Last active November 7, 2023 22:06
Use the Keil µVision compiler from the windows command line.
@echo off
setlocal
:: KeiluVisionBuilder.cmd
:: Written by Flemming Steffensen, 2019.
:: Free for use and abuse by anyone.
:: ======================
:: Configuration
set WaitForLicenseTimeout=60
set BuildAttemptsMax=10
@f-steff
f-steff / EnsureJenkinsServiceRunnning.cmd
Created March 14, 2021 16:25
Workaround to JENKINS-47657, restarting the service whenever it stops.
@echo off
:: 2019-03-20: Flemming Steffensen added this as a workaround to a Jenkins bug JENKINS-47657
:: https://issues.jenkins.io/browse/JENKINS-47657?focusedCommentId=363147&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-363147
::
set "ServiceName=jenkinsslave-C__Jenkins"
for /F "tokens=3 delims=: " %%H in ('sc query "%ServiceName%" ^| findstr " STATE"') DO (
if /i "%%H" neq "RUNNING" (
net start "%ServiceName%"
)
)
@f-steff
f-steff / excel formulas.md
Last active February 15, 2025 21:58
Excel formulas to calculate IP values such as Netmask, IP range start, IP range end, Broadcast IP, Number of hosts.

Excel formulas to calculate IP values - Works in Excel and Google Sheet.

Updated 2023-12-11: Hosts calculation updated to support CIDR or 31 and 32.

Prerequisites:

  • A1 contains an IP address, such as 10.0.0.2
  • B1 contains the number of bits in the netmask (CIDR) such as 24

The below formulas then go into C1, D1 etc. to perform the various calculations. Some calculations depends on other calculations.

@f-steff
f-steff / readme.md
Last active March 1, 2021 21:50
Test of using markdown as part of gists

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Normal heading