Skip to content

Instantly share code, notes, and snippets.

View alash3al's full-sized avatar

Mohammed Al Ashaal alash3al

View GitHub Profile
@alash3al
alash3al / has_ar.js
Last active March 8, 2017 14:08
has_ar(), check if string contains arabic char(s)
/**
* Check if string has an arabic char
* @author Mohammed Alashaal <fb.com/alash3al>
* @param element str
* @return bool
*/
function has_ar(str)
{
var x = /[\u0600-\u06FF]+/;
return x.test(str);
@alash3al
alash3al / array2val.php
Last active April 27, 2017 09:07
Convert any array to string ( single value )
<?php
/**
* Convert array/nested-array to single value
* @param mixed $arg
* @author Mohammed Al Ashaal
* @license MIT License
* @return string
*/
function array2val($arg)
@alash3al
alash3al / session_init.php
Last active August 29, 2015 14:07
better than session_start()
<?php
/**
* Session initializer
* this function will check whether the session already started or not
* if it started then it will not start it again
* @author Mohammed Al Ashaal
*/
function session_init()
{
@alash3al
alash3al / extract_links.php
Last active August 29, 2015 14:07
Extract links from source page or subject
@alash3al
alash3al / form_process_example.php
Last active August 29, 2015 14:08
example > form processing
<?php
// here we handle all form errors
$GLOBALS['formE'] = array();
// say that some hit the submit button
// and the form method is POST
if ( isset( $_POST['submit'] ) )
{
// create a shortcut to $_POST var
@alash3al
alash3al / wget.php
Last active February 23, 2023 18:13
wget() in PHP, no more curl, just one line call
<?php
/**
* wget just like linux wget command
*
* @author Mohammed Al Ashaal <is.gd/alash3al>
* @version 1.0.0
* @license MIT License
*
* @param string $url example 'http://site.com/xxx?k=v'
* @param string $method example 'GET'
@alash3al
alash3al / uri.js
Last active August 29, 2015 14:15 — forked from jlong/uri.js
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@alash3al
alash3al / wget.php
Last active August 29, 2015 14:15
wget(), version 2, a PHP curl alternative
<?php
/**
* wget, the curl alternative
*
* @author Mohammed Al Ashaal <is.gd/alash3al>, <fb.com/alash3al>
* @version 2.0.0
* @license MIT License
*
* @param string $url example 'http://site.com/xxx?k=v'
@alash3al
alash3al / file2base64.js
Last active August 29, 2015 14:15
javascript file2base46, return an uploaded file as base64 encoded
/**
* File2Base64
*
* @param string file the path of the files
* @param string mim_type the type of the file e.g: 'image/png'
* @param callable callback the callback that handle the base64encoded string
*
* @author Mohammed Al Ashaal
* @version 1.0.0
*/
@alash3al
alash3al / parse_url.js
Last active August 29, 2015 14:15
Parse a url and return its components, php parse_url() for javascript
/**
* Parse a url and return its components
*
* @param string $url
* @return Object
*
* @author Mohammed Al Ashaal <is.gd/alash3al>, inspired by PHP
* @version 1.0.0
*/
function parse_url($url)