Skip to content

Instantly share code, notes, and snippets.

Avatar

Mikhail Larchanka larchanka

View GitHub Profile
View randomIntFromInterval.js
function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min);
}
@larchanka
larchanka / getFromLocalStorage.js
Created Jun 18, 2019
Function gets data from localstorage
View getFromLocalStorage.js
export default (itemName, defaultValue, postFn = (str) => str) => {
const item = localStorage.getItem(itemName);
if (item) {
return postFn(item);
}
return defaultValue;
};
@larchanka
larchanka / dirToArray.php
Last active May 6, 2019
Function to scan directory and return array of files
View dirToArray.php
<?php
function dirToArray($dir) {
$ignoredPath = array(
".",
"..",
".htaccess"
);
$result = array();
@larchanka
larchanka / creditCardTypeDetector.js
Last active Sep 15, 2017
Detect type of the payment card
View creditCardTypeDetector.js
export default (cardNumber) => {
// MasterCard
if (/^5[1-5]/.test(cardNumber)) {
return 'mastercard';
}
// Visa
if (/^4/.test(cardNumber)) {
return 'visa';
}
@larchanka
larchanka / contentHashGenerator.js
Created Jun 13, 2017
contentHashGenerator generates a short number hash from the string
View contentHashGenerator.js
const contentHashGenerator = (str = '') => {
let hash = 0;
let i;
let chr;
if (str.length === 0) return hash;
for (i = 0; i < str.length; i++) {
chr = str.charCodeAt(i);
// eslint-disable-next-line
hash = ((hash << 5) - hash) + chr;
// eslint-disable-next-line
View test.js
[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+
@larchanka
larchanka / README.md
Created Sep 26, 2016 — forked from addyosmani/README.md
108 byte CSS Layout Debugger
View README.md

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@larchanka
larchanka / getQueryParam.js
Last active Sep 1, 2016
Get query parameter from the url
View getQueryParam.js
var getQueryParam = function getQueryParam (param) {
var queries = window.location.search, regex, resRegex, results, response;
param = encodeURIComponent(param);
regex = new RegExp('[\\?&]' + param + '=([^&#]*)', 'g');
resRegex = new RegExp('(.*)=([^&#]*)');
results = queries.match(regex);
if (!results) {
return '';
}
@larchanka
larchanka / change-favicon.js
Created Sep 28, 2015 — forked from mathiasbynens/change-favicon.js
Dynamically changing favicons with JavaScript
View change-favicon.js
/*!
* Dynamically changing favicons with JavaScript
* Works in all A-grade browsers except Safari and Internet Explorer
* Demo: http://mathiasbynens.be/demo/dynamic-favicons
*/
// HTML5™, baby! http://mathiasbynens.be/notes/document-head
document.head || (document.head = document.getElementsByTagName('head')[0]);
function changeFavicon(src) {
@larchanka
larchanka / generate-classes.js
Last active Aug 31, 2015
Function generateClasses generates classes string from a passed object
View generate-classes.js
/* generateClasses generates classes string from a passed object, i.e.
generateClasses({
'class1': true,
'class2': false,
'class3': true
});
// will return string 'class1 class3'
*/
(function() {