Skip to content

Instantly share code, notes, and snippets.

View larchanka's full-sized avatar
🥷
On duty

Mikhail Larchanka larchanka

🥷
On duty
View GitHub Profile
/**
* Calculates the ideal ramp length and height for a car jump based on the preference for a higher or longer jump.
*
* @param {'higher' | 'longer'} preference - The preference for the jump, either "higher" or "longer".
* @returns {{length: string, height: string}} - An object containing the scaled length and height of the ramp in meters.
* @throws {Error} - Throws an error if the preference is not "higher" or "longer".
*/
function calculateRcRamp(preference) {
const g = 9.81;
const scale = 1;
@larchanka
larchanka / randomIntFromInterval.js
Last active August 23, 2020 10:38
Random Interval
function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min);
}
@larchanka
larchanka / getFromLocalStorage.js
Created June 18, 2019 14:29
Function gets data from localstorage
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 11:24
Function to scan directory and return array of files
<?php
function dirToArray($dir) {
$ignoredPath = array(
".",
"..",
".htaccess"
);
$result = array();
@larchanka
larchanka / creditCardTypeDetector.js
Last active September 15, 2017 08:26
Detect type of the payment card
export default (cardNumber) => {
// MasterCard
if (/^5[1-5]/.test(cardNumber)) {
return 'mastercard';
}
// Visa
if (/^4/.test(cardNumber)) {
return 'visa';
}
@larchanka
larchanka / contentHashGenerator.js
Created June 13, 2017 13:03
contentHashGenerator generates a short number hash from the string
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
@larchanka
larchanka / test.js
Created October 14, 2016 07:27
Test
[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+
@larchanka
larchanka / README.md
Created September 26, 2016 18:25 — forked from addyosmani/README.md
108 byte CSS Layout Debugger

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 September 1, 2016 12:43
Get query parameter from the url
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 September 28, 2015 11:34 — forked from mathiasbynens/change-favicon.js
Dynamically changing favicons with JavaScript
/*!
* 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) {