Skip to content

Instantly share code, notes, and snippets.

View tanmay27vats's full-sized avatar

Tanmay Vats tanmay27vats

View GitHub Profile
@tanmay27vats
tanmay27vats / install.sh
Last active May 28, 2018 04:39
Install pthreads (Multithreading) on Amazon AWS EC2 server having PHP version 5.6.x
#Install pthreads on AWS-EC2 with php5.6
#!/usr/bin/env bash
sudo yum update -y
sudo yum install httpd
cd
wget https://mirror.webtatic.com/yum/el6/latest.rpm
sudo yum install latest.rpm -y
sudo yum-config-manager --enable webtatic
sudo yum clean all
sudo yum install --enablerepo=webtatic php56w php56w-bcmath php56w-gd php56w-imap php56w-mbstring php56w-mcrypt php56w-mysqlnd php56w-pear php56w-xml php56w-soap php56w-devel -y
@tanmay27vats
tanmay27vats / replace_french_chars.php
Created February 28, 2017 10:04
Replace French orthography to Normal English. I used this to rename folder-name/file-names/slugs
function frenchChars($string)
{
$normalizeChars = array(
'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A',
'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I',
'Ï'=>'I', 'Ñ'=>'N', 'Ń'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U',
'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a',
'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i',
'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ń'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u',
@tanmay27vats
tanmay27vats / function.php
Last active April 18, 2024 08:30
Remove "Product Type/Product Data" Dropdown Options - WooCommerce
add_filter( 'product_type_selector', 'remove_product_types' );
function remove_product_types( $types ){
unset( $types['grouped'] );
unset( $types['external'] );
unset( $types['variable'] );
return $types;
}
@tanmay27vats
tanmay27vats / shopify-variant-filters.txt
Created March 9, 2017 13:07
Showing Shopify product's variants (Size / Length / Color) as filters on collection page.
/*****
Here, I am assuming that you have already assigned all variants as tags of a product. Because Shopify filter does not work with variant options.
And, if you assigns all variants as tags you can not differentiate them from tags.
Here I code that is working for 2 filters Size & Length (with mulitple options. ie mulitple sizes, multiple lengths, etc
*****/
<div class="filters-toolbar">
<div class="filters-toolbar__item size-filter">
{% assign variant_sizes = "" %}
{% assign variant_lengths = "" %}
@tanmay27vats
tanmay27vats / yahoo_weather.php
Last active July 23, 2018 12:03
Yahoo weather YQL API without authentication / No OAuth required - PHP script
<?php
class Yahoo_Weather
{
protected $base_url = "http://query.yahooapis.com/v1/public/yql";
protected $location = false;
protected $units = false;
protected $current = false;
protected $future = false;
protected $data = false;
@tanmay27vats
tanmay27vats / bash.sh
Created April 24, 2017 08:36
change editor for git
git config --global core.editor "vim"
#Run above command in Terminal / git-bash to change git editor from default to "vim" editor
@tanmay27vats
tanmay27vats / update.sql
Created April 24, 2017 08:40
Renaming Custom Post Types and Taxonomies Through MySQL Query - Wordpress
SQL query for renaming the posts:
UPDATE `wp_posts` SET `post_type` = '<new post type name>' WHERE `post_type` = '<old post type name>';
SQL query for renaming taxonomy:
UPDATE `wp_term_taxonomy` SET `taxonomy` = '<new taxonomy name>' WHERE `taxonomy` = '<old taxonomy name>';
# That should take care of all of the database areas. Just remember to match the new names in the code where the post types or taxonomies are registered. As far as I know, this is not handled in any plugins yet.
@tanmay27vats
tanmay27vats / ios_push_notification.php
Last active May 28, 2018 04:41
Apple Push Notification service (APNs) - iOS Push Notification in PHP
<?php
// Provide the Host Information.
$vHost = 'gateway.sandbox.push.apple.com';
//$vHost = 'gateway.push.apple.com';
$vPort = 2195;
// Provide the Certificate and Key Data.
$vCert = 'Certificates.pem';
@tanmay27vats
tanmay27vats / script.js
Last active January 5, 2024 22:58
Custom Add to cart WooCommerce, Refresh fragments data, Refresh cart total items, Get product variation
product_add_to_cart : function(){
var ajx_data = {};
var ajx_grab = {};
$(document).on('change','.single-product .variations_form select',function(e){
var $this = $(this);
var pro_id = $(".single-product .variations_form").attr('data-product_id');
var attribute_name = $this.attr('data-attribute_name');
var attribute_value = $this.val();
var post_ajxurl = window.location+"?wc-ajax=get_variation";
@tanmay27vats
tanmay27vats / function.php
Created June 26, 2017 11:46
Show "Stock Out" if all variations are stock out.
function wc_show_variable_product_stock_out()
{
global $product;
if( $product->is_type( 'variable' ) )
{
$args = array(
'post_type' => 'product_variation',
'post_status' => array( 'private', 'publish' ),
'numberposts' => -1,
'orderby' => 'menu_order',