Skip to content

Instantly share code, notes, and snippets.

View andygock's full-sized avatar

Andy Gock andygock

View GitHub Profile
@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)
@andygock
andygock / download-jre.sh
Created June 2, 2017 09:29
Bash script: Download latest JRE offline installer
#!/bin/bash
#
# Download latest JRE for Windows x64
page="http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html"
# Edit this for other platforms
url=$(curl -s "$page" \
| grep "downloads\[.*jre-.*filepath" | cut -d ',' -f 3 | cut -d '"' -f 4 | grep "x64.exe$")
@andygock
andygock / sync-to-external.cmd
Created April 14, 2017 08:09
Script to sync one directory to another using robocopy (suitable as a form of backup)
@echo off
setlocal
:: set target and source directory, do not use a trailing slash
:: recommended: sync to a subdir on target drive
set source_drive=z:
set target_drive=p:\drive_z
:: exclude these dirs from sync
set excluded_dirs=exclude1 exclude2 "exclude 3"
@andygock
andygock / yt-rip.py
Last active June 2, 2017 15:52
Rip album of AAC audio from Youtube playlist with youtube-dl
#/usr/bin/env python
"""
Prerequisites:
* python
* youtube-dl https://rg3.github.io/youtube-dl/
* (not required yet) mutagen (pip install mutagen)