Skip to content

Instantly share code, notes, and snippets.

View walkergv's full-sized avatar

Glenn Walker walkergv

View GitHub Profile
@walkergv
walkergv / .htaccess
Created February 9, 2015 18:14
Redirect old domain to a new domain in .htaccess file
## Gets an the old domain and any sub page and redirects it to the new domain and any path after the hostname.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^olddomain.com$
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
@walkergv
walkergv / multiselect.excel.vba
Created February 5, 2015 23:04
Create a multiselect excel macro
'
' taken from the website for instructions http://www.contextures.com/excel-data-validation-multiple.html
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count > 1 Then GoTo exitHandler
@walkergv
walkergv / .htaccess
Created January 29, 2015 16:56
Enable caching in .htaccess file. A common Google Page Speed recommendation.
# Begin Cache Control
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType application/javascript A2592000
ExpiresByType text/css A2592000
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
</IfModule>
@walkergv
walkergv / runReport.appscript.js
Created January 29, 2015 05:42
Pass in your Google Analytics Profile Id and use GA Reporting API to get information and output to spreadsheet.
function runReport(profileId) {
var today = new Date();
var oneWeekAgo = new Date(today.getTime() - 30 * 24 * 60 * 60 * 1000);
var startDate = Utilities.formatDate(oneWeekAgo, Session.getScriptTimeZone(),
'yyyy-MM-dd');
var endDate = Utilities.formatDate(today, Session.getScriptTimeZone(),
'yyyy-MM-dd');
var tableId = 'ga:' + profileId;
@walkergv
walkergv / createdocfromsheet.appscript.js
Created January 29, 2015 05:38
Create and Format a Google Doc from Google Sheet
function createDoc() {
//
// Get The Current Spreadsheet
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getActiveSheet();
//
// Get data in spreadsheet
var range = sheet.getDataRange();
var rowsData = range.getValues();
//
@walkergv
walkergv / listallfiles.googleappscript.js
Created January 26, 2015 21:06
Export a List of Google Sheets in a Google Drive Folder
function listFilesInFolder(folderName) {
var folder = DocsList.getFolder(folderName);
var contents = folder.getFiles();
var file, data, rows = [];
for (var i = 0; i < contents.length; i++) {
file = contents[i];
@walkergv
walkergv / .htaccess
Last active August 29, 2015 14:06
Redirect to www version of the site.
########## - BEGIN - remove www version of site
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
########## - END - www.version of site
@walkergv
walkergv / gtm-userscript.js
Last active August 29, 2015 14:01
google tag manager (gtm) userscript for tampermokey
// ==UserScript==
// @name Google Tag Manager Test Script
// @namespace http://www.tikodigital.com/
// @version 0.1
// @description Code to Run Google Tag Manager Client Side
// @include *domain.com*
// @copyright 2014 Tiko Digital
// ==/UserScript==
var actualCode = '(' + function() {
@walkergv
walkergv / php-UA.php
Last active May 20, 2022 09:04
Simple Event Tracking with Measurement Protocol Using cURL and PHP (plus redirect)
<?
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://www.google-analytics.com/collect?v=1&tid=[UA-XXXXXXXXX-1]&cid=[RANDOM_INTEGER_OR_GUID]&t=event&ec=[EVENT_CATEGORY]&ea=[EVENT_ACTION]&el=[EVENT_LABEL]',
CURLOPT_USERAGENT => 'Vanity-URL-Tracker',
));
$resp = curl_exec($curl);
curl_close($curl);
header("HTTP/1.1 301 Moved Permanently");
@walkergv
walkergv / Category to Sheet
Last active July 5, 2023 21:40
A VBA Excel Macro that processes an Excel Table with a category column (must be first column) and applies several sorts, filters and styling. Also it creates a linked table of contents of worksheets in the excel workbook.
Sub CategoryToSheet()
Dim rng As Range
Dim Category As Range
Dim List As New Collection
Dim Item As Variant
Dim i As Integer
Dim rngLinkCell As Range
Dim strSubAddress As String
Dim strDisplayText As String
'