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 / excel formulas.md
Last active April 23, 2024 08:21
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 / Onedrive as a Windows Service.txt
Last active April 10, 2024 08:51
How to set up OneDrive.exe as a Windows Service, allowing synchronization without a user is logged in.
OneDrive.exe as a Windows Service
=================================
Flemming Steffensen, 2017, 2021
For our automatic build setup, we needed to fetch some files off a Sharepoint Library.
Sharepoint allows (if configured so) Lists and Libraries to be synchronized to a local folder by using the OneDrive application.
However, the OneDrive application is started when a user logs in, and in an automated build setup, this never happens.
The solusion were to disable the normal auto-start feature of OneDrive, and then install it as a service, and making sure the
service start as the computer starts.
@f-steff
f-steff / GoogleSheetsEnableScandinavianKeyboardOnMac.user.js
Last active January 20, 2024 21:10
Tampermonkey userscript to enable missing keys in Scandinavian Keyboard mapping on Mac
// ==UserScript==
// @name Google Sheets Enable Scandinavian Keyboard On Mac
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Fix shift+option+number keys in Google Sheets on Mac while using a Scandinavian keyboard layout, by nterception of shift+option+number keys, and replace them with the correct char pasted in. Flaws: Does not enter edit mode when inserting into inactivated sheet cells.
// @author Flemming Steffensen
// @match https://docs.google.com/spreadsheets/*
// @grant none
// @homepageURL https://gist.github.com/f-steff/ace84434e1ee4e1107bcf0ba8d72ed2b
// @updateURL https://gist.githubusercontent.com/f-steff/ace84434e1ee4e1107bcf0ba8d72ed2b/raw/GoogleSheetsEnableScandinavianKeyboardOnMac.js
@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 / 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
$connectedInterfaces = Get-NetAdapter | Where-Object { $_.Status -eq 'Up' }
$connectedInterfaces | ForEach-Object {
$interfaceAlias = $_.Name
$dnsServers = Get-DnsClientServerAddress -InterfaceIndex $_.InterfaceIndex -AddressFamily IPv4 | Select-Object -ExpandProperty ServerAddresses
$interfaceMetric = (Get-NetIPInterface -InterfaceIndex $_.InterfaceIndex).InterfaceMetric | Select-Object -First 1
for ($i = 0; $i -lt $dnsServers.Count; $i++) {
[PSCustomObject]@{
InterfaceAlias = $interfaceAlias
InterfaceMetric = [string]$interfaceMetric
@f-steff
f-steff / README.md
Last active August 6, 2023 19:13
var_dump for Python Jinja2 html template engine.

This code is a macro written in Jinja2, a powerful template engine for Python. This macro, named var_dump, works similarly to PHP's var_dump() function. It helps to print or display structured information about variables, especially useful for debugging.

The var_dump macro takes four parameters:

  • var: The variable you want to display.

  • var_name: The name of the variable (this is optional, and its default value is an empty string).

  • space: The indentation level (this is optional, and its default value is 0).

@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.js
Created February 6, 2023 22:58
Userscript for Tampermonkey to intercept F1 on Google Sheets, so that the annoying Help popup can be suppressed.
// ==UserScript==
// @name F1 key interception on Google Sheets to suppress the Help
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Interception of F1 keypress on Google Sheets and replaces default behavior with nothing.
// @author Flemming Steffensen
// @match https://docs.google.com/spreadsheets/*
// @grant none
// ==/UserScript==
@f-steff
f-steff / ICD3_Switcher.cmd
Last active January 24, 2023 20:52
Batch script to switch USB drivers for the Microchip ICD3 In Circuit Debugger. Unlike the "MPLAB Drive Switcher" utility, this script supports all installation points of MPLAB8 and MPLABX, both 32 and 64 bit, and it uses only windows functionality to perform the switch, which is virtually instantaneous. Tested on Win10. Updated to support multip…
@echo off
:: ICD3 switcher by Flemming Steffensen, Febuary 2021.
:: Switch USB drivers for all Microchip ICD3 In Circuit Debugger connected to the computer.
:: Unlike the "MPLAB Drive Switcher" utility, this script supports all installation points of MPLAB8 and MPLABX,
:: both 32 and 64 bit, and it uses only windows functionality to perform the switch, which is virtually instantaneous.
:: This script is parameterized in run in command prompt and interactive when doubleclicked.
:: Tested on Win10.
::
:: Note, A known ICD3 bug appear to happen much more frequently when switching between drives. The ICD3 firmware also
:: need to be programmed, and while it can happen automatic, I recommend to not do so. If after installing the firmware,