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 / WP3.5 Media Uploader
Last active June 20, 2019 12:53 — forked from mauryaratan/WP3.5 Media Uploader
WordPress 3.5 media uploader in easier steps. If using other than edit post screen, don't forget to use wp_enqueue_media(); in your functions.php
jQuery(document).ready(function($){
var _custom_media = true,
_orig_send_attachment = wp.media.editor.send.attachment;
$('.stag-metabox-table .button').click(function(e) {
var send_attachment_bkp = wp.media.editor.send.attachment;
var button = $(this);
var id = button.attr('id').replace('_button', '');
_custom_media = true;
wp.media.editor.send.attachment = function(props, attachment){
if ( _custom_media ) {
@hemant-tivlabs
hemant-tivlabs / gist:6c512a3209fcaf766b7732b6f56c0c87
Created July 6, 2017 11:12 — forked from hissy/gist:7352933
[WordPress] Add file to media library programmatically
<?php
$file = '/path/to/file.png';
$filename = basename($file);
$upload_file = wp_upload_bits($filename, null, file_get_contents($file));
if (!$upload_file['error']) {
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_parent' => $parent_post_id,
@hemant-tivlabs
hemant-tivlabs / buckets.liquid
Last active September 13, 2017 11:27
Simple yet flexible Shopify section to add a grid of buckets
{% assign bucket_width_class = 'one-half' %}
{% if section.settings.columns == '3' %}
{% assign bucket_width_class = 'one-third' %}
{% elsif section.settings.columns == '4' %}
{% assign bucket_width_class = 'one-quarter' %}
{% endif %}
<section class="wrapper main-content{% if section.settings.width == 'width-full' %} full-width{% endif %}" style="{%
if section.settings.width == 'width-1200' or section.settings.width == 'width-custom'
%}max-width: {% if section_settings.width == 'width-custom' %}{{ section.settings.custom_width }}{% else %}1200{% endif %}px;{%
else %}{% endif %}">
@hemant-tivlabs
hemant-tivlabs / constrained-float.css
Created December 19, 2019 11:05
Constrained Floating HTML DIV - Stays fixed at the top when the page is scrolled down, but never goes out of the container
.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 }
@hemant-tivlabs
hemant-tivlabs / shopify-search-autocomplete.js
Created January 30, 2020 11:40
Shopify search autocomplete
(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 / 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 }
<?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 / 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

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 / .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