Skip to content

Instantly share code, notes, and snippets.

View andygock's full-sized avatar

Andy Gock andygock

View GitHub Profile
@andygock
andygock / README.md
Created March 23, 2024 08:31 — forked from asheroto/README.md
Strip PowerShell output that contains spinner, progress bar, or more than one empty line.

Strip-Progress

Strip PowerShell output that contains spinner, progress bar, or more than one empty line. Fixes download progress formatting by effectively removing extra space after the slash, often seen in winget (example 269 MB / 305 MB).

When to use

This function can be beneficial when you're capturing the output stream of a command, but don't want the extra characters in the text. See examples. Works great with winget.

Usage

#!/bin/bash
#
# Create list.txt with each repo name on a new line
#
# You can copy all the names from your GitHub repo page with the following command in the browser
# copy([ ...document.querySelectorAll("a[itemprop]")].map(a=>a.href.match(/.*\/(.*)$/)[1]).join("\n") + "\n")
#
# Or open settings, repositories, and copy the names from the list, this method below includes repos which you collaborate with, so you may need to just manually remove them
# copy([...document.querySelectorAll(".js-collaborated-repos a.mr-1")].map(n=>n.innerText.replace(/^.*\//,'')).join("\n"))
# Then run:
@echo off
rem Create list.txt with each repo name on a new line
rem
rem You can copy all the names from your GitHub repo page with the following command in the browser
rem copy([ ...document.querySelectorAll("a[itemprop]")].map(a=>a.href.match(/.*\/(.*)$/)[1]).join("\n") + "\n")
rem
rem Or open settings, repositories, and copy the names from the list, this method below includes repos which you collaborate with, so you may need to just manually remove them
rem copy([...document.querySelectorAll(".js-collaborated-repos a.mr-1")].map(n=>n.innerText.replace(/^.*\//,'')).join("\n"))
rem
rem Then run:

GPG Cheat Sheet

Written for GPG versions 2.x only.

List keys

List public keys

gpg --list-keys
@andygock
andygock / copy.js
Created July 24, 2020 14:42
JS function to copy string to clipboard in browser
const copy = str => {
const el = document.createElement("textarea");
el.value = str;
document.body.appendChild(el);
el.select();
document.execCommand("copy");
document.body.removeChild(el);
};
#!/bin/bash
#
# renew-letsencrypt-certificates.sh DOMAIN [EMAIL]
#
# Copy Let's Encrypt SSL certs from a remote public facing web server to local filesystem
# Look for changes, if any change, restarts the web service
# Useful for using Let's Encrypt with local internal servers, with custom DNS.
# Working "mail" command needed for email alerts
#
#!/bin/sh
# Flush tables
iptables -F
# Allow established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow SSH, VNC, Web etc
iptables -A INPUT -p tcp --dport ssh -j ACCEPT
@andygock
andygock / cfg-firewall.sh
Created August 7, 2019 14:46
Basic iptables starter script that only allow incoming SSH and ping
#!/bin/bash
#
# basic iptables starter script that only allow incoming SSH and ping
#
# default actions
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
@andygock
andygock / pi.sh
Created January 13, 2019 13:18
Back up and restore Raspbery Pi microsd card
#!/bin/bash
#
# Usage:
# ./pi.sh backup /dev/sdb
# ./pi.sh restore /dev/sdb
#
# Files created and used during backup and restore:
# mbr.img sfdisk.dump partition[12].parted
#
# For raspbian images, use minimum 8GB microsd card
@andygock
andygock / cypress-drag-and-drop-test.js
Last active June 29, 2021 12:25
Cypress.io testing multiple file drag and drop uploads
// drag and drop multiple files
Cypress.Commands.add("upload_files", (selector, fileUrlArray, type = "") => {
const files = [];
fileUrlArray.forEach((fileUrl) => {
cy.fixture(fileUrl, "base64")
.then(Cypress.Blob.base64StringToBlob)
.then((blob) => {
const nameSegments = fileUrl.split("/");
const name = nameSegments[nameSegments.length - 1];
files.push(new File([blob], name, { type }));