Skip to content

Instantly share code, notes, and snippets.

Avatar

Hemant Arora hemant-tivlabs

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

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 Sep 30, 2020
A more configurable PHP cURL request function
View curl-request.php
<?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 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
<?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 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
View minikube_uninstall.sh
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 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.
View SpinerMan.md

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
<?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 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">
<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 }
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() {
$search_form.removeClass('show-autocomplete');
}
function show_search_form_autocomplete() {
@hemant-tivlabs
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 }