Skip to content

Instantly share code, notes, and snippets.

@dimsemenov
dimsemenov / track-js-error.js
Created December 28, 2014 07:48
Track JavaScript errors with Google Analytics (as events)
(function() {
function trackJavaScriptError(e) {
e = e || window.event;
if(!e || !e.message || !e.lineno){
return true;
}
var errMsg = e.message;
var errSrc = e.filename + ': ' + e.lineno;
ga('send', 'event', 'JavaScript Error', errMsg, errSrc, { 'nonInteraction': 1 });
}
@dimsemenov
dimsemenov / vcl-regex-cheat-sheet
Last active March 12, 2022 19:01
Regular expression cheat sheet for Varnish (.vcl). Examples of vcl regexp. Found here http://kly.no/varnish/regex.txt (by Kristian Lyngstøl)
Regular expression cheat sheet for Varnish
Varnish regular expressions are NOT case sensitive. Varnish uses POSIX
regular expressions, for a complete guide, see: "man 7 regex"
Basic matching:
req.url ~ "searchterm"
True if req.url contains "searchterm" anywhere.
req.url == "searchterm"
/**
*
* desktop-zoom.js:
*
* - Binds mousewheel event for paning zoomed image.
* - Manages "dragging", "zoomed-in", "zoom-out" classes.
* (which are used for cursors and zoom icon)
* - Adds toggleDesktopZoom function.
*
*/
@dimsemenov
dimsemenov / get-image-size.js
Last active February 18, 2018 17:34
I was looking for a way to get an image size with JavaScript before it's completely loaded. It's useful, for example, when you want to display it progressively. I've figured out that we can just fire an interval that will run until an image has defined width. Here is how it works:
// detect if naturalWidth property is supported
// getting it is much faster than getComputedStyle()
var supportsNatural = ( "naturalWidth" in (new Image()) ),
imagePath = 'image.jpg',
interval,
hasSize,
onHasSize = function() {
if(hasSize) return;
var naturalWidth = supportsNatural ? img[0].naturalWidth : img.width();
(function(window) {
'use strict';
var toggleEvent = function(el, name, fn, unbind) {
var methodName = (unbind ? 'remove' : 'add') + 'EventListener';
el[methodName](name, fn, false);
};
@dimsemenov
dimsemenov / ba.css
Created October 27, 2017 21:08
Before/After image viewer, will probably create a separate repo for it some day... (c)
img {
margin: 0;
padding: 0;
display: block;
}
.ba-viewer {
overflow: hidden;
position: relative;
width: 100%;
function fire_royalslider_func($atts){
$sliderid = $atts['id'];
$out = '';
if (!$sliderid) return;
/* Print slider HTML, skip this part if you already have it on page */
$out .= get_new_royalslider($sliderid);
/* Print slider END */
// Init code
@dimsemenov
dimsemenov / count-words.js
Created October 21, 2016 08:48
Counts words & sorts them by number of occurences
var fileToTest = grunt.file.read('somefile.js');
var vars = fileToTest.match(/(\w+)/g);
var i = vars.length;
var count;
var parsedVars = [];
var maxWordLen = 3;
while(i--) {
var word = vars[i];
<?php
$collection = Mage::getModel('review/review')->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
->setDateOrder();
$collection->getSelect()
->join(array('attr' => 'catalog_product_entity_int'), 'attr.entity_id = main_table.entity_pk_value', array('*'))
->where('attr.attribute_id = 136')