Skip to content

Instantly share code, notes, and snippets.

View nilesolutions's full-sized avatar

Ahmed Samy nilesolutions

  • Abu dhabi
View GitHub Profile
@nilesolutions
nilesolutions / tokener.php
Created December 23, 2017 14:44
secrets sharing via token
<?php
require 'vendor/autoload.php';
function decrypt($secret, $string)
{
try {
Firebase\JWT\JWT::$leeway = 1; // $leeway in seconds is a clock skew times between the signing and verifying servers
$string = base64_decode($string);
return (array) Firebase\JWT\JWT::decode(
openssl_decrypt(
@nilesolutions
nilesolutions / gist:a30abc4db5e45112cb97df226ca63995
Created December 23, 2017 14:35
Use ‘optipng’ to optimize/re-compress your png images losslessly!
OptiPNG is a useful tool to compress png images without loss its quality, it really help reduce the bandwidth, diskspace and the loading/response time for website. I used it to re-compress all the png images on cdnjs and successfully made 206857 images smaller(see cdnjs/cdnjs@e936c87e9044fd2b123).
It’s easy to use, you can install it via apt-get, or download and build it from source :
$ sudo apt-get install optipng
Usage:
$ optipng example.png
The default compress level is 2, the range is 0~7 (may depends on the version you are using), I will always use the highest and slowest level:
$ optipng -o7 example.png
@nilesolutions
nilesolutions / wp_remove_p_around_img.php
Created December 23, 2017 12:20 — forked from vinicio/wp_remove_p_around_img.php
Remove paragraph tags around images in WordPress post/page content
<?php
/**
* Move image inside <p> tag above the <p> tag while preserving any link around image.
* Can be prevented by adding any attribute or whitespace to <p> tag, e.g. <p class="yolo"> or even <p >
*/
function remove_p_around_img($content)
{
$contentWithFixedPTags = preg_replace_callback('/<p>((?:.(?!p>))*?)(<a[^>]*>)?\s*(<img[^>]+>)(<\/a>)?(.*?)<\/p>/is', function($matches) {
$image = $matches[2] . $matches[3] . $matches[4];
@nilesolutions
nilesolutions / pars_category.php
Created December 23, 2017 11:45 — forked from ig0r74/pars_category.php
Парсер сайта на примере poverka-ndt.ru
<?php
print '<pre>';
class parserXPath extends DOMXPath {
private function getPage($url){
$ch = curl_init();
curl_setopt ($ch , CURLOPT_URL , $url);
curl_setopt ($ch , CURLOPT_USERAGENT , "Mozilla/5.0");
curl_setopt ($ch , CURLOPT_RETURNTRANSFER , 1 );
// можете добавить кучу других опций
<?php
/**
* Youtube link embed conversion
*
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
*
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
<?php
// date
$date = '423523463463'; // time stamp
$date = date("F j, Y, g:i a", $date);
// satring to date
$str = strtotime('10/16/2016');
$date = date('M d Y',$str);
echo $date;
<?php
/* ---------------------------------------------------------- */
/* minibots.class.php Ver.1.9g */
/* ---------------------------------------------------------- */
/* Mini Bots class is a small php class that allows you to */
/* use some free web seriveces online to retrive usefull data */
/* and infos. This version includes: */
/* smtp validation, check spelling, meteo, exchange rates, */
/* shorten urls, and geo referencing with IP address and more */
/* Feel free to use in your applications, but link my blog: */
<?php
/**
* Created by PhpStorm.
* User: thiphariel
* Date: 15/08/17
* Time: 19:40
*/
namespace App\Api;
<?php
/**
* simple method to encrypt or decrypt a plain text string
* initialization vector(IV) has to be the same when encrypting and decrypting
*
* @param string $action: can be 'encrypt' or 'decrypt'
* @param string $string: string to encrypt or decrypt
*
* @return string
*/
Installing memcached on Mac with Homebrew and Lunchy
This is a quick guide for installing memcached on a Mac with Homebrew, and starting and stopping it with Lunchy. I hope this tutorial will get your memcached up and running in no time.
Step 1 — Install Homebrew
Installing Homebrew is super easy. Just paste this in your terminal —
$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
You should also make sure your Homebrew is up-to-date. Use update and doctor commands to update and fix any issues it may have.