Skip to content

Instantly share code, notes, and snippets.

View ahmadawais's full-sized avatar
Building the easiest way for developers to build AI products BaseAI.dev

Ahmad Awais ⌘ ahmadawais

Building the easiest way for developers to build AI products BaseAI.dev
View GitHub Profile
use v5.12;
use warnings;
use utf8;
my $uname = 'theory';
my ($curr_month, $curr_year) = (gmtime)[4,5];
$curr_year += 1900;
$curr_month += 1;
my %projects;
for my $year (2012..$curr_year) {
@ahmadawais
ahmadawais / wp-admin-menu-reorder.php
Created January 12, 2016 09:46 — forked from raideus/wp-admin-menu-reorder.php
Re-order WordPress Admin menu items
<?php
/**
* Re-orders tabs in the WordPress Admin menu. Include this in the functions.php file of your theme.
*/
function gs_custom_menu_order($menu_ord) {
if (!$menu_ord) return true;
return array(
'index.php',
@ahmadawais
ahmadawais / criticalcss-bookmarklet-devtool-snippet.js
Created January 24, 2016 11:55 — forked from PaulKinlan/criticalcss-bookmarklet-devtool-snippet.js
CriticalCSS Bookmarklet and Devtool Snippet.js
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
@ahmadawais
ahmadawais / gist:4715b693d0432b09a9f6
Created February 21, 2016 16:56 — forked from thegdshop/gist:3171026
WooCommerce - Add checkbox field to the checkout
<?php
/**
* Add checkbox field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my-new-field"><h3>'.__('My Checkbox: ').'</h3>';
@ahmadawais
ahmadawais / wp-singleton-namespace-example.php
Created March 4, 2016 16:17 — forked from szbl/wp-singleton-namespace-example.php
Quick Singleton class to be included in WordPress plugin (or theme functions.php file) that will create a simple Person post type and shows some methods of encapsulating functionality in a class as a "namespace," as well as applying filters to things, allowing other users to extend your code.
<?php
class Sizeable_Person
{
const POST_TYPE_SLUG = 'szbl-person';
public static $instance;
public static function init()
{
if ( is_null( self::$instance ) )
@ahmadawais
ahmadawais / register-post-type.php
Created May 7, 2016 09:47 — forked from justintadlock/register-post-type.php
Help file when registering post types.
<?php
# Register custom post types on the 'init' hook.
add_action( 'init', 'my_register_post_types' );
/**
* Registers post types needed by the plugin.
*
* @since 1.0.0
* @access public

Regular Expression Cheat Sheet - PCRE

Kudos/Source: https://github.com/niklongstone/regular-expression-cheat-sheet

Anchor Description Example Valid match Invalid
^ start of string or line ^foam foam bath foam
\A start of string in any match mode \Afoam foam bath foam
$ end of string or line finish$ finish finnish
\Z end of string, or char before last new line in any match mode finish\Z finish finnish
@ahmadawais
ahmadawais / wp-i18n-cheatsheet.md
Created May 7, 2016 09:49 — forked from bueltge/wp-i18n-cheatsheet.md
WordPress i18n Cheatsheet

WordPress i18n CheatSheet

Whenever I write plugins or themes, there is one thing that needs a little extra attention and is quite frankly hard to get right: Translatable text. This list should helps me to find the right way fast.

Props to Alex Kirk, there list it inside a quiz.

You want to output the username in a sentence.

Assume that the $username has been escaped using esc_html().

@ahmadawais
ahmadawais / customizer.php
Last active May 10, 2016 15:17 — forked from grappler/customizer.php
Theme Check Customizer Issue File and Setting Name https://github.com/Otto42/theme-check/issues/155
<?php
/**
* Checks for the Customizer.
*/
class CustomizerCheck implements themecheck {
protected $error = array();
function check( $php_files, $css_files, $other_files) {
@ahmadawais
ahmadawais / customize-validate-entitled-settings.js
Last active May 11, 2016 13:49 — forked from westonruter/customize-validate-entitled-settings.js
Notify on Save only! Plugin demonstration of Customize Setting Validation: validates Customizer settings that contain titles to ensure they are not empty, and then blocks saving the Customizer until they are populated. See https://github.com/xwp/wp-customize-setting-validation
/* global wp, _customizeValidateEntitledSettingsExports */
/* exported customizeValidateEntitledSettings */
var customizeValidateEntitledSettings = ( function( $, api, exports ) {
var self = {
l10n: {
invalid_value: ''
}
};