Skip to content

Instantly share code, notes, and snippets.

View milantarami's full-sized avatar
💭
building apps.

Milan Tarami milantarami

💭
building apps.
View GitHub Profile
@milantarami
milantarami / schema.js
Created November 18, 2022 12:07 — forked from JoaoCnh/schema.js
Yup conditional validation
Yup.object().shape({
email: Yup.string().email('Invalid email address').required('Email is required!'),
username: Yup.string().required('This man needs a username').when('email', (email, schema) => {
if (email === 'foobar@example.com') { return schema.min(10); }
return schema;
}),
});
// https://blog.bitsrc.io/setting-up-axios-interceptors-for-all-http-calls-in-an-application-71bc2c636e4e
import axios, { AxiosError, AxiosRequestConfig } from "axios";
let MAX_RETRIES = 5;
let ONE_MINUTE = 60 * 1000;
interface AxiosConfig extends AxiosRequestConfig {
retryCount?: number;
@milantarami
milantarami / laraws_nginx.md
Created September 18, 2022 18:38 — forked from ErxrilOwl/laraws_nginx.md
Deploy Laravel on AWS EC2 Ubuntu (nginx)
@milantarami
milantarami / avatar.js
Created September 1, 2022 04:58 — forked from gauravsoti1/avatar.js
Styling Material Ui's Avatar for a project to have different size which adjusts according to screen sizes. Also, gutter spacing on left and right. Libraries: React, material ui, styled-components
import React from "react";
import styled, { css } from "styled-components";
import { Avatar } from "@material-ui/core";
// -------------------------- Defining all the css sizes ------------------------
export const SmallestSizeCSS = css`
width: 30px;
height: 30px;
${props => props.theme.breakpoints.up("lg")} {
@milantarami
milantarami / .php-cs-fixer.dist.php
Created June 18, 2022 05:16 — forked from tabacitu/.php-cs-fixer.dist.php
PHP-CS-Fixer Configuration File for the Laravel Code Style
<?php
/**
-----------------------------------------------------
Enforce the Laravel Code Style using PHP CS Fixer 3.x
-----------------------------------------------------
Credits go to Laravel Shift & Andreas Elia.
https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@milantarami
milantarami / localStorageHelpers.js
Created February 24, 2021 08:51 — forked from scrubmx/localStorage.js
Helper functions for localStorage
if( typeof(Storage) === 'undefined' ) {
// Sorry! No Web Storage support...
}
/**
* Check if key exists in local storage
* @param string key
* @return boolean
*/
function localStorageHas (key) {
@milantarami
milantarami / axios.refresh_token.1.js
Created February 24, 2021 06:43 — forked from Godofbrowser/axios.refresh_token.1.js
Axios interceptor for refresh token when you have multiple parallel requests. Demo implementation: https://github.com/Godofbrowser/axios-refresh-multiple-request
// for multiple requests
let isRefreshing = false;
let failedQueue = [];
const processQueue = (error, token = null) => {
failedQueue.forEach(prom => {
if (error) {
prom.reject(error);
} else {
prom.resolve(token);
@milantarami
milantarami / url-to-base64.js
Last active January 9, 2021 17:00
Convert local URL(URL) to Base64 in javascript
var xhr = new XMLHttpRequest();
xhr.open("GET", "/path/to/local/image/file", true);
xhr.responseType = "blob";
xhr.onload = function (e) {
console.log(this.response);
var reader = new FileReader();
reader.onload = function(event) {
var res = event.target.result;
console.log(res)
}
@milantarami
milantarami / yup-with-final-form.js
Last active November 3, 2022 09:33 — forked from manzoorwanijk/yup-with-final-form.js
How to properly use yup validation schema with (React) Final Form?
import * as yup from 'yup';
import { setIn } from 'final-form';
const validationSchema = yup.object({
email: yup.string().email(),
shipping: yup.object({
name: yup.string(),
phone: yup.object({
code: yup.string().matches(/^\+\d+$/i),
number: yup.number().max(10),