Skip to content

Instantly share code, notes, and snippets.

View OkoyaUsman's full-sized avatar
🏠
Available for freelance job

Okoya Usman OkoyaUsman

🏠
Available for freelance job
View GitHub Profile
@OkoyaUsman
OkoyaUsman / slugit.php
Last active October 30, 2017 09:14 — forked from tlongren/example.php
PHP Clean URL (SLUG) Generator
<?php
setlocale(LC_ALL, 'en_US.UTF8');
function slugit($str, $replace=array(), $delimiter='-') {
if ( !empty($replace) ) {
$str = str_replace((array)$replace, ' ', $str);
}
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
@OkoyaUsman
OkoyaUsman / url-to-domain.php
Created December 10, 2017 04:44
Get the domain name from a URL for display purposes in PHP
<?php
// This is PHP function to convert a user-supplied URL to just the domain name,
// which I use as the link text.
// Remember you still need to use htmlspecialchars() or similar to escape the
// result.
function url_to_domain($url)
{
@OkoyaUsman
OkoyaUsman / .htaccess
Created December 11, 2017 07:28
.htaccess code to leverage browser caching and enable compression for google page speed insight.
I took my chance to provide full .htaccess code to pass on Google PageSpeed Insight:
1. Enable compression
2. Leverage browser caching
# Enable Compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
@OkoyaUsman
OkoyaUsman / mediaqueries.css
Created December 18, 2017 17:52
Media Queries for CSS3 responsive mobile-first web design for all main devices.
@media (min-width:320px) { /* smartphones, iPhone, portrait 480x320 phones */ }
@media (min-width:481px) { /* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */ }
@media (min-width:641px) { /* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */ }
@media (min-width:961px) { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
@media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
@media (min-width:1281px) { /* hi-res laptops and desktops */ }
@OkoyaUsman
OkoyaUsman / htaccess-rules.txt
Created December 23, 2017 05:26
Meaning of special characters in htaccess
.htaccess flag list
C (chained with next rule)
CO=cookie (set specified cookie)
E=var:value (set environment variable var to value)
F (forbidden - sends a 403 header to the user)
G (gone - no longer exists)
H=handler (set handler)
L (last - stop processing rules)
Last rule: instructs the server to stop rewriting after the preceding directive is processed.
@OkoyaUsman
OkoyaUsman / redirect-js.js
Created December 26, 2017 23:43
A simple random page redirector using Javascript. Note: Please don't forget to add comma , after each of the link (except the last link) and please put http:// or https:// in-front of each link.
var linkList = [
"https://google.com",
"https://yahoo.com",
"https://facebook.com",
"https://twitter.com",
"https://ebay.com",
"https://youtube.com"
];
var randomLink = linkList[Math.floor(Math.random()*linkList.length)];
@OkoyaUsman
OkoyaUsman / adblock-detector.js
Created December 26, 2017 23:51
AdBlock detector for Google AdSense. Detects if a user is using AdBlock or not and sends the tracking data to Google Analytics.
function AdblockDetector(){
}
AdblockDetector.prototype.run = function() {
var ad = document.querySelector("ins.adsbygoogle");
if(ad && ad.innerHTML.replace(/\s/g, "").length == 0) {
//Adblock detected
if(typeof ga !== 'undefined') {
ga('send', 'event', 'AdBlock', 'True', {'nonInteraction': 1}); //event hit will not be used in bounce-rate calculation.
}else if(typeof _gaq !== 'undefined') {
_gaq.push(['_trackEvent', 'Adblock', 'True', undefined, undefined, true]); //event hit will not be used in bounce-rate calculation.
@OkoyaUsman
OkoyaUsman / dl.php
Created January 2, 2018 19:44
PHP 7.1+ File Download Generator
<?php
if(isset($_GET['signature'])){
ini_set('max_execution_time', 0);
$useragent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36";
$v = base64_decode($_GET['signature']);
parse_str($v);
if(!isset($mime)){
$mime = "video/mp4";
}
$extension = explode("/", $mime)[1];
@OkoyaUsman
OkoyaUsman / php2js-array.php
Last active November 14, 2024 22:36
How to Convert PHP Array into JavaScript Array
<?php
/*
You can easily use PHP array in javascript you only need to convert PHP array into JSON format Using json_encode() function.
PHP array can be converted to JavScript array and accessible in JavaScript.
Whatever the array type is, a single or multidimensional or indexed or associative array.
*/
//In PHP
var $booksArray = array("Book-1", "Book-2", "Book-3");
@OkoyaUsman
OkoyaUsman / imgtransfer.php
Created January 4, 2018 12:10
3 ways to download and save a remote image on your server using PHP
<?php
/*
In this tutorial I am going to show you some PHP Methods By which you can easily download remote server image on your local server.
Suppose you don't have FTP access of images but you are able to access images via http port and you want to perform bulk image download.
Then these methods are very useful and you can try any of them to download and save a remote images on your server folder.
*/
// Method-1: By using simple copy() function in PHP
copy("REMOTE SERVER IMAGE URL", 'LOCAL SERVER PATH');
// ie: