Skip to content

Instantly share code, notes, and snippets.

View nadeem-khan's full-sized avatar

Nadeem Khan nadeem-khan

View GitHub Profile
@nadeem-khan
nadeem-khan / Linux-Commands.md
Last active September 10, 2018 12:40
Common Server Related Linux Commands.md

Generic commands

find -name skype
whereis drush
sh file.sh //(installing .sh files)
cat file.txt //(open file)
touch file.txt //(creates an empty file)
makedir -p abc/def/ghi //(will make all folders)
less etc/file.txt

echo $PATH

@nadeem-khan
nadeem-khan / Git-Commands
Last active December 9, 2016 11:53
Git Commands
git log -n 2
git log --since=2012-06-15
git log --until=2012-06-15
git log --author="Nadeem"
git log --oneline
git log SHA1..SHA2 --oneline
git log SHA..index.html
git log --format=short
git show SHA
git show --format=online HEAD
@nadeem-khan
nadeem-khan / Rails-Commands.md
Last active November 6, 2017 12:48
Rails Commands

New Rails Project:

 rails new blog

Run Rails Console:

RAILS_ENV=production rails c  (restart console too whenever you make a change in the model)

View All Routes:

/**
* Custom myCRED Widget: This months leaderboard
* This widget will show this months leaderbaord with the option to set
* a title, the number of users to include and if it should be visible for
* non-members.
* @install Paste into your theme or child-themes functions.php file
* @author Gabriel S Merovingi
* @version 1.0
*/
@nadeem-khan
nadeem-khan / change-role-based-on-balance.md
Last active February 6, 2016 20:04 — forked from gabrielmerovingi/change-role-based-on-balance
Change WordPress user role based on Mycred Points

Change WordPress user role based on Mycred Points:

add_filter( 'mycred_add', 'check_for_role_change', 99, 3 );
 function check_for_role_change( $reply, $request, $mycred ) {
// Make sure that if any other filter has declined this we also decline
if ( $reply === false ) return $reply;

// Exclude admins
if ( user_can( $request['user_id'], 'manage_options' ) ) return $reply;
@nadeem-khan
nadeem-khan / Create-Custom-Fields-in-Woocommerce-Checkout-Page.md
Last active July 21, 2022 19:16
Create Custom Fields in Woocommerce Checkout Page and Display them in Orders Details Page in Admin Area

Create Custom Fields in Woocommerce Checkout Page and Display them in Orders Details Page in Admin Area with this WordPress plugin:

<?php


/**
 * Plugin Name: Flowershop - WooCommerceCustomOverrides
 * Plugin URI: http://chillopedia.com
 * Description: Overrides WooCommerce Checkout Form Fields
  • Version: 1.0
@nadeem-khan
nadeem-khan / order-emails.md
Last active August 29, 2015 14:05 — forked from mikejolley/gist:2263203
Add custom fields to Order email of Woocommerce

Add the field to order emails:

 add_filter('woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys');

 function my_woocommerce_email_order_meta_keys( $keys ) {
$keys['How did you hear about us?'] = 'hear_about_us';
return $keys;

}

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

This extends the built-in WordPress function get_the_ID() to return the post ID both inside and outside the loop.

Used outside the loop (in header.php):

<?php if ( function_exists( 'gt_hide_nav' ) && ! gt_hide_nav() ) : ?>
  <nav role="navigation">
    <?php if ( function_exists( 'bones_main_nav' ) ) bones_main_nav(); ?>
  </nav>
@nadeem-khan
nadeem-khan / script.md
Last active August 29, 2015 14:06
Script to create columns in CSV file based on values of two other CSV files
csvmain = CSV.read('data-cleaned.csv', headers:true);nil
csvsku = CSV.read('spree_products_sku.csv', headers:true)
new_rows = [csvmain.headers]
index = 0
index_parsed = 0
start_index = 0
indices = []
csvsku.each do |row|
not_found = true

index = start_index