Skip to content

Instantly share code, notes, and snippets.

View uhhuhyeah's full-sized avatar

David A McClain uhhuhyeah

View GitHub Profile
@uhhuhyeah
uhhuhyeah / optimizely.md
Created October 1, 2013 21:35
How to implement Optimizely on a single page app

Optimizely's script is included in the document's head so they're able to make DOM/Styling changes before the browser has really had the time to render anything. The point of this is to prevent the "flash" of changing the content in front of the user.

This paradigm breaks down with "single page apps". The paradigm that "single page apps" use is one where the initial page load contains just enough HTML and JavaScript to bootstrap the app. The app then downloads/renders the remaining HTML. The problem is that all this happens after Optimizely has tired to make changes and because these elements Optimizely is trying to change are not present on the page yet, it cannot successfully run the code to make the variation.

Here's the workaround we've been using. Create your variation as per norm with the WYSIWYG editor Optimizely provides. Click on 'Edit Code' in the bottom right to reveal the JavaScript Optimizely will run on the page. This is usually jQuery-esque show/hide/replace etc. Write a function that che

@uhhuhyeah
uhhuhyeah / optimizelyRunningExperiments.js
Created September 27, 2013 19:58
Log what Optimizely experiments and variations you have been bucketed into
for (var i=0; i < window.optimizely.data.state.activeExperiments.length; i++) {
var experimentID = window.optimizely.data.state.activeExperiments[i];
var experimentName = window.optimizely.data.experiments[experimentID].name;
var variationName = window.optimizely.data.state.variationNamesMap[experimentID];
console.log(experimentName + " - " + variationName);
}
window.utils = window.utils || {};
utils.Grid = function() {
 // Defaults
 var that = this;
 this.idealColumnWidth = 320;
 this.marginHoriz = 15;
   
 // Public Interface
 this.setupGrid = function(opts) {
@media all {
.page-break {
display: none;
}
}
@media print {
.page-break {
display: block;
page-break-before: always;
@uhhuhyeah
uhhuhyeah / sprocket-helper.css.scss
Created October 23, 2012 16:57
Using sprocket helpers in css (asset pipeline)
.foo {
background: url( image_path 'image.png' );
}
@uhhuhyeah
uhhuhyeah / erb-pre-processing.css.scss.erb
Created October 23, 2012 16:56
Using erb in css (asset pipeline)
.foo {
background: url(<%= asset_path 'image.png' %>);
}
@uhhuhyeah
uhhuhyeah / ids-from-dom-elements.js
Created October 22, 2012 04:56
grab the ids (or other attribute) from a set of DOM elements
// grab the ids (or other attribute) from a set of DOM elements
var ids = $("#mydiv span[id]") // find spans with ID attribute
.map(function() { return this.id; }) // convert to set of IDs
.get(); // convert to instance of Array (optional)
@uhhuhyeah
uhhuhyeah / fancy-javascript.js
Created October 22, 2012 04:49
Fancy JavaScript
if ( foo == "bar" || foo == "foobar" || foo == "foo" ) {
//...
}
// can be written as
if ( foo in { bar:1, foobar:1, foo:1 } ) {
//...
}
@uhhuhyeah
uhhuhyeah / self-clearing-floats-ie.css
Created October 22, 2012 04:29
Self-clearing floats IE
* html .some-floated-element { /* IE6 */
height: 1%;
}
*:first-child+html .some-floated-element { /* IE7 */
min-height: 1px;
}
@uhhuhyeah
uhhuhyeah / self-clearing-floats.css
Created October 22, 2012 04:25
Self-clearing floats
.some-floated-element:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}