Skip to content

Instantly share code, notes, and snippets.

View andygock's full-sized avatar

Andy Gock andygock

View GitHub Profile
@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 }));
@andygock
andygock / javascriptreact.json.txt
Last active February 6, 2018 13:21
Visual Studio Code Snippets for Javascript React
{
// Place your snippets for JavaScript React here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Print to console": {
"prefix": "log",
"body": [
"console.log('$1');",
@andygock
andygock / date_diff_weekdays.php
Created October 16, 2017 03:48
PHP: Calculate number of weekdays between two dates.
<?php
/**
* Calculate number of weekdays between two dates.
*
* @param string $from Start date, in format "YYYY-MM-DD"
* @param string $to End datem in format "YYYY-MM-DD"
* @return int|null Number of weekdays between $from and $to. NULL if either $from or $to is NULL.
*/
static function date_diff_weekdays($from, $to) {
@andygock
andygock / compress-links.py
Created August 25, 2017 17:50
Wrapper script to compress multiple hard linked files.
@andygock
andygock / download-firefox.sh
Created June 4, 2017 13:35
Bash script: Download latest Firefox 32-bit installer for Windows
#!/bin/bash
#
# Download latest Firefox 32-bit installer for Windows
#
url=$(wget -S --max-redirect 0 \
"https://download.mozilla.org/?product=firefox-latest&os=win" 2>&1 \
| grep "^Location" | cut -d ' ' -f 2)
if [ $# -ne 0 ]; then { echo $url; return 0; }; fi
wget "$url" -O "${url##*/}"
@andygock
andygock / download-sublimetext3.sh
Created June 4, 2017 13:31
Bash script: Download latest Sublime Text 3 installer
#!/bin/bash
# Download latest Sublime Text 3 installer
url=$(curl -s "https://www.sublimetext.com/3" \
| grep "dl_linux.*tarball" \
| cut -d '"' -f 6)
curl "$url" -o ${url##*/}
# Example of installation:
#
# tar -jxvf sublime_text_3_build_3126_x64.tar.bz2 -C ~
@andygock
andygock / download-reader11-update.sh
Created June 2, 2017 15:50
Bash script: Download latest Adobe Reader 11 update installer
#!/bin/bash
#
# Download latest Adobe Reader 11 update installer
#
page2=$(curl -s "http://supportdownloads.adobe.com/product.jsp?product=10&platform=Windows" \
| grep "Adobe Reader 11.*update - All" \
| head -n 1 \
| cut -d '"' -f 2)
echo "> $page2"
@andygock
andygock / download-libreoffice.sh
Last active June 2, 2017 09:34
Bash script: Download latest stable LibreOffice for Windows x86
#!/bin/bash
#
# Download latest stable LibreOffice for Windows x86
#
urla=$(curl -s "https://www.libreoffice.org/download/download/" \
| grep "option.*type=win-x86\&" | head -n 2 | cut -d '"' -f 2 | tail -n 1)
urlb=$(curl -s "$urla" | grep "\.msi" | grep -v "torrent" | tail -n 1 | cut -d '"' -f 6)