Skip to content

Instantly share code, notes, and snippets.

@alizadeh118
alizadeh118 / EchoTelegramBot.php
Created October 30, 2023 19:31
PHP script for a Telegram bot that forwards incoming messages
<?php
// URL for Telegram API functions
const TELEGRAM_API_URL = "https://api.telegram.org/botYOUR-TOKEN/";
// Get the JSON data from the incoming POST request
$data = json_decode(file_get_contents("php://input"), true);
// Check if the message is set and is not "/start"
if (isset($data["message"]) && (!isset($data["message"]["text"]) || $data["message"]["text"] !== "/start")) {
@alizadeh118
alizadeh118 / timeDecompose.js
Created March 5, 2020 15:06
Decompose second to time units
function timeDecompose(s, toString) {
toString = Boolean(toString) || false;
s = Number(s);
var time = {};
time.year = Math.floor(s / 3.154e7);
time.month = Math.floor(s % 3.154e7 / 2.628e6);
time.day = Math.floor(s % 3.154e7 % 2.628e6 / 86400);
time.hour = Math.floor(s % 3.154e7 % 2.628e6 % 86400 / 3600);
time.minute = Math.floor(s % 3.154e7 % 2.628e6 % 86400 % 3600 / 60);
@alizadeh118
alizadeh118 / qamariToJalali.js
Created December 22, 2019 12:09
تبدیل تاریخ هجری قمری به هجری شمسی / جلالی / خورشیدی
// m: 1-12
// d: 1-31
const q2j = (y, m, d) => {
let result = (((y - 1) + (m - 1) / 12) * 354.3670 + d + 119) / 365.2422
result = result.toString().split('.')
y = +result[0] + 1
d = +(('0.' + result[1]) * 365.2422).toString().split('.')[0]
if (d > 186) {
d = d - 186
m = parseInt(d / 30) + (d % 30 ? 7 : 6)
@alizadeh118
alizadeh118 / jalaliToQamari.js
Created December 22, 2019 11:10
تبدیل تاریخ هجری شمسی / جلالی / خورشیدی به هجری قمری
// m: 1-12
// d: 1-31
const j2q = (y, m, d) => {
d = m > 6 ? (6 * 31) + ((m - 7) * 30) + d : ((m - 1) * 31) + d
let result = ((y - 1) * 365.2422 + d - 119) / 354.3670
result = result.toString().split('.')
y = +result[0] + 1
result = (('0.' + result[1]) * 12).toString().split('.')
m = +result[0] + 1
d = +(('0.' + result[1]) * 29.530).toString().split('.')[0] + 1
@alizadeh118
alizadeh118 / validation.js
Created October 27, 2018 09:58
Check if the string only includes persian characters
function isPersian(str) {
var p = /^[\u0600-\u06FF\s]+$/;
return p.test(str);
}