Skip to content

Instantly share code, notes, and snippets.

@ncochard
ncochard / babel-webpack.md
Last active September 29, 2023 05:15
The correct way to compile ES6 using babel...

When you create a npm package, remember it might be used in a browser or a server, or even a command line utility… For each package you create, please pay attention at what it will be used for:

  1. Is it going to be used as a dependency to a nodejs application that is not bundled? (e.g. command line utilities)
  2. Is it going to be used as a dependency to a nodejs application that is bundled? (e.g. AWS Lambdas)
  3. Is it going to be used as a dependency to a browser application (always bundled)?.
  • In cases 2) and 3) you want to allow for tree shaking.
  • In cases 1) and 2) you want to benefit from the "ES6"/"ES next" features supported natively by nodejs.
  • In case 3) you also want to benefit from the native support of "ES6" from your browser.
@tessguefen
tessguefen / critical_css.xml
Created October 17, 2017 22:14
Add critical css files to /critical_css/
<mvt:if expr="g.request_cookies:critical_css NE 1 AND g.Screen CIN '|SFNT|CTGY|PLST|PROD|'">
<script>!function(a){"use strict";var b=function(b,c,d){function j(a){return e.body?a():void setTimeout(function(){j(a)})}function l(){f.addEventListener&&f.removeEventListener("load",l),f.media=d||"all"}var g,e=a.document,f=e.createElement("link");if(c)g=c;else{var h=(e.body||e.getElementsByTagName("head")[0]).childNodes;g=h[h.length-1]}var i=e.styleSheets;f.rel="stylesheet",f.href=b,f.media="only x",j(function(){g.parentNode.insertBefore(f,c?g:g.nextSibling)});var k=function(a){for(var b=f.href,c=i.length;c--;)if(i[c].href===b)return a();setTimeout(function(){k(a)})};return f.addEventListener&&f.addEventListener("load",l),f.onloadcssdefined=k,k(l),f};"undefined"!=typeof exports?exports.loadCSS=b:a.loadCSS=b}("undefined"!=typeof global?global:this);
</script>
<noscript><link href="&mvt:global:theme_path;/css/all.min.css" rel="stylesheet" type="text/css" defer="defer"></noscript>
<mvt:if expr="g.Screen EQ 'SFNT'">
@tessguefen
tessguefen / example.xml
Created December 6, 2016 21:38
Order report with dynamic headers (product codes).
<mvt:assign name="l.comma" value="asciichar('44')" />
<mvt:assign name="l.linebreak" value="asciichar('10')" />
<mvt:foreach iterator="order" array="admin_order:orders">
<mvt:foreach iterator="group" array="order:groups">
<mvt:comment> <!-- Build Dynamic Array --> </mvt:comment>
<mvt:if expr="miva_array_search( l.settings:products, 0, l.item, 'l.item:code EQ l.settings:group:code' )">
<mvt:assign name="l.item:quantity" value="l.item:quantity + l.settings:group:quantity" />
<mvt:assign name="l.item:subtotal" value="l.item:subtotal + l.settings:group:subtotal" />
<mvt:else>
@bheyde
bheyde / coupon_batch_report.html
Created December 5, 2016 20:01
Coupon Batch Report
<mvt:foreach iterator="order" array="admin_order:orders">
<mvt:foreach iterator="coupon" array="order:coupons">
<mvt:comment>
:code
:coupon_id
:order_id
:total (discount applied to order)
@tessguefen
tessguefen / example.xml
Last active December 7, 2016 16:14
Group Products Codes together into new array
<mvt:foreach iterator="group" array="basket:groups">
<mvt:comment> <!-- Build Dynamic Array --> </mvt:comment>
<mvt:if expr="miva_array_search( l.settings:new_array, 0, l.item, 'l.item:code EQ l.settings:group:code' )">
<mvt:assign name="l.item:quantity" value="l.item:quantity + l.settings:group:quantity" />
<mvt:else>
<mvt:assign name="l.success" value="miva_array_insert( l.settings:new_array, l.settings:group, -1 )" />
</mvt:if>
<mvt:comment> <!-- Build Dynamic Array --> </mvt:comment>
</mvt:foreach>
@bheyde
bheyde / variant_price_range.html
Created November 15, 2016 23:12
Load High / Low Price Range for a Product with Attributes (pricing at attribute level)
<mvt:comment>
Load all possible variants using toolkit
</mvt:comment>
<mvt:item name="toolkit" param="variantarray|vcount|g.product_code" />
<mvt:comment>
Loop though variants, load product information for each variant, insert into new array
</mvt:comment>
@wojteklu
wojteklu / clean_code.md
Last active May 7, 2024 22:33
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@bheyde
bheyde / scheduled_task.mv
Last active July 15, 2016 15:35
Example Scheduled Task Module
<MvFUNCTION NAME = "Module_Description" PARAMETERS = "module var" STANDARDOUTPUTLEVEL = "">
<MvASSIGN NAME = "l.module:code" VALUE = "call_url_stsk">
<MvASSIGN NAME = "l.module:name" VALUE = "HTTP Request to URL">
<MvASSIGN NAME = "l.module:provider" VALUE = "Miva Merchant">
<MvASSIGN NAME = "l.module:version" VALUE = "9.0003">
<MvASSIGN NAME = "l.module:api_ver" VALUE = "9.05">
<MvASSIGN NAME = "l.module:description" VALUE = "This Scheduled Task allows you to setup a URL which will get called via an http request when the task is run.">
<MvASSIGN NAME = "l.module:features" VALUE = "util, vis_util, scheduledtask">
</MvFUNCTION>
@bheyde
bheyde / mvt_call_headers.html
Created July 14, 2016 15:49
mvt:call - passing custom headers example
<mvt:assign name="g.api_endpoint" value="'https://DJDHGSDJD-dsn.algolia.net'" />
<mvt:assign name="g.index_name" value="'docs.miva'" />
<mvt:assign name="g.path" value="'/1/indexes/' $ g.index_name $ '/390342730'" />
<mvt:assign name="g.api_request" value="g.api_endpoint $ g.path" />
<mvt:assign name="g.headers" value="'X-Algolia-API-Key: 17181817181912' $ asciichar( 13 ) $ asciichar( 10 )" />
<mvt:assign name="g.headers" value=" g.headers $ 'X-Algolia-Application-Id: HSGDJDJDGD' $ asciichar( 13 ) $ asciichar( 10 )" />
<mvt:call action="g.api_request" method="'PUT'" headers="'g.headers'">
@tessguefen
tessguefen / header-example.php
Last active March 17, 2017 23:01
Transient for WordPress & Miva Blog
if ( false === ( $mivaHeader = get_transient( 'miva_header' ) ) ) {
$mivaHeader = file_get_contents("http://" . $hostname . "/mm5/merchant.mvc?Screen=WP-HEADER");
set_transient( 'miva_header', $mivaHeader, 24 * HOUR_IN_SECONDS );
}
echo $mivaHeader;