Skip to content

Instantly share code, notes, and snippets.

@veritstudio
veritstudio / strict-eval.js
Created January 8, 2019 18:17
Strict mode and eval
function strictPrice() {
"use strict";
var price = 200;
eval('var price = 100');
console.log(price); // prints 200
}
function nonStrictPrice() {
var price = 200;
@veritstudio
veritstudio / strict-variables.js
Last active January 8, 2019 17:57
Declaring variables in strict mode
function assignStrict() {
"use strict";
someValue = 1; // error
}
function assignWithoutStrict() {
someValue = 1; // no errors
}
assignStrict();
@veritstudio
veritstudio / strict-function.js
Created January 8, 2019 17:48
Enable strict mode for function
function newExtraFunction() {
"use strict";
}
@veritstudio
veritstudio / redirect.js
Last active December 1, 2018 14:03
Middleware to redirect trailing slash with query parameters
const url = require('url')
module.exports = (config) => {
return (req, res, next) => {
let current = req.protocol + '//' + req.get('host') + req.originalUrl,
withSlash = addSlash(current)
if (current == withSlash) {
next()
@veritstudio
veritstudio / app.js
Created November 26, 2018 21:54
Remove duplicates from array
let names = ['John', 'Alice', 'John', 'Jake', 'Jane', 'Jake'];
function removeDuplicates(duplicates) {
return Array.from(new Set(duplicates));
}
names = removeDuplicates(names);
console.log(names); //output: ["John", "Alice", "Jake", "Jane"]
@veritstudio
veritstudio / bot.js
Created November 15, 2018 15:07
Auction bot
var auctioner = (function ($) {
var module = {};
module.deuterButton = $('.js_sliderDeuteriumMax');
module.deuterInput = $('');
module.submitButton = $('.right_content a.pay');
module.maxAmount = 500000;
module.currentAmount = $('.div_trader .currentSum');
module.currentPlayer = $('.div_trader .currentPlayer');
@veritstudio
veritstudio / content.html
Created October 25, 2018 13:12
Add link inside magento 2 email templates
<!-- // Add this inside html file -->
<a href="{{store direct_url='contact-us'}}">Contact Us</a>
@veritstudio
veritstudio / index.js
Last active October 19, 2018 10:34
Sort array of objects by key value
let coutries = [
{country: 'France', position: 3},
{country: 'Germany', position: 5},
{country: 'Spain', position: 1},
{country: 'Portugal', position: 4},
{country: 'Italy', position: 2}
];
@veritstudio
veritstudio / list.phtml
Created October 17, 2018 14:03
Add custom attribute to img tag
<?php
$productImage = $block->getImage($_product, $image, ['class'=>'float-left']);
?>
@veritstudio
veritstudio / customForm.js
Last active October 12, 2018 09:34
Get formKey for custom forms using JavaScript
define([
'jquery',
'uiComponent',
'ko',
'jquery/ui',
], function ($, Component, ko) {
'use strict';
return Component.extend({