Skip to content

Instantly share code, notes, and snippets.

View yesasha's full-sized avatar

Aleksandr Yefremov yesasha

  • Israel
View GitHub Profile
@yesasha
yesasha / this-is-not-a-library.js
Last active May 16, 2018 11:17
List of usable functions. Use it as a reference only. Don't plug it as a library.
//////////////// IS //////////////////
// Check if an object is primitive
function isPrimitive (obj) {
var type = typeof obj;
return obj == null || type === 'boolean' || type === 'number' || type === 'string' || type === 'symbol';
}
// Check if an object is primitive
function isPrimitive2 (obj) {
@yesasha
yesasha / location-replacer.js
Created February 15, 2018 15:18
Calls location.replace instead of the default assigning behavior, so that history is not populated with each followed link
// Location replacer
addEventListener('click', function (event) {
// Create .which property if not exists
// As far as I've tested, it exists in all modern browsers
if (!event.which && event.button) {
if (event.button & 1) {
event.which = 1;
} else if (event.button & 4) {
event.which = 2;
} else if (event.button & 2) {
@yesasha
yesasha / always-hashchange.js
Created February 15, 2018 15:03
Execute onhashchange even when following link with the same href as current location
// Always Hashchange
addEventListener('click', function (event) {
// Create .which property if not exists
// As far as I've tested, it exists in all modern browsers
if (!event.which && event.button) {
if (event.button & 1) {
event.which = 1;
} else if (event.button & 4) {
event.which = 2;
} else if (event.button & 2) {
@yesasha
yesasha / lse.html
Last active January 12, 2018 14:52
LocalStorage Explorer
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--
Copyright (c) 2018 by Aleksandr Yefremov (https://codepen.io/yesasha/pen/ppdyWL)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER I
@yesasha
yesasha / performance.now.polyfill.js
Last active July 8, 2016 10:52 — forked from paulirish/performance.now()-polyfill.js
performance.now() and performance.timing.navigationStart polyfill
// performance.now() and performance.timing.navigationStart polyfill
if (!window.performance) {
window.performance = {};
}
if (!performance.now) {
performance.now = function () {
return Date.now() - this.timing.navigationStart;
}
}
@yesasha
yesasha / eventlistener.js
Last active August 29, 2015 14:17
Attach and then remove event listeners
// Helps to attach and then remove event listeners
// without having to worry about saving the callback and other arguments,
// like the original javascript functions require.
// Also allows passing "this" and any amount of arguments
// to the callback function
//
// Copyright (c) 2015 Aleksandr Efremov
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@yesasha
yesasha / keepratio.js
Last active August 29, 2015 14:17
Keep Aspect Ratio (new oop version)
// Keeps aspect ratio of an element by listening to window resize event
// and setting height = width / aspect ratio
//
// Copyright (c) 2015 Aleksandr Efremov
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@yesasha
yesasha / date.now.js
Last active August 29, 2015 14:16
Date.now() polyfill
// Date.now() polyfill for old browsers (<ie 8)
if (!Date.now) {
Date.now = function () {
return (new Date).getTime();
};
}
@yesasha
yesasha / keepratio.js
Last active August 29, 2015 14:16
Keep Aspect Ratio
// Keeps aspect ratio of an element by listening to window resize event
// and setting height = width / aspect ratio
//
// Copyright (c) 2015 Aleksandr Efremov
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is