Skip to content

Instantly share code, notes, and snippets.

View JonTheNiceGuy's full-sized avatar

Jon "The Nice Guy" Spriggs JonTheNiceGuy

View GitHub Profile
@JonTheNiceGuy
JonTheNiceGuy / wait_for_network.sh
Last active May 17, 2023 10:06
Wait for the NIC to be assigned an IP address, then wait for google's DNS to respond, and then sleep for rand(30,600), used like this `wait_for_network.sh && do_something`
#! /bin/bash
# This script checks that the interface is up, and that an internet connection is available
# It is based on code from http://askubuntu.com/questions/3299/how-to-run-cron-job-when-network-is-up
#
# Then it sleeps for a random number of seconds between 30 and 600.
# This is based on code from http://tldp.org/LDP/abs/html/randomvar.html
#
# Collated by @JonTheNiceGuy on 2015-10-15
# Fix from @p1r473 on 2023-05-17 with thanks!
@JonTheNiceGuy
JonTheNiceGuy / findgit.sh
Created October 20, 2015 21:27
Find a commit which references a piece of text (I use this in https://github.com/garethr/vagrantboxes-heroku)
#!/bin/bash
git log -S"$1" -- www/index.html | grep commit
@JonTheNiceGuy
JonTheNiceGuy / alt-tab.ahk
Created November 20, 2015 08:17
Need something to rotate around windows on your Windows Desktop or RDP screen? This will do it! :) Requires AutoHotKey
InputBox, Sleep_Period, Alt-Tab-Script, How long do you want to wait between alt-tab - default 1 minute, , , , , , , , 1
InputBox, Number_Windows, Alt-Tab-Script, How many windows (max 6), , , , , , , , 3
SleepTime := ((Sleep_Period * 60) * 1000)
MsgBox, Sleeping %SleepTime%
Loop {
sleep, %SleepTime%
if Number_Windows = 2
{
Send, {alt down}{tab}{alt up}
}
@JonTheNiceGuy
JonTheNiceGuy / init.pp
Created December 12, 2015 21:57
Want to set a username and password in Puppet? Keep getting "You reset the password for a user 8m times" in your logs? This may be the gist for you! Only really works if you've got a consistent user salt across all your boxes :)
define createuser (
$username = $title,
$password = 'defaultpw',
$groups = ['users'],
$home = "/home/${username}"
$shell = '/bin/bash') {
user { $username:
ensure => present,
password => generate(
@JonTheNiceGuy
JonTheNiceGuy / x_sudo.sh
Created December 30, 2015 15:37
Need to use X as a user on a box after Sudo? Try this. Both files need putting somewhere in the path, and need chmod 755 owned by root.
#! /bin/bash
if [ -n "$DISPLAY" ]; then
CURRENTDISPLAY="`echo $DISPLAY | cut -d ':' -f 2 | cut -d '.' -f 1 | sed -e s/^/:/`"
DPYNAME="`xauth list | grep "$CURRENTDISPLAY" | cut -d ' ' -f 1`"
PROTONAME="`xauth list | grep "$CURRENTDISPLAY" | cut -d ' ' -f 3`"
HEXKEY="`xauth list | grep "$CURRENTDISPLAY" | cut -d ' ' -f 5`"
fi
if [ -z "$1" ] && [ `id -u root` == '0' ]; then
SU_TO="root"
@JonTheNiceGuy
JonTheNiceGuy / AAA VBA Snippets Readme.md
Last active June 3, 2022 14:25
VBA Snippets for Sharepoint Sync, Base64(sha1(AES(MESSAGE))), HTTP requests and other misc functions :)

This code is largely derived from sources found online. As such, I didn't think it was unreasonable to compile it into a series of extracts to use in your own projects.

In here we have code to perform an off-line sync with sharepoint lists, to perform an HTTP request, to check whether tables exist, and drop them if they do, and to produce Base64 encoded SHA1 signed AES ecrypted (with multiple rounds) text.

Function names:

  • ResyncWithSharepoint(URL)
  • SyncTable(TableName) (Note this depends on the tables having a Sharepoint Link already established with the prefix sp)
  • HttpOK(URL)
  • Sleep(microseconds)
  • ifTableExists(tableName, DatabaseFileName)
@JonTheNiceGuy
JonTheNiceGuy / AAA_Vagrant + Windows + Chocolatey Provisioning.md
Last active March 11, 2016 13:27
There are lots of instructions about setting up an auto-provisioning Linux host in Vagrant, but not a lot about doing the same for Windows. This should help!

Copy all of these into a single directory, make sure you've got a recent version of Vagrant and Virtualbox installed, then just... vagrant up

Vagrant will start a "simple" Windows 2012r2 box, created (presumably) by the fine folks at OpenTable and then it runs the provisioning sequence:

  • This will first run the ChocoBootstrap.cmd file to load Chocolatey onto the box (via InstallChocolatey.ps1)
  • It then uses chocolatey to install BoxStarter using the InstallBoxStarter.bat script
  • Lastly, it copies the BoxStarterOperations.txt file to %temp% and then executes it via RunBoxstarter.bat

This was all made a lot easier due to these blog posts

@JonTheNiceGuy
JonTheNiceGuy / line.sh
Created March 19, 2016 12:56
Get the latest Vagrant on x86/x64 Debian based systems
#! /bin/bash
if [ `uname -p` == 'x86_64' ]
then
wget `curl -s https://www.vagrantup.com/downloads.html | sed 's/\s/\n/g' | grep x86_64.deb | cut -c 7- | cut --delimiter=\" -f 1` -O /tmp/vagrant.deb; dpkg -i /tmp/vagrant.deb; rm /tmp/vagrant.deb
else
wget `curl -s https://www.vagrantup.com/downloads.html | sed 's/\s/\n/g' | grep i686.deb | cut -c 7- | cut --delimiter=\" -f 1` -O /tmp/vagrant.deb; dpkg -i /tmp/vagrant.deb; rm /tmp/vagrant.deb
fi
@JonTheNiceGuy
JonTheNiceGuy / AAA GPG Encrypt a file to a large number of recipients README.md
Created April 6, 2016 13:36
This batch file is used to encrypt a file with GPG against a large number of recipient email addresses

Using this script

Place this batch file and the text file into the same directory, edit the batch file to specify the key server and the text file to specify the names to encrypt.

If you hit an issue where an individual has multiple keys against their name, the script may well complain and ditch responses. In this case, uncomment the line in the batch file which says: REM %COMMAND% --recv-keys <KEY ID>

So it should say instead: %COMMAND% --recv-keys DECAFBAD

@JonTheNiceGuy
JonTheNiceGuy / Building Labs.md
Created September 26, 2016 19:33
Building Labs - A Basic Overview

Building a Lab network

The basics

Jon@Sprig.gs / @JonTheNiceGuy / @g7vri


Overview

  • Introduction