Skip to content

Instantly share code, notes, and snippets.

View MatthewDaniels's full-sized avatar

Matthew Daniels MatthewDaniels

  • Brisbane, Qld, Australia
View GitHub Profile
@MatthewDaniels
MatthewDaniels / IE7-8 Background Resize Mixin
Created February 19, 2013 01:14
Internet Explorer < version 9 background resize less mixin. An easy way to get css background-size: cover in internet explorer versions 8 and lower. Add it to your mixins less file and reference wherever you need it.
// used to make a background image (including alpha images) scale to the size of it's container in ie7 & ie8
.ie7-8-backgroundScale(@filename) {
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='@{filename}', sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='@{filename}', sizingMethod='scale')";
}
@MatthewDaniels
MatthewDaniels / toType.js
Last active March 16, 2016 21:51
A better typeof implementation
/**
* A better typeof implementation.<br>
* This method will return a proper string for
* every object in javascript; including, but not limited to:
* 'array'
* 'arguments'
* 'error'
* 'date'
* 'regexp'
* 'json'
@MatthewDaniels
MatthewDaniels / Upload file to S3 - Multipart
Last active January 9, 2022 23:24
Use this as a structure to send a file to S3. It uses the AWS Javascript SDK - unfortunately, without using requires js, all other builds failed aside from the CDN provided version here: https://sdk.amazonaws.com/js/aws-sdk-2.2.33.min.js
// NOTE: it is suggested that you use very limited credentials
// a good solution is to create an IAM user in AWS that has only PUT rights to S3
// use a temporary bucket that has an expiry (24hrs or something low)
// once the file is uploaded get your server to move the file to another bucket that has much less
// restricted rights.
// See: readme for more info
// setup the credentials
AWS.config.update({
accessKeyId: accessKeyId,
@MatthewDaniels
MatthewDaniels / getIPForGTM.js
Created March 16, 2016 21:52
Load a user's IP address via a service so we can add it to a dataLayer in GTM - beware we do not want to store it in it's raw form, but we can manipulate the data in GTM once there (ie: check against a filtered list and add a flag)
var request = new XMLHttpRequest();
// if the endpoint changes, then manipulation of the returned data may need to change in the onReadyState handler
request.open('GET', 'https://api.ipify.org', true);
request.onreadystatechange = function() {
if (this.readyState === 4) {
if (this.status >= 200 && this.status < 400) {
// Success!
var data = this.responseText;
console.log('respose', data);
@MatthewDaniels
MatthewDaniels / parseQueryString.js
Created April 6, 2016 03:29
Parse the current window location's query parameters into a map
function parseQueryString() {
var query = (window.location.search || '?').substr(1),
map = {};
query.replace(/([^&=]+)=?([^&]*)(?:&+|$)/g, function(match, key, value) {
(map[key] = map[key] || []).push(value);
});
return map;
}
@MatthewDaniels
MatthewDaniels / GA Tracker helper
Last active November 13, 2017 03:47
This script iterates the Google Analytics trackers on the page (assuming the Google Analytics variable is 'ga'. It then outputs various bits of info, including the tracker name, the tracking ID, the client ID, the cookie domain and any custom dimensions that exist. Copy and paste it into the console on the page you want to find out more about.
if(window.ga) {
var arr = window.ga.getAll();
for (var i = 0, len = arr.length; i < len; i++) {
var t = arr[i];
if(console.group) {
console.group(t.get('name'));
}
console.log('Main tracker object:', t);
@MatthewDaniels
MatthewDaniels / gzip.conf
Last active May 1, 2021 01:01
Nginx Standard Gzip Conf: Store this file in /etc/nginx/conf.d and include in standard server directive
# Compression
# Enable Gzip compressed.
gzip on;
# Enable compression both for HTTP/1.0 and HTTP/1.1.
gzip_http_version 1.1;
# Compression level (1-9).
# 5 is a perfect compromise between size and cpu usage, offering about
@MatthewDaniels
MatthewDaniels / cache.conf
Created May 20, 2016 01:31
Nginx Standard Cache Conf: Store this file in /etc/nginx/conf.d and include in standard server directive
# Proxy Cache Settings
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=reverse_cache:60m inactive=90m max_size=1000m;
@MatthewDaniels
MatthewDaniels / GA-Management-Properties-and-lists.gs
Last active June 7, 2016 04:13
A simple google apps script script for Google Sheets that replaces the current sheet's data with Property & View information for a specific Google Analytics Account. You will need to enable access via the API to your account - see: https://developers.google.com/apps-script/guides/services/advanced ... NOTE: THIS IS QUITE MESSY AND HAS NO CHEKCIN…
function getSummary() {
var listed = Analytics.Management.AccountSummaries.list();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
// var baseRangeRow = 4
// sheet.getRange(baseRangeRow,1).setValue(listed.items[0]);
// sheet.getRange(baseRangeRow+1,1).setValue(listed.items[0].webProperties[0]);
// sheet.getRange(baseRangeRow+2,1).setValue(listed.items[0].webProperties[0].profiles[0]);
ga(function(tracker) {
// Grab a reference to the default sendHitTask function.
var originalSendHitTask = tracker.get('sendHitTask');
// Modifies sendHitTask to send a copy of the request to a local server after
// sending the normal request to www.google-analytics.com/collect.
tracker.set('sendHitTask', function(model) {
// sends the original hit task