Skip to content

Instantly share code, notes, and snippets.

View mhmoudsami's full-sized avatar

Sami El mhmoudsami

  • germany
  • 09:46 (UTC -12:00)
View GitHub Profile
@mhmoudsami
mhmoudsami / background.js
Created October 21, 2017 14:21 — forked from danharper/background.js
Bare minimum Chrome extension to inject a JS file into the given page when you click on the browser action icon. The script then inserts a new div into the DOM.
// this is the background code...
// listen for our browerAction to be clicked
chrome.browserAction.onClicked.addListener(function (tab) {
// for the current tab, inject the "inject.js" file & execute it
chrome.tabs.executeScript(tab.ib, {
file: 'inject.js'
});
});
/**
* php string tempate
* @param $string string
* @param replacement_array array of key value pair to replace
* @example render_string_template("my name is {name}" , ['name' => 'mahmoud sami'])
*/
if (! function_exists('render_string_template')) :
function render_string_template($string , $replacement_array)
{
$string_processed = preg_replace_callback(
@mhmoudsami
mhmoudsami / gist:e1e4ec0aef23c22c09535c2e6177bc81
Created February 28, 2017 14:41 — forked from jonathanmoore/gist:2640302
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

# install
$ sudo npm install -g cordova ionic
# create new project
ionic start todo blank
ionic start todo tabs
ionic start todo sidemenu
# add new platform
ionic platform add ios
@mhmoudsami
mhmoudsami / hide div in single post if post belongs to category ID
Last active October 22, 2016 21:53
hide div in single post if post belongs to category ID
add_filter('body_class', 'hide_div_if_post_belongs_to_category');
function hide_div_if_post_belongs_to_category($classes) {
if ( is_singular('post') )
{
if (in_category($category_id , get_the_ID()))
{
$classes[] = 'hide-this-div';
}
}
return $classes;
@mhmoudsami
mhmoudsami / redirect-to-login-if-not-logged-in.php
Created October 10, 2016 20:27
Redirect to wp-login.php if user is not logged in
<?php
/**
* @package Redirect to login if not logged in
* @version 1.5
*/
/*
Plugin Name: Redirect to login if not logged in
Plugin URI: http://wordpress.org/plugins/redirect-to-login-if-not-logged-in/
Description: Redirects a user to the login page if the user is not logged in. After login the user gets redirected to the original entry page.
Author: Daan Kortenbach
@mhmoudsami
mhmoudsami / levenshtein.js
Created August 25, 2016 17:43 — forked from andrei-m/levenshtein.js
Levenshtein distance between two given strings implemented in JavaScript and usable as a Node.js module
/*
Copyright (c) 2011 Andrei Mackenzie
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
@mhmoudsami
mhmoudsami / fix wordpress directory and files permision
Created August 18, 2016 17:17
fix wordpress directory and files permision
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
@mhmoudsami
mhmoudsami / HTML 5 Date input with default value php
Created August 17, 2016 13:20
HTML 5 Date input with default value php
// the date fromat must be Y-m-d
<input type="date" value="<?php echo date("Y-m-d"); ?>">
@mhmoudsami
mhmoudsami / .bash_aliases
Created July 25, 2016 15:03 — forked from inbalj/.bash_aliases
Linux Bash and scripts
#!/bin/bash
#
# All the alias for you linux
#
#
# Some more ls aliases
alias e='exit'