Skip to content

Instantly share code, notes, and snippets.

View Willshaw's full-sized avatar

Peter Williamson Willshaw

View GitHub Profile
@Willshaw
Willshaw / fixnetwork.bat
Created March 22, 2020 19:42
Quick batch file to disable/enable network adapter (mine is often slow on Windows 10 after waking from sleep)
@rem save this file somewhere, then create shortcut like this
@rem C:\Windows\System32\cmd.exe /c "C:\path\to\fixnetwork.bat"
netsh interface show interface
@echo on
@rem Disable the adapter - make sure the quoted name matches your adapter name
netsh interface set interface "INSERT NETWORK ADAPTER NAME HERE" DISABLED
@rem Wait 2 seconds before re-enabling (again adapter names must be correct)
timeout /t 2
@Willshaw
Willshaw / pre-request.js
Created June 15, 2021 09:59
Pre-request script for Postman calling api.comcar.co.uk/v1/
// build the hash
var current_timestamp = ((new Date()).getTime() / 1000).toFixed();
postman.setEnvironmentVariable('this_timestamp', current_timestamp );
postman.setEnvironmentVariable('this_nonce', Math.floor( Math.random() * 10000 ));
// the message is made up of the order/filter etc params
// params need to be put into alphabetical order
var current_message = '';
var query_params = postman.__execution.request.url.query;
@Willshaw
Willshaw / hash.sh
Last active July 21, 2020 11:06
Use coldfusion to execute a bash script and get the current git commit
#!/bin/bash
# change directory to the path passed from cf
# then do a git log, oneline to avoid commit messages (I had to specify the full path to git)
# pipe that to "head" and limit it to 1 line
# this will give us "HASH MESSAGE"
# use awk to print the first "column" -> HASH
cd $1 && /usr/local/git/bin/git log --oneline | head -n 1 | awk '{print $1}'
@Willshaw
Willshaw / git_quick_commit.sh
Last active May 12, 2020 09:21
Short cut to git commit -m using folder path after httpdocs
# add this to your ~/.bashrc
# then as long as you're inside an httpdocs folder (e.g. /var/www/vhosts/example/httpdocs/my/awesome/tool)
# you can go like this:
# git add .
# git status (to be safe now)
# git_quick_commit I done some stuff
#
# and you'll get a commit message like:
# 45dcc35 my > awesome > tool: I done some stuff
#
@Willshaw
Willshaw / random.js
Created December 31, 2019 16:06
Create a string of random numbers seperated by your mask
// simply returns a single random number
const singleRandom = function singleRandom() {
return (Math.random() * 10).toFixed(0);
};
/*
accept a mask of seperators, e.g. / or //::
and return the mask strings surrounded by numbers.
- if the seperator changes, add a space
- / becomes X/Y
@Willshaw
Willshaw / truncate-vs-delete.sql
Last active January 30, 2019 12:39
Difference between TRUNCATE and DELETE
-- this was written for mysql to show how TRUNCATE does more than just DELETE all the rows
-- make sure you have a `test` database and a user with permissions to CREATE tables
DROP TABLE `test`.`test`;
CREATE TABLE `test`.`test`
(
`id` INT(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
`name` VARCHAR(32) NOT NULL
);
@Willshaw
Willshaw / plusplus-a-or-a-plusplus.js
Last active January 28, 2019 05:31
Show the difference between a++ and ++a
/**
* update quantity based on button type
* make sure we don't go below zero
*/
if( action_type === 'minus' ) {
// this returned my value, then decremented it, so it never saved
// hitting the minus button always resulted in the same number
quantity = quantity ? quantity-- : 0;
@Willshaw
Willshaw / null-values-insert-select.sql
Created June 18, 2018 07:38
MySQL showing a NULL value converting to a 0 during an INSERT..SELECT...
####################################
# #
# Example queries to demonsrate #
# how SELECTing a NULL value is #
# converting it into a 0 during a #
# INSERT...SELECT statement #
# #
####################################
# recreate an empty example price table
@Willshaw
Willshaw / gapps spreadsheet to pdf description
Created March 11, 2018 20:58
script to take text from a google spreadsheet and save it as the description on a pdf in google drive
/*
this script relies on a spreadsheet being called "test desc" and a pdf being called "test.pdf"
there needs to be a description in cell A1 of "test desc"
*/
function setNewDescription(file_id,description){
var file_by_id = DriveApp.getFileById(file_id);
Logger.log(file_by_id.getDescription());
@Willshaw
Willshaw / example.sh
Created January 4, 2018 17:32
simple start to a bash script
#!/bin/bash
################################
# to use the tracker:
# call the track script, using the full path to the script
# and also give it an action string, and a script string
#
# $REPO_PATH"bin/track.sh" "completed thing" $REPO_PATH"task_one"
#
# /path/to/script/bin/track.sh "action that happened" "script/that/is/doing/things"