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 / 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 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 / 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

@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,
@f-steff
f-steff / Parse_Robocopy_Return_Codes.cmd
Created February 4, 2021 13:43
Use Robocopy in Batch scripts and understand the errors.
echo FETCHING files...
set "source=\\myFileServer\FileServer\Files_To_Go_Onto_CD"
set "dest=.\CD_FILES"
robocopy %source% %dest%
if %ERRORLEVEL% EQU 16 echo ***FATAL ERROR*** & goto fail
if %ERRORLEVEL% EQU 15 echo OKCOPY + FAIL + MISMATCHES + XTRA & goto fail
if %ERRORLEVEL% EQU 14 echo FAIL + MISMATCHES + XTRA & goto fail
if %ERRORLEVEL% EQU 13 echo OKCOPY + FAIL + MISMATCHES & goto fail
if %ERRORLEVEL% EQU 12 echo FAIL + MISMATCHES& goto fail
if %ERRORLEVEL% EQU 11 echo OKCOPY + FAIL + XTRA & goto fail
@f-steff
f-steff / Notepad++_Access_NetworkDrives.txt
Last active February 4, 2021 13:41
When Notepad++ and others suddenly can't access mapped drives from network resources, this is the fix
When Notepad++ and others suddenly can't access mapped drives from network resources, this is the fix:
1. Add a new DWORD to your registry:
HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System/EnableLinkedConnection
2. Set it to a value of 1.
3. Reboot & all should be good.
@f-steff
f-steff / Fix_Includes.cmd
Created February 4, 2021 11:15
Fix Microchip includes to allow SourceTrail and other tools to analyze MPLAB C8, C16 or C32 source code without errors.
:: Fix to allow SourceTrail to analyze MPLAB CX8 source code.
@echo off
setlocal enabledelayedexpansion
::Usage:
:: Copy Microchip includes from C:\Program Files (x86)\Microchip\xc8\v1.33\include
:: to another folder such as C:\Program Files (x86)\Microchip\xc8\v1.33\include_fixed
:: Copy this file (fix.cmd) into the include_fixed folder, and execute.
::
:: Depends on Strawbery Perl from https://strawberryperl.com/
@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 / NumberedFiles2NumberedFolders.sh
Created January 13, 2020 12:20
Bash shell: Sort sets of numbered files into numbered Folders
# I had 70000+ files all named after the pattern nnn_something.jpg. nnn was a number from 000 to 999. Not all numbers existed.
# Each set of nnn belonged together, and I wanted them placed in sub-folders like this 074/074_something.jpg
# These three bash shell commands cleaned up the mess in a few seconds:
# CREATE FOLDERS.
#This works on bash prior to version 4 - as on Mac. (Newer Bash can just write $ mkdir {000..999} )
$ for i in 00{0..9} 0{10..99} {100..999}; do mkdir ${i} ; done
# MOVE FILES
@f-steff
f-steff / ReplaceVars.sh
Created January 7, 2020 12:32
Bash script to replace multiple predefined variables in a template file to create a new file. Test files included.
#!/bin/bash
echo "Replacing variables in file."
InFile="${1:-Test.txt}"
InFileName="${InFile%.*}"
InFileExt=${InFile#"$InFileName"}
OutFile=${2:-"${InFileName}_out${InFileExt}"}
InVar=${3:-VarValues.txt}
if [ ! -f $InFile ] || [ ! -f $InVar ] ; then