Skip to content

Instantly share code, notes, and snippets.

View mrfarhadir's full-sized avatar
🎯
Focusing

Farhad Mehryari mrfarhadir

🎯
Focusing
  • Apple
  • Sweden
  • 15:13 (UTC -12:00)
View GitHub Profile
@mrfarhadir
mrfarhadir / hash.js
Last active November 24, 2024 00:40
Proxy middleware for Nuxt framework. (usage in the comment)
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();
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'
function [retval] = isPositiveDefinit(A)
FLAG = 1;
IS_SYMMETRIC = isequal(A,A.');
if (IS_SYMMETRIC == 0)
retval = 0;
else
@mrfarhadir
mrfarhadir / algo.js
Last active January 14, 2020 19:16
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) {
function ImprovedEuler(F)
% Improved Euler Method
% blog.mrfarhad.ir
% author: Farhad Mehryari
a = 0;
b = 200;
% محدوده مورد نظر
n = 100; % ـعداد دفعات تکرار حلقه
@mrfarhadir
mrfarhadir / Euler.m
Created June 12, 2019 08:21
Euler method
% 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;
@mrfarhadir
mrfarhadir / piano.m
Created March 4, 2019 21:06
Soltan Qalbha song with matlab
% 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
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 % شرط خروج از حلقه
@mrfarhadir
mrfarhadir / romberg.m
Created January 19, 2019 14:16
Romberg Integration in Numerical Analysis
% 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));
% 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;