Skip to content

Instantly share code, notes, and snippets.

View dillansimmons's full-sized avatar

Dillan Simmons dillansimmons

View GitHub Profile
@dillansimmons
dillansimmons / findDupesInArray.js
Last active October 18, 2016 18:08
Map and find duplicates in 2 arrays
// Arrays
var x = ["7","?","X","X","Q", "?"];
var y = ["?","X","Z","Q", "?", "?"];
var find_dupes = function (array1, array2) {
/* Map Arrays, make uppercase if neccessary
var xx = array1.map(function(x){ return x.toUpperCase() })
var yy = array2.map(function(x){ return x.toUpperCase() }) */
@dillansimmons
dillansimmons / findDupesInSingleArray.js
Last active October 18, 2016 18:21
Find duplicates in single array
//Array
var y = ["?","X","Z","Q","W","W"];
/*OPTION ONE*/
var find_dupe = function (array) {
/* Map Arrays, make uppercase if wanted
var yy = array.map(function(x){ return x.toUpperCase() })*/
// Sort function
var sorted_arr = array.slice().sort(); // We use slice to clone the array so the original array won't be modified)
var results = [];
@dillansimmons
dillansimmons / JQueryEqualHeight.js
Last active October 19, 2016 16:19
JQueryEqualHeight
// Equal height function (finds tallest of all and matches) takes class/id/html-element
var equal_height = function equalheight(element) {
maxheight=0;
// Find Tallest of elements
$(element).each(function(){
maxheight = $(this).height() > maxheight ? $(this).height() : maxheight;
})
// Make all elements the same height.
$(element).height(maxheight);
};
@dillansimmons
dillansimmons / filterOutDuplicatesArray.js
Last active October 18, 2016 18:19
Filter out duplicates from array and create new array.
// Array
var x = ['x','x','y','q','x'];
var list_no_dupes = function(ogArray) {
// Filter and return new array
var newArray = ogArray.filter(function(ele, pos) {
return ogArray.indexOf(ele) === pos;
});
return newArray;
};
@dillansimmons
dillansimmons / recaptchaMarketo.js
Created October 21, 2016 05:51
Insert Google reCAPTCHA into Marketo form with validation
/* Load the Google reCAPTCHA API : Make sure it loads somewhere above the insert code-->
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
*/
/* Main code that inserts the reCAPTCHA into the marketo form */
// Wait for Marketo form to load
MktoForms2.whenReady(function (form) {
// Insert the recap div after the last form row
$( '<div id="recap"></div>' ).insertAfter( ".mktoFormRow:last-of-type" );
// render the recap : replace with your site key
@dillansimmons
dillansimmons / firstTouchUTMCookie.js
Created October 25, 2016 19:29
Store first touch utm in cookie and input into hidden field (Cookie.js, JQuery)
// Initiate JQUERY
// Initiate cookie.js : https://github.com/js-cookie/js-cookie
// Parse the URL
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
// Give the URL parameters variable names
@dillansimmons
dillansimmons / findAndReplaceWP.sql
Last active August 16, 2017 15:39
Worpdpress: Find and Replace URL
UPDATE wp_options SET option_value = replace(option_value, 'http://olddomain.com', 'http://newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://olddomain.com','http://newdomain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://olddomain.com', 'http://newdomain.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://olddomain.com', 'http://newdomain.com');
@dillansimmons
dillansimmons / parseURL.js
Last active August 16, 2017 15:39
Parse URL values
// JS for grabbing utm params
var getRefQueryParam = function() {
var temp = {};
document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function() {
var decode = function(s) {
return decodeURIComponent(s.split("+").join(" "));
};
temp[decode(arguments[1])] = decode(arguments[2]);
});
return temp;
@dillansimmons
dillansimmons / passUTM.js
Last active August 26, 2024 10:35
Pass current UTMS to in page links Javascript
// JS for grabbing utm params and parsing into url
var getRefQueryParam = function() {
var temp = {};
document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function() {
var decode = function(s) {
return decodeURIComponent(s.split("+").join(" "));
};
temp[decode(arguments[1])] = decode(arguments[2]);
});
return temp;
@dillansimmons
dillansimmons / RestrictFreeMail_Marketo.js
Last active June 11, 2020 19:47
Restrict free email addresses: Marketo
// Taken from http://developers.marketo.com/blog/restrict-free-email-domains-on-form-fill-out/
// Prepared by Ian Taylor and Murtza Manzur on 9/9/2014 - Modified Dillan Simmons 8/15/17
(function (){
// Please include the email domains you would like to block in this list
var invalidDomains = ["@gmail.","@yahoo.","@hotmail.","@live.","@aol.","@outlook.","@test."];
MktoForms2.whenReady(function (form){
form.onValidate(function(){
var email = form.vals().Email;