Skip to content

Instantly share code, notes, and snippets.

View nrkn's full-sized avatar

Nik nrkn

View GitHub Profile
<div id="ProductSection" data-section-id="{{ section.id }}" data-section-type="product-template" data-zoom-toggle="zoom-in" data-zoom-enabled="{{ section.settings.product_image_zoom_enable }}" data-related-enabled="{{ section.settings.product_related_enable }}" data-social-sharing="{{ section.settings.social_sharing }}" data-show-compare-at-price="{{ section.settings.product_show_compare_at_price }}" data-stock="{{ section.settings.product_quantity_message }}" data-incoming-transfer="{{ section.settings.product_incoming_message }}">
{% include 'breadcrumb' %}
<div class="grid" itemscope itemtype="http://schema.org/Product">
<meta itemprop="url" content="{{ shop.url }}{{ product.url }}">
<meta itemprop="image" content="{{ product.featured_image.src | img_url: 'grande' }}">
<div class="grid-item large--two-fifths">
<div class="grid">
<div class="grid-item large--eleven-twelfths text-center">
{% assign saved_amount = compare_price | minus: product_price %}
{% comment %}
Unless this store uses multiple currencies,
we will remove the decimals when they are equal to 00,
or when the amount is > 10 (dollars, pounds, etc.).
{% endcomment %}
<!-- using expected price-sale template -->
@nrkn
nrkn / dfs-generator.js
Created June 2, 2017 03:30
Generator for depth first search of a tree node
const dfsGenerator = function*( node ){
const nodes = [ node ]
while( nodes.length > 0 ){
const current = nodes.pop()
yield current
let child = current.lastChild
@nrkn
nrkn / dfs-iterator.js
Last active June 2, 2017 03:34
Iterator for depth first search of a tree node
const dfsIterator = node => {
const nodes = [ node ]
const next = () => {
const done = nodes.length === 0
if( done ) return { done }
const value = nodes.pop()
let child = value.lastChild
const flatten = array => {
const result = []
const nodes = array.slice()
let node
while( nodes.length > 0 ){
node = nodes.pop()
if( Array.isArray( node ) ){
nodes.push( ...node )
@nrkn
nrkn / how-to-do-stuff.md
Created May 30, 2017 00:08
How to do stuff

How to do stuff

Why would I want to do stuff?

You would probably want to do stuff because:

  • Stuff is fun
  • Stuff is good

How do I get into stuff?

@nrkn
nrkn / adapter.ts
Last active October 17, 2016 02:12
interface Predicate<T> {
( subject:T ): boolean
}
interface DomAdapter<TNode, TElementNode> {
// is the node a tag?
isTag: Predicate<TNode>,
// does at least one of passed nodes pass the test?
existsOne: ( test:Predicate<TElementNode>, nodes:[TNode] ) => boolean,
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/index.js",
"stopOnEntry": false,
"args": [],
@nrkn
nrkn / stringify.js
Last active July 19, 2023 08:24
Human readable json stringify where simple arrays use only one line
const isPrimitive = obj =>
obj === null ||
[ 'string', 'number', 'boolean' ].includes( typeof obj )
const isArrayOfPrimitive = obj =>
Array.isArray( obj ) && obj.every( isPrimitive )
const format = arr =>
`^^^[ ${
arr.map( val => JSON.stringify( val ) ).join( ', ' )
const template = data =>
`<p>
Use the <strong>${ data.power }</strong>, ${ data.name }!
</p>`
document.getElementById( 'target' ).innerHTML = template( {name: "Luke", power: "force"} )