Skip to content

Instantly share code, notes, and snippets.

View alash3al's full-sized avatar

Mohammed Al Ashaal alash3al

View GitHub Profile
<?php
/**
* Convert the specified minutes (int) to the specified format (hours)
*
* @author Mohammed Al Ashaal <https://alash3al.xyz>
* @version 1.0
* @return string
*/
function minutes2hours($m, $format = "%02d:%02d") {
if ( $m < 60 ) {
@alash3al
alash3al / gist:b4a93e5f20622bf6655541f03ea78501
Created January 26, 2017 10:04 — 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

/**
* Get the difference between two dates in detailed info
*
* @param float|int d1
* @param float|int d2
*
* @return Object
*/
function timeDiffBetween(d1, d2) {
result = {
<?php
/**
* Horus "Core" - be simple :)
*
* This version will only work on PHP 7 and higher .
*
* @package Horus
* @copyright 2014 - 2016 (c) Horus
* @author Mohammed Al Ashaal <alash3al.xyz>
* @license MIT LICENSE
@alash3al
alash3al / mksite.sh
Last active May 7, 2016 08:28
nginx+php environment
#!/bin/sh
# change this to the apps directory
apps_dir=/home/alash3al/Dev/php
# don't change this var's value
site=$1
# just change
htdocs=$apps_dir/$site
@alash3al
alash3al / xerver.php
Created March 3, 2016 12:22
dirty & quick php router only for xerver platform
<?php namespace xerver;
// sort the _SERVER array based on its keys
ksort($_SERVER);
// normalize our path-info
$_SERVER["PATH_INFO"] = preg_replace("~/+~", "/", "/" . $_SERVER["PATH_INFO"] . "/");
// start the output buffer
ob_start();
@alash3al
alash3al / google_speech2text.md
Created February 28, 2016 20:57 — forked from alotaiba/google_speech2text.md
Google Speech To Text API

Google Speech To Text API

Base URL: https://www.google.com/speech-api/v1/recognize
It accepts POST requests with voice file encoded in FLAC format, and query parameters for control.

Query Parameters

client
The client's name you're connecting from. For spoofing purposes, let's use chromium

lang
Speech language, for example, ar-QA for Qatari Arabic, or en-US for U.S. English

@alash3al
alash3al / timeDiff2.js
Created January 6, 2016 20:59
Implementation of the "since x time ago" format, it starts from second to millennium ;-)
/*
* timeDiff, return the difference between two times "in seconds"
* in the format of "since x (second|minute|...)(s) ago" .
*
* @version v2.0
* @license MIT License
* @author Mohammed Al Ashaal <www.alash3al.xyz>
* @example `console.log(timeDiff(current_unix_timestamp, old_unix_timestamp))`
* @return Object
*/
@alash3al
alash3al / timeDiff.js
Created December 31, 2015 22:07
get the difference between two unix dates in the style of "x [second|minute|hour|month|year]s ago"
// timeDiff - get the difference between two "unix" dates
// version: 1.0.0
// author: Mohammed Al Ashaal
function timeDiff(t_new, t_old) {
t = {
second: 1,
minute: 1 * 60,
hour: 1 * 60 * 60,
day: 1 * 60 * 60 * 24,
week: 1 * 60 * 60 * 24 * 7,
@alash3al
alash3al / gist:d1513cdc6d6d6f690295
Created December 31, 2015 04:08 — forked from orangexception/gist:1301150
Minify JavaScript Regular Expression

Notice

Do not run this against minified JavaScript packages. The minified packages often rely on line returns to execute correctly.

This regular expression was designed to minify simple JavaScript.

Regular Expression

(?s)[\t\r\n]|[ ][ ]+|/\*.*?\*/*

I put spaces in square brackets as a reminder that they exist. Spaces can be important. For example, $( "#foo #bar" ) should not become $("#foo#bar"). However, we do want to remove spaces if they are used for indentation.