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 / DownloadFtpFolder.ps1
Created September 23, 2019 12:02
Download all files in a folder on an FTP-server to the DestinationFolder. Source and destination must be specified. UrlPort, UserName and Password can be specified. Defaults to access a hardcoded URL.
# DownloadFtpFolder.ps1 created by f-steff, Sept.12 2019.
# This is a modified version of DownloadFtpDirectory() by Martin Prikryl.
# usage: DownloadFtpFolder.ps1 SourceFolder Destination folder [UrlPort Username Password]
function EnsureTargetDirectory ($localPath)
{
# Ensure to return a full qualified path.
# Will create the folder(s) if needed.
try
{
@f-steff
f-steff / List_FTP_Folders.groovy
Last active September 23, 2019 12:19
Jenkins Groovy: List folders located in a particular FTP folder.
// Created by f-steff 2019. Use and abuse as you wish.
@Grab(group='commons-net', module='commons-net', version='2.0')
import org.apache.commons.net.ftp.FTPClient
import org.apache.commons.net.ftp.FTPFile
//def path="pub/"
println("Fetching reverse sorted list of ftp folders from $path");
FTPClient ftpClient = new FTPClient()
ftpClient.connect "arnold.c64.org",21

Keybase proof

I hereby claim:

  • I am f-steff on github.
  • I am fsteff (https://keybase.io/fsteff) on keybase.
  • I have a public key ASDjVUweLva7Q1ChOFIyIM6oVz9iDJ5obsZZNleUt2mgQAo

To claim this, I am signing this object:

@f-steff
f-steff / goto-example.sh
Created October 9, 2019 09:36
Goto in bash - Brilliant for debugging!!
#!/bin/bash
# GOTO for bash, https://stackoverflow.com/questions/9639103/is-there-a-goto-statement-in-bash/52872489#52872489
# Based upon https://stackoverflow.com/a/31269848/5353461
function goto
{
local label=$1
cmd=$(sed -En "/^[[:space:]]*#[[:space:]]*$label:[[:space:]]*#/{:a;n;p;ba};" "$0")
eval "$cmd"
exit
@f-steff
f-steff / OnlineTools.txt
Created October 9, 2019 09:54
Usefull online tools:
List of Online Tools
====================
https://www.shellcheck.net/
Finds bugs in shell-scrips - not 100% perfect, but comes with very usefull suggestions.
For folks who want Chrome to always restore windows to their original spaces, you can set that by running this command in a terminal window (for Canary, use `com.google.Chrome.canary`):
defaults write com.google.Chrome NSWindowRestoresWorkspaceAtLaunch -bool YES
To go back to the default behavior, run:
defaults delete com.google.Chrome NSWindowRestoresWorkspaceAtLaunch
This should work for any Mac app, not just Chrome.
@f-steff
f-steff / Excel_Save_CSV.vba
Last active October 10, 2019 11:23
Excel macro to save proper csv files regardless of system settings
Private Sub save_CSV()
' Written by Flemming Steffensen, 1997
' The CSV ("Comma Separated Values") File Format: (Simple as it is, Microsoft can not follow the rules!)
' * Each record is one line - Line separator may be LF (0x0A) or CRLF (0x0D0A), a line seperator may also be embedded in the data (making a record more than one line but still acceptable).
' * Fields are separated with commas. - Duh.
' * Leading and trailing whitespace is ignored - Unless the field is delimited with double-quotes in that case the whitespace is preserved.
' * Embedded commas - Field must be delimited with double-quotes.
' * Embedded double-quotes - Embedded double-quote characters must be doubled, and the field must be delimited with double-quotes.
' * Embedded line-breaks - Fields must be surounded by double-quotes.
' * Always Delimiting - Fields may always be delimited with double quotes, the delimiters will be parsed and discarded by the reading applications.
@f-steff
f-steff / bash_tricks.sh
Last active October 11, 2019 08:03
How to comment out bit pieces of code simple and effective.
#!/bin/bash
echo "Multi line comments in Bash"
: '
blah blah
blah blah
blah blah
blah blah
blah blah
# '
echo "All done done!"
@f-steff
f-steff / ZipUp.cmd
Created October 11, 2019 19:38
Batch sub-function to create a zip archive from a folder.
:: === Main code:
:: My answer to https://stackoverflow.com/questions/17546016/how-can-you-zip-or-unzip-from-the-script-using-only-windows-built-in-capabiliti/58013665#58013665
call :ZipUp "C:\Some\Path" "C:\Archive.zip"
:: === SubRoutines:
:ZipUp
::Arguments: Source_folder, destination_zip
@f-steff
f-steff / FixInjectedArraysInBash.sh
Last active October 25, 2019 12:54
Fix for array variables imported into bash using Jenkins 'Inject environment variables' plugin
#!/bin/bash
# fsteff 2019
# Workaround for bash not properly supporting export of environment array variables.
# When using Jenkins 'Inject environment variables' plugin, array variables ends up in a strange state,
# where they are listed as exported variables, but are not actual shell variables.
# Checking using `env` or `printenv` shows injected array variables unrolled (ie not as arrays)
# Checking using `declare -p`, `declare -xp` and `set` does not show injected array variables - but normal array variable are shown as arrays.
# The workaround below loops through the output of `printenv` and sets each injected variable it finds.
# NOTE: This must be run in the 'Execute Shell' where the variables are needed.
# NOTE2: Using as a script file, requires that it's executed as `. ./FixInjectedArraysInBash.sh` or `source ./FixInjectedArraysInBash.sh`