Skip to content

Instantly share code, notes, and snippets.

View manojmohangit's full-sized avatar

Manoj Mohan manojmohangit

View GitHub Profile
@manojmohangit
manojmohangit / toggle_prefix.sh
Last active May 7, 2025 09:56
Bash Script for toggling prefix in the last "n" lines of a file
#!/bin/bash
# This script can be used to switch off some features from the configuration file.
# Usage:
# ./toggle_prefix.sh filename prefix num_lines
# Example:
# ./toggle_prefix.sh yourfile.txt ";" 4
# Default values
@manojmohangit
manojmohangit / Loading Script in JS
Created August 27, 2020 07:30
Loading Script in JavaScript
(function () {
var customJS = document.createElement('script');
customJS.type = 'text/javascript';
customJS.async = true;
customJS.onload = function() {console.log("loaded")};
customJS.src = 'custom.js';
var scriptDom = document.getElementsByTagName('script')[0];
scriptDom.parentNode.insertBefore(customJS, scriptDom);
})();
@manojmohangit
manojmohangit / run-android-emulator.bat
Last active April 27, 2020 02:16
Run Android Emulator without opening Android Studio
:: Runnning Android Emulator without opening Android Studio
:: Before Running this batch script, make sure ANDROID_HOME environment variable is configured
:: This script will run your first virtual device listed by -list-avds
ECHO OFF
TITLE Run Android Emulator
set path_to_emulator_dir=%ANDROID_HOME%\emulator\
CD /D %path_to_emulator_dir%
emulator -list-avds > temp.txt
@manojmohangit
manojmohangit / reorder-pdf-file-python-script.py
Last active June 16, 2021 01:34
Python Script to reorder the sequence of PDF file
# Run the file - python reorder-pdf-file-python-script.py <input-filename> <output-filename>
# Reference from geeksforgeeks - https://www.geeksforgeeks.org/working-with-pdf-files-in-python/
# Used Python Library - PyPDF2 and sys
import PyPDF2
import sys
def PDFmerge(pdfs, output):
# creating pdf file merger object
pdfMerger = PyPDF2.PdfFileMerger()
@manojmohangit
manojmohangit / vscode-snippet-php-debug-html-break
Created October 10, 2019 06:19
Echo html break in php - Helpfull for debug purpose
{
//Type php_br for the snippet to work
"Php Debug Break": {
"prefix" : "php_br",
"body": ["echo \"<br/>\";",
"echo \"\";",
"echo \"<br/>\";"
],
"description": "Echo statement for debug purpose in php"
}
@manojmohangit
manojmohangit / vscode-snippet-html-jquery
Last active August 6, 2019 09:25
Visual Studio Code Snippet for creating html file with appropriate tags along with jquery setup
{
//Type html_setup/html_jquery_setup for the snippet to work
"Html Setup Code": {
"prefix" : "html_setup",
"body": ["<html>",
"\t<head>",
"\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
"\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />",
"\t\t<title>Page Title</title>",
@manojmohangit
manojmohangit / Check pdf file pages are rotated or not in a directory
Created July 24, 2019 18:52
Check pdf file pages are rotated or not in a directory in Python
import PyPDF2
import os
#list all the files in the directory
files = os.listdir("pdffile")
for file in files:
#check if the file is pdf, if not skip the file
if ".pdf" not in file:
continue
#open the pdf file
@manojmohangit
manojmohangit / calculateTaxToBePaid.js
Created May 21, 2019 17:30
Calculate CGST, SGST, IGST as per section 88A
var Ip = 500, // Payable IGST
Cp = 500, // Payable CGST
Sp = 500, // Payable SGST
Ic = 200, // IGST Credit
Cc = 400, // CGST Credit
Sc = 700; // SGST Credit
// Calculate Tax as per Section 88(A)
function calculateTaxToBePaid(Ip,Cp,Sp,Ic,Cc,Sc) {
@manojmohangit
manojmohangit / addVirtualCoupon.php
Created March 2, 2018 05:40
Create Virtual Coupon in Woocommerce to have custom discount on the cart
// add the below code to your theme's functions.php
/*'woocommerce_get_shop_coupon_data' is used to add virtual coupon*/
add_filter('woocommerce_get_shop_coupon_data', 'addVirtualCouponDiscount', 10, 2);
add_action('woocommerce_cart_calculate_fees', 'addCoupontoCart');
function addVirtualCouponDiscount($data, $coupon_code) {
if($coupon_code == "virtual_coupon") {
$coupon = array(
@manojmohangit
manojmohangit / wc-change-default-billing-country.php
Last active March 2, 2018 06:15
Set the default country on the checkout in Woocommerce 3.0+
add_filter('default_checkout_billing_country', 'change_default_checkout_country');
function change_default_checkout_country($county_code) {
return empty($county_code) ? 'XX' : $county_code ; // 'XX' is the default country code if there is no country code passed on to the filter (if user has saved billing country).
}