Skip to content

Instantly share code, notes, and snippets.

View hemant-tivlabs's full-sized avatar

Hemant Arora hemant-tivlabs

View GitHub Profile
@hemant-tivlabs
hemant-tivlabs / gitlab-webhook.php
Created September 24, 2020 07:08
Helps deploy a Gitlab repo to the server location (includes clone and pull upon every commit to master branch)
<?php
/* gitlab deploy webhook */
define('GITLAB_VALIDATE_REQUEST_TOKEN', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('GITLAB_PERSONAL_ACCESS_TOKEN', 'xxxxxxxxxxxxxxxxxxxx');
define('GITLAB_USERNAME', 'xxxxxxxxxx');
$repositories = array('xxxxxxxxxx');
ob_start();
try {
@hemant-tivlabs
hemant-tivlabs / curl-request.php
Last active September 30, 2020 15:50
A more configurable PHP cURL request function
<?php
function curl_request($url, $method = 'POST', $params = array(), $options = array()) {
try {
$options_defaults = array(
'headers' => array(),
'json_response' => true,
'connecttimeout' => null,
'timeout' => null,
'returnresponsecode' => false
);
@hemant-tivlabs
hemant-tivlabs / jQuery-modClass.md
Last active March 31, 2021 09:33
Use modClass instead of jQuery's `addClass` or `removeClass` to save on writing conditional if-else statements

jQuery.modClass()

In my opinion, instead of using the traditional if-else statements to switch CSS classes, using a conditional operator in conjunction with modClass makes the code simpler, easier to read and saves on code lines.

Instead of doing the traditional way:

if (i < 5) {
  jQuery('ul').removeClass('many-items');
} else {
@hemant-tivlabs
hemant-tivlabs / native-language-selector.liquid
Created July 8, 2021 12:27
Adds language selector dropdown to Shopify theme
# Native Language Selector
Adds language selector dropdown to Shopify theme
## Usage
```
{% render 'native-language-selector', id: 'header-nls' %}
```
@hemant-tivlabs
hemant-tivlabs / magic-swatches.js
Created July 8, 2021 09:49
Magic Swatches - convert Shopify PDP variant option dropdowns to swatches
class magicSwatches {
constructor(config) {
config = typeof config == 'undefined' ? {} : config;
this.option_wrapper_selector = typeof config.option_wrapper != 'undefined' ? config.option_wrapper : '.selector-wrapper';
this.product_form_selector = typeof config.product_form != 'undefined' ? config.product_form : 'form.product-form';
this.strip_giftcard_values = typeof config.strip_giftcard_values != 'undefined' ? config.strip_giftcard_values : true;
this.form = document.querySelector(this.product_form_selector);
this.option_wrappers = document.querySelectorAll(this.option_wrapper_selector);
this.variant_selectbox = this.form.querySelector('[name="id"]');