Skip to content

Instantly share code, notes, and snippets.

@faustienf
faustienf / declination.js
Created December 19, 2017 13:24
Склонятор
export function declination(num, titles) {
const cases = [2, 0, 1, 1, 1, 2];
return titles[(num % 100 > 4 && num % 100 < 20)
? 2
: cases[(num % 10 < 5) ? num % 10 : 5]
];
}
declination(1, ['яблоко', 'яблока', 'яблок']); // яблоко
declination(2, ['яблоко', 'яблока', 'яблок']); // яблока
@faustienf
faustienf / getCalendarMatrix.js
Last active December 29, 2017 22:18
Generate matrix for calendar
/**
* Dependencies
* moment
* ramda
*/
/**
*
* @param {string} date
* @param {Object} options
@faustienf
faustienf / sort.js
Created February 10, 2018 10:55
sort anime on http://animeru.tv
$('#mse2_results .mse2-row').sort(function(a,b) {
function getViews(el) {
return Number($(el).find('table tr:last td').text().trim().match(/\d+$/ig)[0])
}
return getViews(b) - getViews(a);
}).appendTo('#mse2_results');
@faustienf
faustienf / media.scss
Created April 11, 2018 10:15
Simple breakpoint mixin
// breakpoints from bootstrap 4
$grid-breakpoints: (
xs: 0,
sm: 576px,
md: 768px,
lg: 992px,
xl: 1200px
) !default;
@mixin breakpoint($point) {
tplink archer t4u driver
https://askubuntu.com/questions/802205/how-to-install-tp-link-archer-t4u-driver
interface CalendarDay {
label: number;
timestamp: number;
isCurrentMonth: boolean;
}
type CalendarWeek = CalendarDay[];
type Calendar = CalendarWeek[];
/**
* @example
const obj = {
a: {
b: {
c: [1, 2, 3]
},
d: '',
f: true,
},
g: {
h: 2,
// copy from https://github.com/microsoft/TypeScript/issues/13298#issuecomment-513813788
type Overwrite<T, S extends any> = {[P in keyof T]: S[P]};
type TupleUnshift<T extends any[], X> = T extends any ? ((x: X, ...t: T) => void) extends (...t: infer R) => void ? R : never : never;
type TuplePush<T extends any[], X> = T extends any
? Overwrite<TupleUnshift<T, any>, T & {[x: string]: X}>
: never;
import {
createRef,
useCallback,
useRef,
RefObject,
} from 'react';
type RefsMap<T> = Partial<Record<string, RefObject<T>>>;
type LinkRef<T> = (key: string) => RefObject<T>;
let scrollWidth: null | number = null;
export const getScrollWidth = (): number => {
if (scrollWidth !== null) {
return scrollWidth;
}
const el = document.createElement('div');
el.style.position = 'fixed';
el.style.zIndex = '-1';