Skip to content

Instantly share code, notes, and snippets.

View vpadhariya's full-sized avatar

Vijay Padhariya vpadhariya

View GitHub Profile
@vpadhariya
vpadhariya / https-for-express-node-server.js
Created January 6, 2024 04:30
Here how we can enable https server for Express Node Server
const express = require('express');
var bodyParser = require('body-parser')
const mongoose = require('mongoose');
const routes = require('./routes/routes');
// for HTTP and HTTPS listening
var fs = require('fs');
var http = require('http');
var https = require('https');
var privateKey = fs.readFileSync('{PATH TO PRIVATE KEY}/privkey.pem', 'utf8');

Awesome-Selfhosted

Awesome

Selfhosting is the process of locally hosting and managing applications instead of renting from SaaS providers.

This is a list of Free Software network services and web applications which can be hosted locally. Non-Free software is listed on the Non-Free page.

See Contributing.

@vpadhariya
vpadhariya / security.php
Created July 27, 2021 13:33
WordPress Security Rules as mu-plugins (put this file under wp-content/mu-plugins/security.php and you are done)
<?php
/*
Plugin Name: WP Security Rules
Plugin URI: https://digitize-info.com
Description: Here we will define the site wise security rules
Version: 0.3
Author: Vijay Padhariya
Author URI: https://vijaypadhariya.com
*/
@vpadhariya
vpadhariya / YoutubeCommand.php
Created September 17, 2019 17:25
Youtube Data search and parsing
<?php
//require_once('modules/admin/models/ServiceProvider.php');
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class YoutubeCommand extends CConsoleCommand
@vpadhariya
vpadhariya / sanitize_output.php
Created August 23, 2018 11:18
Sanitize output of html, remove html, css, js comments and trim output.
<?php
/*
* Compressing the HTML Output
*/
function sanitize_output($buffer)
{
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
@vpadhariya
vpadhariya / .htaccess
Created August 8, 2018 14:17
Apache Various Compression Techniques via .htaccess
<IfModule mod_mime.c>
AddType text/css .css
AddType text/x-component .htc
AddType application/x-javascript .js
AddType application/javascript .js2
AddType text/javascript .js3
AddType text/x-js .js4
AddType text/html .html .htm
AddType text/richtext .rtf .rtx
AddType image/svg+xml .svg .svgz
@vpadhariya
vpadhariya / create_directory.php
Last active July 24, 2018 10:23
In any of core php project this function will help you create directory structure like follow PROJECT_ROOT/uploads/1_100 PROJECT_ROOT/uploads/101_200 PROJECT_ROOT/uploads/201_300 here is how to use it below will create PROJECT_ROOT/uploads/1_100 and return its path. createDir(1, "PROJECT_ROOT/uploads/"); Where PROJECT_ROOT is the hard path of th…
<?php
/**
* Creates a directory according to given id and parent dir path
* @params integer $id this id will decide which directory to return or create and then return
* @params string $parent this will decide what is the path of the directory.
*/
function createDir($id, $parent)
{
$nd_dirlimit = 100;
$mod = ceil($id / $nd_dirlimit) - 1;
@vpadhariya
vpadhariya / clone site using wget.txt
Created January 23, 2018 07:57
Clone site and remove query string values from the files in linux.
# Clone entire site.
wget --content-disposition --execute robots=off --recursive --no-parent --continue --no-clobber http://example.com
# Remove query string from a static resource.
for i in `find $1 -type f -name "*\?*"`; do mv $i `echo $i | cut -d? -f1`; done
@vpadhariya
vpadhariya / wordpres-get-posts-base-on-category-ratio.php
Created October 11, 2017 08:34
WordPress - Get posts base on ratio percentage per category
<?php
/**
* Category Ratio: Get Posts base on Custom % per category it means that each category.
*
* Get Category ratio from Settings like below.
* $category_ratio = array(category_id for selected category => inserted category ratio);
*
* NOTE: Most important the total of category ratio for all the selected categories must be 100%
* (this you need to set using JavaScript logic on back admin) otherwise it will create problem.
@vpadhariya
vpadhariya / PHP-Trim-output.php
Last active August 10, 2017 08:21
PHP Trim html output of a html page
<?php
/**
* Trim output of html
*/
function trim_output($buffer)
{
// Replace key with their values.
$replace = array(
"#<!--.*?-->#s" => "", // strip comments