Skip to content

Instantly share code, notes, and snippets.

View MrFranke's full-sized avatar

Mikhail MrFranke

  • Russia
View GitHub Profile
@MrFranke
MrFranke / MinWindowSubstringWithoutDuplicate.js
Created April 9, 2021 18:47
MinWindowSubstring problem without duplicate letters O(n)
function MinWindowSubstringWithoutDuplicate([N, K]) {
const matcher = N.split("").reduce((acc, char, idx) => {
if (acc.size === new Set(K).size) {
return acc;
}
for (const Kchar of K) {
if (char === Kchar) {
acc.set(char, idx)
break;
@MrFranke
MrFranke / storybook.config.js
Created September 25, 2019 15:49
Storybook config file for CRA project
import { configure } from '@storybook/react';
import '../src/index.css'; // custom styles for storybook layout
const req = require.context('../src', true, /\.stories\.tsx$/); // all *.stories.tsx files
// import files
function loadStories() {
req.keys().forEach(filename => req(filename));
}
@MrFranke
MrFranke / Dockerfile
Created August 26, 2019 21:33
Dockerfile for SPA
FROM node:lts-alpine as builder
RUN apk add --no-cache bash
WORKDIR /usr/src/app
COPY . .
ENV NODE_ENV=production
RUN npm i -g yarn
RUN \
yarn install --frozen-lockfile --production; \
yarn build
@MrFranke
MrFranke / Dockerfile
Last active August 26, 2019 21:30
Pass env variables to nginx config
FROM nginx:alpine
ENV API_ENDPOINT=http://localhost/api/v1
ENV APP_VERSION=v1.0.0
RUN /bin/sh -c "envsubst '\${API_ENDPOINT} \${APP_VERSION}' < /etc/nginx/conf.d/default.tmpl > /etc/nginx/conf.d/default.conf && cat /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;' "
@MrFranke
MrFranke / passwords.js
Created August 15, 2019 13:24
Yup passwords matchs
Yup.object().shape({
password: Yup.string().required('Password is required'),
passwordConfirm: Yup.mixed().test('match', 'Passwords do not match', function (password) {
return password === this.parent.passwordConfirm
}).required('Password confirm is required')
})
@MrFranke
MrFranke / curry.js
Created March 13, 2019 12:36
Ramda carring with default arguments
const fn = (a, b, c) => [a,b,c];
const fnWithDefault = (a, b = 'default arg', c) => [a,b,c];
R.curry(fn)(1); // fn(b) => fn(c) => [1,b,c]
R.curry(fnWithDefault)(1); // [1, 'default arg', undefined]
@MrFranke
MrFranke / Dockerfile
Created November 28, 2018 14:40
Dockerfile for SPA with proxy to API
FROM node:carbon as builder
WORKDIR /usr/src/app
COPY . .
ENV NODE_ENV production
RUN npm i && npm run build
FROM nginx:1.15.2
WORKDIR /usr/src/app
ENV API_ENDPOINT https://api.com
COPY --from=builder /usr/src/app/build .
exec("cwebp -m 6 -preset icon -mt -af " + source_file + " -o " + file.dest + ".webp");
if( fs.statSync(file.dest)["size"] < fs.statSync(file.dest + ".webp")["size"]){
exec("cwebp -m 6 -preset picture -mt -af " + source_file + " -o " + file.dest + ".webp");
if( fs.statSync(file.dest)["size"] < fs.statSync(file.dest + ".webp")["size"]){
exec("cwebp -m 6 -lossless -mt " + file.dest + " -o " + file.dest + ".webp");
}
}
@MrFranke
MrFranke / ReactCreditCardNumberFilter.js
Created December 16, 2016 15:24
Simple react stateless component for credit card number formatting
function CreditCardNumber (props) => {
let formatter = (event) => {
let val = event.target.value;
let newVal = '';
val.replace(/([0-9]{0,4})/g, function(str){
newVal += str.length === 4 ? str+' ' : str;
});
event.target.value = newVal.replace(/(\s$)/g, '').slice(0,19);
};
return <input type="text" onChange="formatter" placeholder="0000 0000 0000 0000" {...props}>;
@MrFranke
MrFranke / gulp.js
Created March 15, 2016 19:09
Пример конфига для gulp
//
// Requirements
//
var gulp = require('gulp'),
_if = require('gulp-if'),
path = require('path'),
argv = require('yargs').argv,
clean = require('gulp-clean'),
filter = require('gulp-filter'),
rename = require('gulp-rename'),