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 / 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 / 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 / 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(
<?php
/*
* The MIT License
*
* Copyright 2016 Steve Guidetti.
*
* 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
<?php
function compose(callable $initial, callable ...$functions)
{
if (count($functions) < 1) {
throw new \InvalidArgumentException('at least two functions are required');
}
return array_reduce($functions, function ($f, $g) {
return function (...$args) use ($f, $g) {
return $f($g(...$args));
@nilesolutions
nilesolutions / CompressAwsImages.php
Created December 29, 2017 21:02 — forked from Ryuske/CompressAwsImages.php
Laravel 4.2 artisan command for compressing AWS images
<?php
/**
* Command for losslessly compressing Amazon AWS images
*/
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
/**
@nilesolutions
nilesolutions / DemoReel100.ino
Created January 19, 2018 09:44 — forked from kriegsman/DemoReel100.ino
FastLED "100-line" demo reel
#include "FastLED.h"
// FastLED "100-lines-of-code" demo reel, showing just a few
// of the kinds of animation patterns you can quickly and easily
// compose using FastLED.
//
// This example also shows one easy way to define multiple
// animations patterns and have them automatically rotate.
//
// -Mark Kriegsman, December 2014
@nilesolutions
nilesolutions / convert-wordpress-to-blogger-export-file.php
Last active January 19, 2018 11:53
convert your wordpress to blogger xml file that you can import your posts into your blog سكريبت التحويل من الوردبريس الي بلوجر
<?php
ini_set('max_execution_time', 0);
ini_set('memory_limit' , '500M');
class convert2bloger {
private $database = NULL;
private $errors = array();
private $curEntry = array(); // current entry of the parser
@nilesolutions
nilesolutions / README.md
Created April 2, 2018 12:09 — forked from hofmannsven/README.md
My simply Git Cheatsheet
@nilesolutions
nilesolutions / Dockerfile
Created June 22, 2018 19:06 — forked from hardillb/Dockerfile
Mosquitto + auth_plugin + mongo
FROM ubuntu:16.04
MAINTAINER Ben Hardill <[email protected]>
ENV DEBIAN_FRONTEND noninteractive
USER root
RUN apt-get update && apt-get install -y \
pkg-config \