Skip to content

Instantly share code, notes, and snippets.

View craigmr's full-sized avatar

Craig Simpson craigmr

View GitHub Profile
@craigmr
craigmr / user-exentsions.js
Created July 11, 2013 18:23
So at work we are setting up a selenium RC 1 grid. We decided to use RC1 and not web drivers since we can setup user-extensions to create locations and custom actions for our QA team. We’ve slowly got the grid running with our python test cases running the client drivers. Somewhere in the setup (we still don’t know the cause) our user extensions…
//This is a fix to get the user-extensions working for RC. The check is to prevent a runtime error in the IDE
//since the IDE does not contain command factory.
if(this['commandFactory']){
commandFactory.registerAll(selenium);
}
@craigmr
craigmr / gist:5e83e12fb2e102c7b43f
Last active August 29, 2015 14:20
Example of Race Condition
/**
* calculateZ() is a simplified version of a race conidtion. We have two ansync tasks
* that modifiy the state before each call is complete.
*/
function calculateZ() {
let x = 0, y = 0, z;
//Async call to get the true value of y
setTimeout(() => y = 2, Math.random() * 1000);
@craigmr
craigmr / gist:c83320db1d230210b8b3
Last active August 29, 2015 14:20
Chained Async Calls to Prevent Race Conditions
/**
* calculateZChained() Chain the two aysnc calls together to fix the race condition.
*/
function calculateZChained() {
let x = 0, y = 0, z;
//Async call to get the true value of y
setTimeout(() => {
y = 2;
@craigmr
craigmr / gist:3cc34725cd82e81e3a4e
Last active August 29, 2015 14:20
Promise Async Calls to Prevent Race Conditions
/**
* calculatePromise() Use promises to get x and y values, now we can run our
* async tasks in parallel using Promise.all. Once we have both values
*/
function calculatePromise() {
var y = new Promise((resolve, reject) => {
setTimeout(() => resolve(2), Math.random() * 1000);
});
var x = new Promise((resolve, reject) => {
@craigmr
craigmr / breadcrumb.js
Last active August 29, 2015 14:21
How Functional Programing Can Avoid Broken State
(function nonFunctionalExample(){
this.breadCrumb = []; //<-- external state
this.node = {
name: "Child",
parent: {
name: "Parent"
}
};
@craigmr
craigmr / zip-poly-factory.js
Created May 28, 2015 18:24
How would you implement the following factory?
var zipCodeData = {
'30324': {
value: 10
//Etc.
}
};
var map = new google.maps.Map(document.getElementById('map-canvas'), {});
var zipPolys = createZipPolygons(map);
@craigmr
craigmr / VIBirst.js
Last active August 29, 2015 14:24
Sample way to configure product specific Birst api
angular.module('valueIntelligence.test', [])
.config(function(VIBirstProvider) {
VIBirstProvider.setConfig({
url: ''
});
});
angular.module('valueIntelligence.test').provider('VIBirst', function(){
var saConfig = {};
@craigmr
craigmr / using_concat.js
Created July 29, 2015 15:45
Reduce code to reduce bugs
//So writing out the arrays like this works but will lead to bugs b/c since allQueries is just conversionTotalsQueries and conversionTypeQueries
//combined you might forget to update one array. To prevent that just concat the two.
var allQueries = [conversionsQueryMonth, leadsQueryMonth, actionsQueryMonth, conversionsQueryDay, leadsQueryDay, actionsQueryDay];
var conversionTotalsQueries = [conversionsQueryMonth, conversionsQueryDay];
var conversionTypeQueries = [actionsQueryMonth, actionsQueryDay, leadsQueryMonth, leadsQueryDay];
//refactored to use less code and prevent bugs
var conversionTotalsQueries = [conversionsQueryMonth, conversionsQueryDay];
var conversionTypeQueries = [actionsQueryMonth, actionsQueryDay, leadsQueryMonth, leadsQueryDay];
var allQueries = conversionTotalsQueries.concat(conversionTypeQueries); //Returns new array so conversionTotalsQueries is not modified
@craigmr
craigmr / widget.html
Last active September 2, 2015 03:27
Captionable Widget Test
<!-- Start Captionable Widget Tag -->
<script>
var username = 'charliereid';
var width = 300;
var height = 250;
document.write('<iframe src="http://play.captionable.com/widget/'+ encodeURI(username) +'?w='+ width +'&h='+ height +'" width="'+ width +'" height="'+ height +'" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" allowtransparency="true"></iframe>');
</script>
<!-- End Captionable Widget Tag -->
@craigmr
craigmr / widget-simple.html
Created September 8, 2015 00:51
Captionable Simple Widget
<div style="width:300px; height:250px; text-align: center;">
<a href="http://play.captionable.com/widget/charliereid/link" target="_blank" style="padding: 0;margin: 0;">
<img src="http://play.captionable.com/widget/charliereid/image" alt="Can you guess the caption?" height="250" width="250">
</a>
</div>