Skip to content

Instantly share code, notes, and snippets.

View 7LayersDesign's full-sized avatar

Andy Hutchins 7LayersDesign

View GitHub Profile
@7LayersDesign
7LayersDesign / courtesylink.js
Last active December 20, 2015 12:59
To make this change, just add a courtesyLink to each center recipe. This will override the general one set at the top. Below is an example. This is the Food.com version which is a little different, but the courtesyLink is the same.
@7LayersDesign
7LayersDesign / trackme.js
Last active December 21, 2015 07:18
Tracking function.
_doTracking: function(tag){
var cacheBuster = (new Date()).getTime(),
$body = $('body'),
$tracker = $('#dynamic-tracking');
tag += "&cb=$timestamp$";
// Select or create tracking image
if( $tracker.length > 0 ) {
// Updated existing element
$tracker.attr('src', tag.replace(/\$timestamp\$/, cacheBuster));
} else {
@7LayersDesign
7LayersDesign / query_string_get.js
Created August 20, 2013 15:29
Get query string parameter from 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, " "));
}
@7LayersDesign
7LayersDesign / l4_gmail.php
Last active December 21, 2015 15:49
GMail config for PHP mail in Laravel 4
<?php
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'encryption' => 'ssl',
'username' => 'your-email@gmail.com',
'password' => 'your-password',
@7LayersDesign
7LayersDesign / weightedRandom.js
Last active December 21, 2015 19:58
Weighted random function. Should be used with lists smaller than 100. Passed that is not efficient.
// array of items. Weight must add up to 100
// video1 = 20%, vieo2 = 50%, video3 = 10%, video4 = 20%
var items = ['Video1', 'Video2', 'Video3', 'Video4'];
var weights = [20, 50, 10, 20];
/**
* Return a random value from aItems based on aWeights
* @param {array} aItems Array of you items.
* @param {array} aWeights Array of weights that match items.
* @return {String} Selected item.
@7LayersDesign
7LayersDesign / testWeightedRandom.js
Last active December 21, 2015 19:58
Test the weightRandom function by calling 1000 times and counting each result.
// array of items. Weight must add up to 100
// video1 = 20%, vieo2 = 50%, video3 = 10%, video4 = 20%
var items = ['Video1', 'Video2', 'Video3', 'Video4'];
var weights = [20, 50, 10, 20];
/**
* Return a random value from aItems based on aWeights
* @param {array} aItems Array of you items.
* @param {array} aWeights Array of weights that match items.
* @return {String} Selected item.
@7LayersDesign
7LayersDesign / random_xml
Created August 30, 2013 15:55
Load random XML file.
var randomXML = Math.floor(Math.random()*4);
var xmlUrlArray = new Array(
"placeholder", // PATH TO URL #1
"placeholder", // PATH TO URL #2
"placeholder", // PATH TO URL #3
"placeholder" // PATH TO URL #4
);
flashvars.randomNum = xmlUrlArray[randomXML];
@7LayersDesign
7LayersDesign / l4_table_seeder.php
Created September 9, 2013 16:09
Laravel table seeder template.
<?php
class MyTableTableSeeder extends Seeder {
public function run()
{
DB::table('MyTable')->truncate();
}
}
@7LayersDesign
7LayersDesign / bootstrap-3.html
Created September 11, 2013 19:05
Bootstrap 3 base
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 101 Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="assets/css/bootstrap.min.css" rel="stylesheet" media="screen">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
@7LayersDesign
7LayersDesign / bootstrap-3-starter.html
Created September 11, 2013 19:06
Bootstrap 3 starter template.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../assets/ico/favicon.png">