Skip to content

Instantly share code, notes, and snippets.

View MRezaSafari's full-sized avatar
🎯
Focusing

Reza Safari MRezaSafari

🎯
Focusing
View GitHub Profile
@MRezaSafari
MRezaSafari / server.js
Created June 8, 2024 13:44
simple http server
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const port = 3000;
app.use(bodyParser());
const USER_EMAIL = "[email protected]";
const USER_PASSWORD = "123";
@MRezaSafari
MRezaSafari / enforce-element-jsx-rule.js
Created August 29, 2023 11:04
Enforce allowed child types for custom components
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "Enforce allowed child types for custom components",
category: "Best Practices",
recommended: true,
},
},
create(context) {
@MRezaSafari
MRezaSafari / fetch-interceptor.js
Created August 11, 2023 22:56
fetch interceptor
export const interceptor = async () => {
const { fetch: originalFetch } = window;
window.fetch = async (...args) => {
let [resource, config] = args;
const URLcutOff = "https://myapi.com";
const trailing = resource.slice(URLcutOff.length);
console.log(trailing);
if (trailing.startsWith("/posts")) {
resource = `https://myapi.com`;
}
@MRezaSafari
MRezaSafari / avatar.tsx
Created February 9, 2023 09:45
Nextjs 13 Gravatar Like Generator
import { ImageResponse } from '@vercel/og';
import { NextRequest } from 'next/server';
export const config = {
runtime: 'edge',
};
const padZero = (str: string, len = 2) => {
const zeros = new Array(len).join('0');
return (zeros + str).slice(-len);
function serverObjectsSanitizer<T>(input: T, ignoreList: string[]): T {
if (Array.isArray(input))
return input.map((i) =>
serverObjectsSanitizer(i, ignoreList)
) as unknown as T;
if (typeof input == 'object' && input != null)
return Object.keys(input).reduce((t, c) => {
const before = input[c];
if (ignoreList.indexOf(c) > -1) {
delete t[c];
function isValidIranianNationalCode(input) {
if (!/^\d{10}$/.test(input))
return false;
var check = parseInt(input[9]);
var sum = 0;
var i;
for (i = 0; i < 9; ++i) {
sum += parseInt(input[i]) * (10 - i);
}
@MRezaSafari
MRezaSafari / Microsoft.PowerShell_profile.ps1
Last active November 5, 2021 22:33
my preferred powerline settings using Matheus Castello code
# Install-Module PANSIES -AllowClobber
# Install-Module PowerLine
# lets set the powerline in this profile
Import-Module PowerLine
# aux variables
$ERRORS_COUNT = 0
$ERROR_EMOJI = "😖", "😵", "🥴", "😭", "😱", "😡", "🤬", "🙃", "🤔", "🙄", `
"🥺", "😫", "💀", "💩", "😰"
import axios from 'axios';
import {useCallback, useEffect, useState} from 'react';
const useApi = (url, method, data = {}, options = {}) => {
const [response, setResponse] = useState(null);
const [loading, setLoading] = useState(true);
const fetch = useCallback(async () => {
const req = await axios({url, method, data, ...options});
@MRezaSafari
MRezaSafari / useTable.js
Created March 3, 2020 07:39
useTable hook for ant design 4.x
import axios from 'axios';
import React from 'react';
const useTable = (url, initialParams) => {
const [data, setData] = React.useState([]);
const [loading, setLoading] = React.useState(false);
const [filters, setFilters] = React.useState({});
const [pagination, setPagination] = React.useState({
pageSizeOptions: ['5', '10', '20', '30', '100'],
defaultPageSize: 5,
@MRezaSafari
MRezaSafari / PersianDatePicker.jsx
Last active July 11, 2020 14:20
antd jalali date picker
import React from 'react';
import {DatePicker} from 'antd';
import moment from 'moment-jalaali';
export default function PersianDatePicker() {
var locale = {
"lang": {
locale: 'fa_IR',