Skip to content

Instantly share code, notes, and snippets.

View dav11d's full-sized avatar

David dav11d

  • UK
View GitHub Profile
@dav11d
dav11d / gist:5704f8c4b5ad6a13d13f2cab44e0b71e
Created June 3, 2018 21:43 — forked from voskresla/gist:c89266d7e64618c123cd506e9130929c
Shopify link-product-options-in-menus Brooklyn Theme
<script>
// (c) Copyright 2016 Caroline Schnapp. All Rights Reserved. Contact: mllegeorgesand@gmail.com
// See https://docs.shopify.com/themes/customization/navigation/link-product-options-in-menus
// Modified by Jonathan Moore (Style Hatch) https://github.com/jonathanmoore
/*
Updated to work with sectioned themes
- Added required methods from the deprecated options_selection.js
- Triggers an initial variant change
- Hides sold out variants with only one option
@dav11d
dav11d / shopify-auto-currencies-switcher.js
Created April 25, 2018 09:39 — forked from chrisgrabinski/shopify-auto-currencies-switcher.js
(Shopify) Automatically change a shop's currency based on the customer's geolocation
// Dependencies
// - https://github.com/carolineschnapp/currencies
// Don't change currency if Cookie has been already set
if (Currency.cookie.read() == null) {
jQuery.ajax( {
url: '//freegeoip.net/json/',
type: 'GET',
dataType: 'jsonp',
<script>
jQuery.ajax( {
url: '//freegeoip.net/json/',
type: 'POST',
dataType: 'jsonp',
success: function(location) {
// If the visitor is browsing from Canada.
if (location.country_code === 'CA') {
// Tell him about the Canadian store.
jQuery.fancybox.open(jQuery('#message'));
@dav11d
dav11d / collection-sidebar.liquid
Created April 18, 2018 13:47
Shopify Sidebar Tag Filter
<aside id="collection-filters">
<h2>Narrow Results</h2>
{% comment %}Exceptions{% endcomment %}
{% if collection.handle contains 'x' %}{% assign handle = 'y' %}
{% else %}{% assign handle = collection.handle %}{% endif %}
{% for i in (1..5) %}
{% capture include_filter %}{{ handle }}_filter_no_{{ i }}_enable{% endcapture %}
<!-- {{ include_filter }} -->
{% if settings[include_filter] %}
{% capture include_filter %}include_{{ handle }}_filter_no_{{ i }}{% endcapture %}
@dav11d
dav11d / context.ex
Created February 28, 2018 14:57 — forked from ericstumper/context.ex
Guardian Authentication with Absinthe GraphQL in Elixir
defmodule Languafy.Web.Context do
@behaviour Plug
import Plug.Conn
alias Languafy.User
def init(opts), do: opts
def call(conn, _) do
case build_context(conn) do
{:ok, context} ->
function SmoothScroll(target, speed, smooth) {
if (target == document)
target = (document.documentElement || document.body.parentNode || document.body) // cross browser support for document scrolling
var moving = false
var pos = target.scrollTop
target.addEventListener('mousewheel', scrolled, false)
target.addEventListener('DOMMouseScroll', scrolled, false)
function scrolled(e) {
@dav11d
dav11d / script.js
Created January 21, 2018 21:11 — forked from vielhuber/script.js
on mousewheel vanilla js scroll horizontally #js
document.addEventListener('wheel', function(e)
{
if(e.type != 'wheel')
{
return;
}
let delta = ((e.deltaY || -e.wheelDelta || e.detail) >> 10) || 1;
delta = delta * (-300);
document.documentElement.scrollLeft -= delta;
e.preventDefault();
var Excel = require('exceljs');
XLSX = require('xlsx');
var workbook = new Excel.Workbook();
var wb = XLSX.readFile('dhl.xls');
sheet1 = XLSX.utils.sheet_to_json(wb.Sheets.Sheet1);
var rows = new Array();
// import or export top level
npm: {
compilers: ['babel-brunch'],
enabled: true,
styles: {
tachyons: ['css/tachyons.min.css']
}
}
def atc([], new_item) do
[new_item]
end
def atc([h = %{product_id: id, size: size, quantity: old_quantity}|t], %{product_id: id, quantity: growth, size: size}) do
[%{h | quantity: old_quantity + growth}|t]
end
def atc([h|t], new_item) do
[h|atc(t, new_item)]