Skip to content

Instantly share code, notes, and snippets.

@guz-anton
guz-anton / index.md
Last active February 15, 2024 11:15
smaple

type AA = Partial<Record<'next' | 'back' | 'hideOthers', string>> type BB = Record<'next' | 'back' | 'hideOthers', string>

const aa: AA = { next: 'adads' }

type FN = (a: Record<string, string>) => void

const fx: FN = (bb) => console.log(bb)

@guz-anton
guz-anton / Readme.md
Last active December 10, 2023 15:45
Add text to image in batch
@guz-anton
guz-anton / CamelCase-to-Snake-Case.ts
Last active June 26, 2023 13:58
Types collection
type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}`
? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
: Lowercase<S>
type KeysToCamelCase<T> = {
[K in keyof T as CamelCase<string & K>]: T[K]
}
type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ?
const fx = (fn, start, ...xn) => {
const FF = class {
constructor (...rn) {
const ww = (...wn) => { return new FF(...rn, ...wn)}
ww.valueOf = () => this.valueOf()
ww.toString = () => this.toString()
this.items = rn
const toDigit = (...values) => {
const isValue = x => x != null && !isNaN(x) && isFinite(x);
return +values.find(isValue) || 0;
}
const toDigit = (...values) => +values.find(x => x != null && !isNaN(x) && isFinite(x)) || 0;
// const freezeFn = fn => (c => x => c[x] != null ? c[x] : c[x] = fn(x))({})
const freezeFn = fn => (c => {return function cached(x){if (c[x] != null) {c[x] = fn(x, cached)}; return c[x]}})({})
const fibFn = (x, fn) => fn(x - 1) + fn(x - 2)
const fibArgs = (x, fn) => +!parseInt(x) || +(x == 0) || +(x == 1) || fibFn(parseInt(x), fn)
const fibonacci = freezeFn(fibArgs)
const facFn = (x, fn) => x * fn(x - 1)
const facArgs = (x, fn) => +!parseInt(x) || +(x == 0) || +(x == 1) || facFn(parseInt(x), fn)
const factorial = freezeFn(facArgs)
const fnBy = fn => x => y => !fn || !Math[fn] || !x || !y ? 0 : y < 0 ? 0 : y > x ? x : Math[fn] (10 * y / x) * x / 10;
// const ceilBy = max => y => !max || !y ? 0 : y < 0 ? 0 : y > max ? max : Math.ceil (10 * y / max) * max / 10;
const ceilBy = fnBy('ceil');
const roundBy = fnBy('round');
const floorBy = fnBy('floor');
const fiveStarRating = ceilBy(5);
const oneHundredPoints = roundBy(100);
// Example
@guz-anton
guz-anton / loader.html
Created April 23, 2019 15:38 — forked from bluesmoon/loader.html
A CSP compliant non-blocking script loader
<script id="nb-loader-script">
(function(url) {
// document.currentScript works on most browsers, but not all
var where = document.currentScript || document.getElementById("nb-loader-script"),
promoted = false,
LOADER_TIMEOUT = 3000,
IDPREFIX = "__nb-script";
// function to promote a preload link node to an async script node
@guz-anton
guz-anton / 000-blank
Last active January 21, 2019 17:12
Install Magento 2
server {
listen 80;
server_name {};
set $MAGE_MODE developer;
set $MAGE_RUN_TYPE website;
set $MAGE_RUN_CODE {};
set $MAGE_ROOT /var/www/{};
@guz-anton
guz-anton / example.phtml
Last active March 23, 2021 09:53
Instagram feed. Magento 2 + instafeed.js snippet.
<div data-role="instafeed" class="instafeed-container"></div>
<script type="text/x-magento-init">
{
"[data-role=instafeed]": {
"instafeed-loader": {
"userId": "{{userId}}", // https://stackoverflow.com/q/11796349
"accessToken": "{{accessToken}}" // https://www.instagram.com/developer/authentication/
}
}
}