Skip to content

Instantly share code, notes, and snippets.

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

Okoya Usman mokoshalb

🏠
Available for freelance job
  • NodeTent - Web Development & IT Services Company
  • Lagos, Nigeria
View GitHub Profile
@mokoshalb
mokoshalb / 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);
@mokoshalb
mokoshalb / blogger2wordpresslinkfix.php
Last active November 16, 2017 09:08 — forked from ryandonsullivan/fixlinks.php
Fix Blogger post permalinks after import into WordPress
<?php
/**
* Rewrite WordPress URLs to match Blogger permalinks exactly.
*
* This script is intended for one time use only after importing Blogger
* content into WordPress and should be removed from the server immediately
* after the script has run one time. It shouldn't be needed again after the
* initial rewrite.
*
* @version 0.1.0
@mokoshalb
mokoshalb / luhn.php
Created November 30, 2017 21:30
Simple PHP script to generate syntactically valid credit card numbers using the Luhn check. Also see http://en.wikipedia.org/wiki/Luhn_algorithm Not valid for making transactions anywhere!
<?
$bin = $_POST['bin'];
$length = $_POST['length'];
if ( $length == 0 )
$length = 16;
if ( $bin != '' )
$cardNumber = completed_number( $bin, $length );
@mokoshalb
mokoshalb / 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)
{
@mokoshalb
mokoshalb / .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
@mokoshalb
mokoshalb / php-regex-page-title.php
Created December 14, 2017 08:02
How to PHP regex match an HTML document's title
<?php
function parseTitle($html) {
// Get the text in a <title>
$matches = array();
preg_match("/<title>(.*)<\/title>/is", $html, $matches);
if (count($matches) > 1) {
return trim($matches[1]);
} else {
return null;
}
@mokoshalb
mokoshalb / 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 */ }
@mokoshalb
mokoshalb / 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.
@mokoshalb
mokoshalb / 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)];
@mokoshalb
mokoshalb / 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.