Skip to content

Instantly share code, notes, and snippets.

View guillaumegarcia13's full-sized avatar
💭
Building awesome things 🚀

GARCIA Guillaume guillaumegarcia13

💭
Building awesome things 🚀
View GitHub Profile
@guillaumegarcia13
guillaumegarcia13 / launchpad_trick.js
Last active July 2, 2019 11:51
Exposing internals of a Launchpad-launched Neptune app
// Expose variable when launched from Launchpad
if (sap.n) {
var attr; // optional (fill with the name of the window attribute you want, eg. 'APPxxx')
var exposed = (attr) ? window[attr] = {}
: window;
var regex = /var (\w*) \= new /gm; // regexp to determine all variable names (and a few wrong ones)
var funcCode = arguments.callee + '';
var match;
while ((match = regex.exec(funcCode)) !== null) {
@guillaumegarcia13
guillaumegarcia13 / findVal.js
Created June 20, 2019 18:54
Recursively search object attributes
// From https://stackoverflow.com/questions/40603913/search-recursively-for-value-in-object-by-property-name
function findVal(obj, key) {
var seen = new Set;
var active = [obj];
while (active.length) {
var new_active = [];
var found = [];
for (var i=0 ; i<active.length ; i++) {
// See: https://stackoverflow.com/questions/24586110/resolve-promises-one-after-another-i-e-in-sequence/31070150#31070150
// https://decembersoft.com/posts/promises-in-serial-with-array-reduce/
/*
* Serialize promises (or rather tasks because once created, a Promise starts executing immedialtely
*/
const promiseSerializer = (tasks: Array<()=>Promise<any>>) => {
return tasks.reduce((promiseChain: Promise<any>, currentTask: ()=>Promise<any>) => {
return promiseChain.then(chainResults =>
currentTask().then(currentResult =>
@guillaumegarcia13
guillaumegarcia13 / button-masking.js
Created November 25, 2018 22:18
Wrapping and masking a button with jQuery
$('input#checkout').wrap('<div id="bf"><div>');
var $cloneInput = $('input#checkout').clone();
$cloneInput
.attr('id', 'bf_checkout')
.attr('name', 'bf_checkout')
.appendTo('div#bf')
.on('click', function(e) {
doSomething().always(function() {
$('input#checkout').click(); // call underlying button
});
<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
var Shopify = Shopify || {};
Shopify.optionsMap = {};
Shopify.updateOptionsInSelector = function(selectorIndex) {
@guillaumegarcia13
guillaumegarcia13 / git-log-alias.sh
Created September 20, 2018 07:52
Git Log alias
# From: https://coderwall.com/p/euwpig/a-better-git-log
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
{% comment %}
Remove sold-out variants.
Only works for products that have one option.
It won't work with products that have two or three options, like Size and Color.
See: https://docs.myshopify.io/themes/customization/products/hide-variants-that-are-sold-out
{% endcomment %}
{% if product.options.size == 1 %}
<script>
var $addToCartForm = $('form[action="/cart/add"]');
{% comment %}
Disable sold-out variants.
Only works for products that have one option.
It won't work with products that have two or three options, like Size and Color.
See: https://docs.myshopify.io/themes/customization/products/hide-variants-that-are-sold-out
{% endcomment %}
{% if product.options.size == 1 %}
<script>
var $addToCartForm = $('form[action="/cart/add"]');
@guillaumegarcia13
guillaumegarcia13 / fiddler.ts
Last active September 6, 2018 13:46
Debug node.js requests with Fiddler
/* Adapted from: https://weblogs.asp.net/dixin/use-fiddler-with-node-js
/* Usage:
import { Fiddler } from './../src/helpers/fiddler';
...
Fiddler.proxyRequests();
*/
import * as url from 'url';
import * as http from 'http';
<!-- VIEW
Trick to download document silently (without opening a new tab) -->
<iframe *ngIf="hiddenUrl" class="hidden" [src]="hiddenUrl">
</iframe>
<!-- CONTROLLER -->
public hiddenUrl: SafeUrl;
...