Skip to content

Instantly share code, notes, and snippets.

View farhadhp's full-sized avatar
💻
coding

Farhad Hassanpour farhadhp

💻
coding
View GitHub Profile
@farhadhp
farhadhp / wget-dl.sh
Created October 17, 2022 09:55
wget dl
#!/usr/bin/env bash
file_url="FILE_URL"
file_name="fileName"
for i in 1 2 3 4; do
wget —limit-rate=5m -O $file_name $file_url
sudo rm -rfv $file_name
done
@farhadhp
farhadhp / removeUtf8Bom.php
Created March 19, 2022 09:41
Remove UTF8 Bom in PHP
// Remove UTF8 Bom
function removeUtf8Bom($text)
{
$bom = pack('H*', 'EFBBBF');
$text = preg_replace("/^$bom/", '', $text);
return $text;
}
@farhadhp
farhadhp / numberFormat.js
Created April 28, 2021 22:19
Javascript number format
function formatNumber(num) {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
}
console.log(formatNumber(1234)) // 1,234
console.log(formatNumber(123456)) // 123,456
console.log(formatNumber(123456789)) // 123,456,789
((colors, query) =>
Array.from(document.querySelectorAll(query)).forEach(cell =>
cell.setAttribute(
"fill",
`#${colors[Math.floor(Math.random() * colors.length)]}`
)
))(["acd5f2", "7fa8c9", "527ba0", "254e77"], ".user-contrib-cell");
@farhadhp
farhadhp / convert_numbers_to_persian.php
Last active August 29, 2022 12:50
تبدیل اعداد فارسی به اعداد لاتین و بالعکس در php
<?php
/**
* Author: Farhad Hassan Pour
* Author Url: https://farhadhp.ir
* Description: Convert Latin numbers to persian number
*/
function convert_numbers_to_persian($srting,$toPersian=true)
{
$en_num = array('0','1','2','3','4','5','6','7','8','9');
@farhadhp
farhadhp / floor.php
Created April 3, 2019 13:58
floor in php
<?php
/**
* Author: Farhad Hassan pour
* Author url: https://farhadhp.ir
* Description: floor — Round fractions down
*/
// example
echo floor(4.9); // Output: 4
echo floor(8.2); // Output: 8
@farhadhp
farhadhp / get_current_url.php
Last active January 24, 2018 15:36
Get current url in wordpress
<?php
/*
* Get current url in wordpress
* @return url
*/
function get_current_url(){
global $wp;
return add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
}
@farhadhp
farhadhp / has_duplicated_array.php
Created April 19, 2017 16:43
has_duplicated_array : An simple function to check if given array contains duplicated values
<?php
/*
* Author : Farhad Hassan Pour (https://farhadhp.github.io/)
*/
function has_duplicated_array($arr) {
$count_value = array_count_values($arr);
rsort($count_value);
return $count_value[0] > 1;
}