Skip to content

Instantly share code, notes, and snippets.

/**
* Remove diacritics (tashkeel) from Arabic text
*
* @author @AmrMekkawy
* @param string $text arabic text with diacritics (tashkeel)
* @return string arabic text without the diacritics (tashkeel)
*/
function remove_tashkeel($text = '')
{
$text_without_tashkeel = str_replace(['َ', 'ً', 'ُ', 'ٌ', 'ِ', 'ٍ', 'ْ', 'ّ'], '', $text);
/**
* Remove "kasheda" character from Arabic text
*
* @author @AmrMekkawy
* @param string $text arabic text with (kasheda) character
* @return string arabic text without the (kasheda) character
*/
function remove_kasheda($text = '')
{
$text_without_kasheda = str_replace('ـ', '', $text);
@AmrMekkawy
AmrMekkawy / sum-all-passed-arguments.js
Created August 26, 2016 09:12
A Javascript function that sums all passed arguments
x = sumAll(1, 123, 500, 115, 44, 88);
function sumAll() {
var i, sum = 0;
for (i = 0; i < arguments.length; i++) {
sum += arguments[i];
}
return sum;
}
@AmrMekkawy
AmrMekkawy / change-text-direction-of-input-or-textbox-automatically.js
Created March 2, 2017 22:49
Change the direction of the text dynamically based on the user input. Source: http://stackoverflow.com/a/7770258/458204
$('input, textarea').keyup(function(){
$this = $(this);
if($this.val().length == 1)
{
var x = new RegExp("[\x00-\x80]+"); // is ascii
//alert(x.test($this.val()));
var isAscii = x.test($this.val());
@AmrMekkawy
AmrMekkawy / prevent-form-submission-when-choosing-a-place-from-google-places-autocomplete-searchbox.js
Last active March 5, 2017 19:31
Prevent form submission when choosing a place from google places autocomplete searchbox
// See Demo: https://jsbin.com/wipaze
placesSearchbox = $("#google-places-searchbox");
placesSearchbox.on("focus blur", function() {
$(this).closest("form").toggleClass('prevent_submit');
});
placesSearchbox.closest("form").on("submit", function(e) {
// more about "closest()": https://goo.gl/BzLwZm
@AmrMekkawy
AmrMekkawy / Oauth2.md
Created April 13, 2017 16:27 — forked from mziwisky/Oauth2.md
Oauth2 Explanation

OAUTH2

The Problem

I’m a web app that wants to allow other web apps access to my users’ information, but I want to ensure that the user says it’s ok.

The Solution

I can’t trust the other web apps, so I must interact with my users directly. I’ll let them know that the other app is trying to get their info, and ask whether they want to grant that permission. Oauth defines a way to initiate that permission verification from the other app’s site so that the user experience is smooth. If the user grants permission, I issue an AuthToken to the other app which it can use to make requests for that user's info.

Note on encryption

Oauth2 has nothing to do with encryption -- it relies upon SSL to keep things (like the client app’s shared_secret) secure.

@AmrMekkawy
AmrMekkawy / API.md
Created June 19, 2017 16:03 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@AmrMekkawy
AmrMekkawy / my-custom-settings-for-visual-studio-code.json
Last active July 2, 2017 14:58
My custom settings for the open source "Visual Studio Code" editor https://code.visualstudio.com
{
"workbench.iconTheme": "material-icon-theme",
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"window.zoomLevel": 0,
"editor.fontSize": 15,
"editor.renderLineHighlight": "all",
"workbench.colorTheme": "One Monokai",
"workbench.activityBar.visible": true,
"window.menuBarVisibility": "toggle",
"editor.minimap.enabled": false
@AmrMekkawy
AmrMekkawy / gulpfile.js
Last active July 10, 2017 23:40
Example of gulpfile.js
// define locations of the used directories
var dirs = {
src: {
scss: 'src/scss',
js: 'src/js',
img: 'src/img'
},
dist: {
css: 'dist/css',
js: 'dist/js',
@AmrMekkawy
AmrMekkawy / bootstrap-media-queries.css
Last active July 17, 2019 11:07
Bootstrap standard media queries
/* Extra Small: Portrait phones and smaller */
@media (max-width: 480px) {
}
/* Extra Small: Landscape phones and portrait tablets */
@media (max-width: 767px) {
}