Skip to content

Instantly share code, notes, and snippets.

View RyadPasha's full-sized avatar
🎯
Focusing

Mohamed Riyad RyadPasha

🎯
Focusing
View GitHub Profile
"""
Oracle Database Connection Wrapper.
@author: Mohamed Riyad <@RyadPasha>
@url: http://ryadpasha.com
@email: me@ryadpasha.com
@license: MIT License
"""
import cx_Oracle
@RyadPasha
RyadPasha / PHPFileDownloader.php
Last active July 11, 2019 15:13
Download Large Files with PHP.
/**
* Download a large distant file to a local destination.
*
* This method is very memory efficient :-)
* The file can be huge, PHP doesn't load it in memory.
*
* /!\ Warning, the return value is always true, you must use === to test the response type too.
*
* @author Mohamed Riyad <@RyadPasha>
* @url: http://ryadpasha.com
@RyadPasha
RyadPasha / mime2ext.php
Created October 26, 2018 11:09
Converting MIME type to file Extension in PHP.
function mime2ext($mime) {
$mime_map = [
'video/3gpp2' => '3g2',
'video/3gp' => '3gp',
'video/3gpp' => '3gp',
'application/x-compressed' => '7zip',
'audio/x-acc' => 'aac',
'audio/ac3' => 'ac3',
'application/postscript' => 'ai',
'audio/x-aiff' => 'aif',
@RyadPasha
RyadPasha / ConnectJDBC3.java
Created November 17, 2018 16:02
Connecting to database in Java with JDBC.
/**
* Connecting to database in Java with JDBC 3.0 and backward.
*
* @author: Mohamed Riyad <@RyadPasha>
* @url: http://ryadpasha.com
* @email: me@ryadpasha.com
* @license: MIT License
*/
import java.sql.Connection;
import java.sql.DriverManager;
@RyadPasha
RyadPasha / fileUploader.php
Last active July 20, 2019 10:53
Full Secure File Upload Function in PHP.
<?php
/**
* @project: PHP File Uploader
*
* @purpose: This fuction provides a full secure file upload in PHP.
* @version: 1.0
*
*
* @author: Mohamed Riyad
* @created on: 9 Jun, 2019
@RyadPasha
RyadPasha / arabic-nums-to-english-nums.js
Last active July 22, 2024 12:32
Convert Arabic/Persian numbers to English numbers in JavaScript
function conv2EnNum(str){
return parseFloat(str
.replace(/[٠١٢٣٤٥٦٧٨٩]/g, function (d) { return d.charCodeAt(0) - 1632; }) // Convert Arabic numbers
.replace(/[۰۱۲۳۴۵۶۷۸۹]/g, function (d) { return d.charCodeAt(0) - 1776; }) // Convert Persian numbers
)*1;
}
// Examples:
alert(conv2EnNum('٠١٢٣٤٥٦٧٨٩')); // -> 01213456789
alert(conv2EnNum('١٣.٥')); // -> 13.5
@RyadPasha
RyadPasha / arabic-nums-to-english-nums.php
Last active July 20, 2019 10:53
Convert Arabic/Persian numbers to English numbers in PHP
<?php
function conv2EnNum($str) {
$str = str_replace(['٠','١','٢','٣','٤','٥','٦','٧','٨','٩'], range(0, 9), $str); // Convert Arabic numbers
$str = str_replace(['۰','۱','۲','۳','۴','۵','۶','۷','۸','۹'], range(0, 9), $str); // Convert Persian numbers
return preg_replace('/[^0-9\.,]/', '', $str);
}
echo conv2EnNum('٠١٢٣٤٥٦٧٨٩'); // -> 01213456789
echo conv2EnNum('١٣.٥'); // -> 13.5
/**
* sends a request to the specified url from a form. this will change the window location.
* @param {string} path the path to send the post request to
* @param {object} params the paramiters to add to the url
* @param {string} [method=post] the method to use on the form
*/
function post(path, params, method='POST') {
// The rest of this code assumes you are not using a library.
/**
* sends a request to the specified url from a form. this will change the window location.
* @param {string} path the path to send the post request to
* @param {object} params the paramiters to add to the url
* @param {string} [method=post] the method to use on the form
*/
function post(path, params, method='POST') {
var form = $('<form></form>');
@RyadPasha
RyadPasha / ds_store_removal
Created October 28, 2021 06:19
How to remove .DS_Store file from GitHub that macOS creates
# remove .DS_Store file from GitHub that macOS creates
# find and remove .DS_Store
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
# create .gitignore file, if needed
touch .gitignore
echo .DS_Store > .gitignore
# push changes to GitHub