Skip to content

Instantly share code, notes, and snippets.


Hemant Arora hemant-tivlabs

View GitHub Profile
hemant-tivlabs /
Last active Mar 31, 2021
Use modClass instead of jQuery's `addClass` or `removeClass` to save on writing conditional if-else statements


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) {
} else {
hemant-tivlabs / curl-request.php
Last active Sep 30, 2020
A more configurable PHP cURL request function
View curl-request.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 / gitlab-webhook.php
Created Sep 24, 2020
Helps deploy a Gitlab repo to the server location (includes clone and pull upon every commit to master branch)
View gitlab-webhook.php
/* gitlab deploy webhook */
define('GITLAB_VALIDATE_REQUEST_TOKEN', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('GITLAB_PERSONAL_ACCESS_TOKEN', 'xxxxxxxxxxxxxxxxxxxx');
define('GITLAB_USERNAME', 'xxxxxxxxxx');
$repositories = array('xxxxxxxxxx');
try {
hemant-tivlabs / .htaccess
Created Sep 21, 2020
An .htaccess rewrite helper file that helps pass URI fragments as parameters to a single file
View .htaccess
<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 /
Last active Apr 9, 2020
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

View github-webhook-handler.php
* GitHub webhook handler template.
* @see
* @author Miloslav Hůla (
$hookSecret = 's.e.c.r.e.t'; # set NULL to disable check
hemant-tivlabs / execute-shell-command.php
Last active Mar 30, 2020
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.
View execute-shell-command.php
<!DOCTYPE html>
<html lang="en">
<title>Shell exec</title>
<link href="|Source+Sans+Pro:200,400&display=swap" rel="stylesheet" />
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 }
View shopify-search-autocomplete.js
(function($) {
$(document).ready(function() {
var $search_form = $('#header #form-search'),
search_cache = [];
$search_form.find('input[name="q"]').attr('autocomplete', 'off');
function hide_search_form_autocomplete() {
function show_search_form_autocomplete() {
hemant-tivlabs / constrained-float.css
Created Dec 19, 2019
Constrained Floating HTML DIV - Stays fixed at the top when the page is scrolled down, but never goes out of the container
View constrained-float.css
.has-constrained-float { position: relative; /* This container div should have a defined height of its own, that defines the range the floating child could travel. In general use, this could be a child of a flex parent, as that would automatically take the height of its sibling */ }
.constrained-float.fixed { position: fixed; top: 0 }
.constrained-float.absolute { bottom: 0; position: absolute; top: auto }