Skip to content

Instantly share code, notes, and snippets.

View mhmoudsami's full-sized avatar

Sami El mhmoudsami

  • germany
  • 16:53 (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'
});
});
@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

@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 / .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'
@mhmoudsami
mhmoudsami / vhosts.sh
Created July 25, 2016 14:47 — forked from aamnah/vhosts.sh
Bash script to create Virtual host files [source](http://ubuntuforums.org/showthread.php?t=2106950)
#!/bin/bash
# Source: http://ubuntuforums.org/showthread.php?t=2106950
#Check for root
true="true"true="true"
ROOT_UID=0
overwrite=""
if [ "$UID" -ne "$ROOT_UID" ]; then
echo "Must be run as root, use sudo."
exit 0
fi
@mhmoudsami
mhmoudsami / install-wp.sh
Created July 25, 2016 14:43 — forked from aamnah/install-wp.sh
Install WordPress via Shell
# Colors
Color_Off='\033[0m' # Color Reset
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[0;33m' # Yellow
Cyan='\033[0;36m' # Cyan
# Bold
BRed='\033[1;31m' # Red
BGreen='\033[1;32m' # Green
@mhmoudsami
mhmoudsami / vhost.sh
Created July 25, 2016 14:40 — forked from aamnah/vhost.sh
Bash script to create virtual host file
#!/bin/sh
############
# Author: Aamnah
# URL: http://aamnah.com
# Based on: https://www.linode.com/docs/websites/hosting-a-website
############
# Reset
Color_Off='\033[0m' # Text Reset
@mhmoudsami
mhmoudsami / color_luminance.php
Created July 17, 2016 12:48 — forked from stephenharris/color_luminance.php
Lighten or darken a given colour
<?php
/**
* Lightens/darkens a given colour (hex format), returning the altered colour in hex format.7
* @param str $hex Colour as hexadecimal (with or without hash);
* @percent float $percent Decimal ( 0.2 = lighten by 20%(), -0.4 = darken by 40%() )
* @return str Lightened/Darkend colour as hexadecimal (with hash);
*/
function color_luminance( $hex, $percent ) {
// validate hex string
@mhmoudsami
mhmoudsami / _wordpress_core.scss
Created June 28, 2016 14:54 — forked from lgladdy/_wordpress_core.scss
WordPress Core Styles in SASS
/* =WordPress Core - Sassified.
-------------------------------------------------------------- */
.alignnone {
margin: 5px 20px 20px 0;
}
.aligncenter, div.aligncenter {
display: block;
margin: 5px auto 5px auto;
}