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 / 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"]');
@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 / 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 / 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 / .htaccess
Created September 21, 2020 04:41
An .htaccess rewrite helper file that helps pass URI fragments as parameters to a single file
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /
## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
minikube stop; minikube delete &&
docker stop $(docker ps -aq) &&
rm -rf ~/.kube ~/.minikube &&
sudo rm -rf /usr/local/bin/localkube /usr/local/bin/minikube &&
launchctl stop '*kubelet*.mount' &&
launchctl stop localkube.service &&
launchctl disable localkube.service &&
sudo rm -rf /etc/kubernetes/ &&
docker system prune -af --volumes
@hemant-tivlabs
hemant-tivlabs / SpinerMan.md
Last active April 9, 2020 08:12
The "SpinerMan" PHP class is capable of processing a nested spintax (spinner text) and retrieve statistical information like max number of variations, holes, min and max words, and much more.

SpinerMan, the spintax processor

A spintax (or simply spinner text) is a specially formatted text that is capable of generating a unique articles (unique combination of words) everytime it is executed and is used popularly as an SEO measure.

SpinerMan is a PHP Class that is capable of processing a spintax and retrieve statistical information like maximum number of variations, holes, minimum and maximum number of words, and much more. It supports nested blocks and parses the input into a tree with details available at every node.

NOTE: This script was written by an unknown JavaScript developer somewhere near 2014, when spintax was a very popular thing. I'm not the original author of this wonderful script. Instead, I have merely converted the script into a PHP class and made it available to the world (thanks to GitHub!).

Member functions

<?php
/**
* GitHub webhook handler template.
*
* @see https://developer.github.com/webhooks/
* @author Miloslav Hůla (https://github.com/milo)
*/
$hookSecret = 's.e.c.r.e.t'; # set NULL to disable check
@hemant-tivlabs
hemant-tivlabs / execute-shell-command.php
Last active March 30, 2020 07:39
Execute a shell command via the PHP `shell_exec` function. Please use the file wisely and remove it from live server once the job is done, as this gives complete server shell control and makes your system vulnerable.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Shell exec</title>
<link href="https://fonts.googleapis.com/css?family=Fira+Code|Source+Sans+Pro:200,400&display=swap" rel="stylesheet" />
<style>
html, body { margin: 0; padding: 0 }
body { font-family: 'Source Sans Pro', sans-serif; font-size: 13px }
body * { box-sizing: border-box; position: relative }
h1 { color: #D66; font-size: 48px; font-weight: 200; line-height: 1em; margin: 0 0 0.5em }