Skip to content

Instantly share code, notes, and snippets.

View caleboleary's full-sized avatar

Caleb O'Leary caleboleary

View GitHub Profile
@caleboleary
caleboleary / mocha.js
Created December 7, 2016 18:57
Mocha & Chai Javascript Unit Testing Quick Start http://codepen.io/caleboleary/pen/YpLbRJ
<style>@charset "utf-8";body{margin:0}#mocha{font:20px/1.5 "Helvetica Neue",Helvetica,Arial,sans-serif;margin:60px 50px}#mocha ul,#mocha li{margin:0;padding:0}#mocha ul{list-style:none}#mocha h1,#mocha h2{margin:0}#mocha h1{margin-top:15px;font-size:1em;font-weight:200}#mocha h1 a{text-decoration:none;color:inherit}#mocha h1 a:hover{text-decoration:underline}#mocha .suite .suite h1{margin-top:0;font-size:.8em}#mocha .hidden{display:none}#mocha h2{font-size:12px;font-weight:normal;cursor:pointer}#mocha .suite{margin-left:15px}#mocha .test{margin-left:15px;overflow:hidden}#mocha .test.pending:hover h2::after{content:'(pending)';font-family:arial,sans-serif}#mocha .test.pass.medium .duration{background:#c09853}#mocha .test.pass.slow .duration{background:#b94a48}#mocha .test.pass::before{content:'✓';font-size:12px;display:block;float:left;margin-right:5px;color:#00d6b2}#mocha .test.pass .duration{font-size:9px;margin-left:5px;padding:2px 5px;color:#fff;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.2);-moz-box-sh
@caleboleary
caleboleary / emailformatmobile-snippet.xml
Created December 5, 2016 17:40
sublime snippet, convert "display:block" to a formatted style with mirrored and fomatted name (.m-display-block{display:block;} )
<snippet>
<content>
<![CDATA[.${1:m-${SELECTION/[\s:;#]+/-/g}}{${SELECTION};} ]]>
</content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>emailformatmobilecss</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>text.html</scope>
<!-- Optional: Description to show in the menu -->
<description>Email Format Mobile CSS</description>
@caleboleary
caleboleary / recursive-object-string-search.js
Created June 29, 2016 14:24
recursive object string search
function recursiveObjectStringSearch(needleString, hayStackObject){
var result = [];
for(var index in hayStackObject) {
if (hayStackObject.hasOwnProperty(index)) {
if (typeof hayStackObject[index] === 'string'){
if (needleString.indexOf(hayStackObject[index]) > -1 || hayStackObject[index].indexOf(needleString) > -1) {
result.push(hayStackObject[index]);
continue;
}
}
@caleboleary
caleboleary / accordion.js
Last active June 27, 2016 16:42
simple accordion set up jQuery
// simple accordion set up for prod tabs
$(document).ready(function(){
var coSimpleAccordion = (function($) {
'use strict';
var coSimpleAccordion = {
init: function() {
$('.tabHead.open').nextAll('div.tabBody').addClass('open').show();
$('.tabHead.closed').nextAll('div.tabBody').addClass('closed').hide();
coSimpleAccordion.listen();
},
@caleboleary
caleboleary / mvt-string-cleaner-scrubber.html
Last active May 4, 2016 15:53
http://snippets.miva.com/id/1462377050/1 String Scrubber/Cleaner -- define an allowed alphabet, delete all characters not in alphabet
<mvt:comment>define your allowed characters</mvt:comment>
<mvt:assign name="g.allowed" value="'abcdefghijklmnopqrstuvwxyz'" />
<mvt:comment>the string to scrub</mvt:comment>
<mvt:assign name="g.string" value="'Test123-!hello'" />
<mvt:assign name="g.counter" value="1" />
<mvt:comment>for each letter in string</mvt:comment>
<mvt:while expr="g.counter LE len(g.string)">
<mvt:comment>if this letter is contained in allowed, increment</mvt:comment>
<mvt:if expr="substring(g.string, g.counter, 1) CIN g.allowed">
<mvt:assign name="g.counter" value="g.counter+1" />
@caleboleary
caleboleary / mvtdo-upcharge.html
Created April 25, 2016 16:46
Miva mvt:do custom upcharge template
<mvt:comment>
|
|
| Efficient mvt:do custom upcharges - function similar to toolkit upcharges
| assign the 4 below variables and drop in anywhere above basket charge loop
|
|
</mvt:comment>
<mvt:assign name="g.customCharge:value" value="28" />
<mvt:assign name="g.customCharge:type" value="'CustomUpcharge'" />
@caleboleary
caleboleary / unique.js
Last active April 25, 2016 14:35
javascript make array unique speed (filter vs for loop/indexOf) hint: filter wins
console.time('1');
var data = [1,4,56,4,6,4,3,6,7,7,4,3,7,5,34,3,5,7,45,43];
console.log(data.sort().filter(function(n,i){
return data[i] !== data[i+1];
}));
console.timeEnd('1');
console.time('2');
var data = [1,4,56,4,6,4,3,6,7,7,4,3,7,5,34,3,5,7,45,43];
var uniq = [];
<mvt:assign name="g.string" value="'one|two|three|four|five|six'" />
<h3>Split String mvt:do</h3>
<p>Does not inherently support multi-character splitting, you'd have to perform a glosub first (see next example)</p>
<mvt:do file="g.Module_Library_Utilities" name="l.success" value="SplitString( g.string, '|', g.splitString )" />
<!-- @@ &mvt:global:MvDO_Error; -->
<mvt:foreach iterator="line" array="global:splitString">
&mvt:line;</br>
</mvt:foreach>
@caleboleary
caleboleary / twitter_image_size.html
Created April 5, 2016 16:49
Miva check twitter image filesize and act accordingly before displaying the twitter card image tag
<mvt:comment>
|
| This checks whether the image you're going to send in the twitter card is below 1mb in size, and sends or generates a small version depending
|
</mvt:comment>
<mvt:comment>IF THE IMAGE CUSTOM FIELD IS SET UP</mvt:comment>
<mvt:if expr="l.settings:product:customfield_values:productimagecustomfields:social_image">
<mvt:comment>IF THE IMAGE'S SIZE IS GREATER THAN 1MB</mvt:comment>
<mvt:if expr="ssize('/mm5/'$l.settings:product:customfield_values:productimagecustomfields:social_image) GT 1000000">
var doorState = 'CLOSED';
var inputs = ['button_clicked','cycle_complete','button_clicked','button_clicked','button_clicked','button_clicked','button_clicked','cycle_complete'];
console.log('Door: '+doorState);
for (var i = 0; i < inputs.length; i++) {
if (inputs[i] == 'button_clicked') {
//button clicked actions
if (doorState == 'CLOSED' || doorState == 'STOPPED WHILE CLOSING') {
doorState = 'OPENING';
}
else if (doorState == 'CLOSING') {