This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import crypto from 'crypto'; | |
export function randomHex(length) { | |
return crypto.randomBytes(length / 2).toString('hex'); | |
} | |
export function createHash(url, secretKey) { | |
const randomHexStr = randomHex(64); | |
const timestamp = Date.now(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git config --global alias.lg 'log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit' | |
git config --global alias.p push | |
git config --global alias.st 'status -sb' | |
git config --global alias.last 'log -2 HEAD --stat' | |
git config --global alias.se '!git rev-list --all | xargs git grep -F' | |
git config --global alias.ch 'checkout' | |
git config --global alias.b 'symbolic-ref --short HEAD' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [retval] = isPositiveDefinit(A) | |
FLAG = 1; | |
IS_SYMMETRIC = isequal(A,A.'); | |
if (IS_SYMMETRIC == 0) | |
retval = 0; | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const algo = arr => { | |
let sum_half = 0 | |
let i = 0 | |
let p = 0 | |
while(i < arr.length) | |
sum_half += arr[i++] | |
sum_half /= 2 | |
let left_side_sum = 0 | |
let last_diff = 0 | |
for(i in arr) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ImprovedEuler(F) | |
% Improved Euler Method | |
% blog.mrfarhad.ir | |
% author: Farhad Mehryari | |
a = 0; | |
b = 200; | |
% محدوده مورد نظر | |
n = 100; % ـعداد دفعات تکرار حلقه |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% matlab eular method | |
% Author: Farhad Mehryari | |
% blog.mrfarhad.ir | |
function [y t] = euler(f,a,b,ya,n) | |
h = (b - a) / n; | |
y(1,:) = ya; | |
t(1) = a; | |
for i = 1 : n | |
y(i+1,:) = y(i,:) + h * f(t(i),y(i,:)); | |
t(i+1) = t(i) + h; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% play piano with matlab | |
% "soltan qalba" ha song | |
% author: Farhad Mehryari | |
notecreate = @(frq,dur,v) sin(2*pi* [1:dur]/v * (440*2.^((frq-1)/12))); | |
notename = {'A' 'A#' 'B' 'C' 'C#' 'D' 'D#' 'E' 'F' 'F#' 'G' 'G#'}; | |
song = {'A' 'B' 'C' 'E' 'F' 'E' 'F' 'E' 'F' 'E' 'D' 'E' 'D' 'E' 'D' 'E' 'D' 'C' 'D' 'C' 'D' 'C' 'B' 'A' 'A' 'B'}; | |
durations = [1 1 1 3 1 2 1 2 1 1 1 1 2 1 2 1 1 1 1 2 1 2 1 2 1 0.5 1] | |
for k1 = 1:length(song) | |
if (string(song(k1)) == '0') | |
songidx(k1) = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function root = newton(f,df) | |
% Newton-Raphson method | |
% Author: Farhad Mehryari | |
i = 1; | |
p0 = 0.5*pi; %شرایط اولیه | |
N = 100; %حداکثر تعداد تکرار | |
error = 0.0001; %خطا | |
while i <= N | |
p = p0 - (f(p0)/df(p0)); %روش نیوتن | |
if (abs(p - p0)/abs(p)) < error % شرط خروج از حلقه |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Romberg Integration in Numerical Analysis | |
% Author: Farhad Mehryari | |
% Web: blog.mrfarhad.ir | |
function r = romberg(f,a,b,n) | |
h = (b - a) ./ (2.^(0:n-1)); | |
r(1,1) = (b - a) * (f(a) + f(b)) / 2; | |
for j = 2:n | |
subtotal = 0; | |
for i = 1:2^(j-2) | |
subtotal = subtotal + f(a + (2 * i - 1) * h(j)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% LU Matrix decomposition algorithm | |
% Author: Farhad Mehryari | |
% Web: blog.mrfarhad.ir | |
function [ L, U ] = LU(A) | |
% A شرط بررسی مربعی بودن ماتریس | |
sz = size(A); | |
if sz(1)~=sz(2) | |
fprintf('A is not square !\n'); | |
clear x; | |
return; |
NewerOlder