Skip to content

Instantly share code, notes, and snippets.

View ahmu83's full-sized avatar
🎯
Focusing

Ahmad Karim ahmu83

🎯
Focusing
View GitHub Profile
@ahmu83
ahmu83 / get-next-dates.php
Created September 5, 2022 15:52
Get next n number of dates from a specified date or the current date
<?php
/**
* Get next n number of dates from a specified date
*
* @param Integer $n Number of dates
* @param String $from Now or the from date
* @param Boolean $exclude_weekends Exclude weekends
* @return Array
*/
@ahmu83
ahmu83 / wp-adminbar-toggler.php
Last active February 5, 2022 19:09
wp-adminbar toggler. Toggle adminbar from a URL parameter.
<?php
/**
* wpadminbar toggle for conveniently showing/hiding adminbar from a URL parameter.
*
* USAGE:
* 1. Upload wp-adminbar-toggler.php to theme
* 2. Include this file in theme's functions.php
* - require_once( get_stylesheet_directory() . '/wp-adminbar-toggler.php' );
* 3. Use ?adminbar=1 in the URL to show adminbar. Use ?adminbar=0 in the URL to
<?php
/**
* This function retrieves post meta using a custom $wpdb query. There are two reasons for this approach.
* 1. When doing get_post_meta to query all the meta keys it returns an array or array
* 2. This function also queries for LIKE fields. i.e, get_post_meta2(1, 'first_name, last_name, hobby_%')
*
* TODO: distinct meta_key, meta_value
*
*/
@ahmu83
ahmu83 / copy-to-clipboard-bookmarklet.md
Created January 4, 2022 21:52 — forked from stefanmaric/copy-to-clipboard-bookmarklet.md
Create Bookmarklet (browser bookmark that executes Javsacript) to copy a given text to Clipboard

Copy-to-clipboard Bookmarklet

Create Bookmarklet (browser bookmark that executes Javsacript) to copy a given text to Clipboard.

This is the base javascript:

(function (text) {
  var node = document.createElement('textarea')
  var selection = document.getSelection()
<!-- Transparent GIF Image Favicon -->
<link rel="icon" href="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" type="image/gif">
<!-- Black GIF Image Favicon -->
<link rel="icon" href="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" type="image/gif">
<!-- Transparent PNG Image Favicon -->
<link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" type="image/png">
<?php
/**
* Function to check for more than one
* array keys of a long/nested associative array.
*
* i.e, instead of doing this $var['key1']['key2'] (which will result in undefined
* notice if the key/index does not exist) you can do this isset_key($var, 'key1', 'key2')
*
* @param array $var Array variable
<?php
/**
* There is not a hard and fast rule to check if the
* current page is the blog page (the page you set in
* the settings to display blog posts). This is what the
* documentation says: "There is no conditional tag for the blog page."
*
* Read the full section here: https://codex.wordpress.org/Conditional_Tags
*
* Not sure if there is another way to achieve this!
@ahmu83
ahmu83 / print_are.php
Last active May 13, 2021 19:49
Pretty Version of PHP's print_r Function
<?php
/**
* A pretty version of "print_r" function
*
* @param Array|stdClass $obj
* @param string $title Optional.
* @param bool $collapse Optional.
* @return string Type returned.
*/
<!DOCTYPE html>
<html>
<head>
<title>Simple CSS Loading Icon</title>
</head>
<style type="text/css" media="screen">
body {
margin-top: 150px;
$.ajax({
url: '/URL/',
type: 'POST', /* POST/GET */
dataType: 'json', /* xml/html/script/json/jsonp */
data: form_data,
crossDomain: true,
success: function(data, textStatus, xhr) {
/* success */
},
error: function(xhr, textStatus, errorThrown) {