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 / 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 / youtube_id_regex.php
Created January 5, 2018 09:49 — forked from ghalusa/youtube_id_regex.php
Extract the YouTube Video ID from a URL in PHP
<?php
// Here is a sample of the URLs this regex matches: (there can be more content after the given URL that will be ignored)
// http://youtu.be/dQw4w9WgXcQ
// http://www.youtube.com/embed/dQw4w9WgXcQ
// http://www.youtube.com/watch?v=dQw4w9WgXcQ
// http://www.youtube.com/?v=dQw4w9WgXcQ
// http://www.youtube.com/v/dQw4w9WgXcQ
// http://www.youtube.com/e/dQw4w9WgXcQ
// http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcQ
@mokoshalb
mokoshalb / php-regex-meta-description.php
Created January 5, 2018 10:08
How to PHP regex match an HTML document's meta description
<?php
function parseDescription($html) {
// Get the 'content' attribute value in a <meta name="description" ... />
$matches = array();
// Search for <meta name="description" content="Buy my stuff" />
preg_match('/<meta.*?name=("|\')description("|\').*?content=("|\')(.*?)("|\')/i', $html, $matches);
if (count($matches) > 4) {
return trim($matches[4]);
}
@mokoshalb
mokoshalb / .htaccess
Created August 9, 2018 12:48 — forked from voku/gist:d958041e7b1c19356e721de1eda1e6f8
.htaccess with many options + description
# Apache Server Configs v2.14 | MIT License
# https://github.com/h5bp/server-configs-apache
# (!) Using `.htaccess` files slows down Apache, therefore, if you have
# access to the main server configuration file (which is usually called
# `httpd.conf`), you should add this logic there.
#
# https://httpd.apache.org/docs/current/howto/htaccess.html.
# ----------------------------------------------------------------------
// WARNING: jquery required!
// jquery cdn: https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js
function detectAdblock(selector) {
return ($($(selector)[0]).css('display') == 'none');
}
function preventAdblockStyles(selector) {
$(selector).attr('style', 'display: block!important;visibility: visible!important;text-decoration: none!important;');
}
@mokoshalb
mokoshalb / Office_kms
Created July 4, 2019 05:36 — forked from CHEF-KOCH/KMS_office.cmd
KMS server Windows
cd\Program Files\Microsoft Office\Office16
cd\Program Files (x86)\Microsoft Office\Office16
cscript OSPP.VBS /sethst:kms.digiboy.ir
cscript OSPP.VBS /actcscript OSPP.VBS /dstatus
slmgr.vbs /ckms