Skip to content

Instantly share code, notes, and snippets.

View MRezaSafari's full-sized avatar
🎯
Focusing

Reza Safari MRezaSafari

🎯
Focusing
View GitHub Profile
function readTextFile(file, callback) {
var rawFile = new XMLHttpRequest();
rawFile.overrideMimeType("application/json");
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4 && rawFile.status == "200") {
callback(rawFile.responseText);
}
}
rawFile.send(null);
var mainInfo = null;
$http.get('content.json').success(function(data) {
mainInfo = data;
});
@MRezaSafari
MRezaSafari / CalculateAspectRatio.cs
Last active April 26, 2020 13:45
calculate the aspect ratio of image
public Size CalculateAspectRation(int desiredWidth, int desiredHeight, Image image){
var widthScale = (double)desiredWidth / image.Width;
var heightScale = (double)desiredHeight / image.Height;
var scale = widthScale < heightScale ? widthScale : heightScale;
return new Size
{
Width = (int)(scale * image.Width),
Height = (int)(scale * image.Height)
Error C2143 syntax error: missing ';' before ')'
Error C2143 syntax error: missing ';' before ')'
Error C2143 syntax error: missing ';' before ')'
Error C2143 syntax error: missing ';' before ')'
Error C2143 syntax error: missing ';' before ')'
Error C2143 syntax error: missing ';' before ')'
Error C2061 syntax error: identifier 'DelayedSpellCastEvent'
Error C2061 syntax error: identifier 'DelayedSpellCastEvent'
@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',
@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,
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 / 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 = "😖", "😵", "🥴", "😭", "😱", "😡", "🤬", "🙃", "🤔", "🙄", `
"🥺", "😫", "💀", "💩", "😰"
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);
}
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];