Skip to content

Instantly share code, notes, and snippets.

View Clivern's full-sized avatar

Ahmed Clivern

View GitHub Profile
@Clivern
Clivern / gist:2476ec77ad55248f445a
Last active August 29, 2015 14:09
How To Add Custom Rewrite Rules In WordPress
<?php
/*
Plugin Name: Products Plugin
Plugin URI: http://clivern.com/how-to-add-custom-rewrite-rules-in-wordpress/
Description: Register URL rules for our products
Version: 1.0
Author: Clivern
Author URI: http://clivern.com/
License: MIT
*/
@Clivern
Clivern / utf_csv.php
Created October 14, 2016 23:49
CSV With UTF-8 Support
$results = [
['اسم المستخدم', 'اسم المستخدم', 'اسم المستخدم'],
[5,8,6],
[5,8,7],
[2,3,5]
];
header('Content-Encoding: UTF-8');
header('Content-type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename=sss.csv');
echo "\xEF\xBB\xBF"; // UTF-8 BOM
@Clivern
Clivern / install-tomcat-8.5.14.sh
Last active January 7, 2020 01:07
How to Install Apache Tomcat 8 on Ubuntu 16.04
#!/bin/bash
# For More Info http://clivern.com/how-to-install-apache-tomcat-8-on-ubuntu-16-04
sudo apt-get update
sudo apt-get install default-jdk
sudo apt-get install unzip
cd /opt
curl -O http://apache.mirrors.ionfish.org/tomcat/tomcat-8/v8.5.15/bin/apache-tomcat-8.5.15.zip
sudo unzip apache-tomcat-8.5.15.zip
sudo mv apache-tomcat-8.5.15 tomcat
@Clivern
Clivern / PID.sh
Created May 1, 2017 10:30
Run Process In BG & Get PID
foo &
FOO_PID=$!
# do other stuff
kill $FOO_PID
@Clivern
Clivern / install_gradle_4_0.sh
Created June 26, 2017 13:42
Install Gradle V4.0
cd /opt
sudo wget https://services.gradle.org/distributions/gradle-4.0-bin.zip
sudo unzip gradle-4.0-bin.zip
sudo mv gradle-4.0 gradle
sudo rm gradle-4.0-bin.zip
export PATH=$PATH:/opt/gradle/bin
gradle -v
@Clivern
Clivern / MHD.sql
Created July 26, 2017 13:49
Managing Hierarchical Data in MySQL
CREATE TABLE category(category_id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20) NOT NULL, parent INT DEFAULT NULL);
INSERT INTO category VALUES(1,'ELECTRONICS',NULL),(2,'TELEVISIONS',1),(3,'TUBE',2),(4,'LCD',2),(5,'PLASMA',2),(6,'PORTABLE ELECTRONICS',1),(7,'MP3 PLAYERS',6),(8,'FLASH',7),(9,'CD PLAYERS',6),(10,'2 WAY RADIOS',6);
SELECT t1.name AS lev1, t2.name as lev2, t3.name as lev3, t4.name as lev4, t5.name as lev5
FROM category AS t1
INNER JOIN category AS t2 ON t2.parent = t1.category_id
INNER JOIN category AS t3 ON t3.parent = t2.category_id
INNER JOIN category AS t4 ON t4.parent = t3.category_id
INNER JOIN category AS t5 ON t5.parent = t4.category_id
@Clivern
Clivern / Interface.php
Created July 27, 2017 11:48
OOP Class Implementation
<?php
interface Storage
{
public function set($data);
public function get();
public function store();
}
@Clivern
Clivern / Java_systemd.md
Created October 16, 2017 11:38
Systemd For Java Project

Add Service File

sudo nano /etc/systemd/system/racter.service

Add Service Configs

[Unit]
Description=Racter Service
After=syslog.target
@Clivern
Clivern / SlugService.java
Created February 22, 2018 15:27
Java Class To Create Slugs
/*
* Copyright (C) 2018 Clivern <http://clivern.com>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
@Clivern
Clivern / python_decorator_guide.md
Created April 27, 2018 23:53 — forked from Zearin/python_decorator_guide.md
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].