Skip to content

Instantly share code, notes, and snippets.

View isaumya's full-sized avatar
👨‍💻
Think Twice, Code Once

Saumya Majumder isaumya

👨‍💻
Think Twice, Code Once
View GitHub Profile
@isaumya
isaumya / adblock-detector.js
Created January 8, 2017 07:11
Show some message to the users when they are using AdBlocker on your website
/** IMPORTANT NOTE:
* Make sure you put this JS in the footer of your site
* and not to include in a file and then load it in the defer or async way
* Otherwose the script may not work properly.
*
* Though this script was written keeping WordPress in mind, but it can be used
* on any CMS or in any sites. Enjoy :)
*
* Custom script written for www.iSaumya.com/blog/ by Saumya Majumder in 2016
**/
@isaumya
isaumya / back-button-refresh.php
Created December 23, 2016 12:05
Refresh page when click browser back button
<?php
/**
* Adding a special function to ensure that when the user click on back button,
* it will reload the pages, instead of loading from cache so that the js can run again
**/
add_action( 'wp_footer', 'aicp_refresh_on_back' );
function aicp_refresh_on_back() {
echo '<input type="hidden" id="refreshed" value="no">
<script type="text/javascript">
onload=function(){
@isaumya
isaumya / console-log-special-message.js
Created December 11, 2016 11:01
Showing special message in the console.log
/* This script will show a special designed message in the console.log section of your website
* for those who looks for something extra in your website.
* Fiddle Link: https://jsfiddle.net/isaumya/vtjswjuL/
**/
jQuery(function ($) {
try{
console.log("%c < ISAUMYA /> ","background: linear-gradient(to right, rgba(231,76,60,1) 0%,rgba(155,89,182,1) 100%););font-size:3em;border-radius:1em;color:#ffffff;font-weight:bold;font-style: italic;");
console.log('%c made with ♥ by Saumya Majumder © 2016', 'color: #e74c3c;font-size:1.1em;');
}
catch(e){}
@isaumya
isaumya / html-title-changer.js
Created December 11, 2016 10:35
Change the title of the page if user click on some other tag
/* Let's say the normal title of page in the <title> tag is => iSaumya.com
* but when user will go to some other tab of the browser, it will be changed
* from iSaumya.com to 。◕‿◕。 iSaumya.com
**/
var original_title = document.title;
document.addEventListener("visibilitychange", function(){
if(document.hidden)
document.title = "。◕‿◕。 iSaumya.com";
else
document.title = original_title;
@isaumya
isaumya / some-plugin-file-name.php
Created October 22, 2016 16:57
WordPress basic plugin header example
<?php
/*
Plugin Name: Type a plugin name here
Plugin URI: https://www.isaumya.com/ (This is supposed to link to the plugin's official page, but you can put any link here)
Description: Type a detailed description about the plugin. Like what is does. What changes does it make to the site etc.
Version: 1.0 (Just a version number for your plugin)
Author: Saumya Majumder (Author's Name, i.e. your name)
Author URI: https://www.isaumya.com/ (This is supposed to link to the author's official page, but you can put any link here)
*/
@isaumya
isaumya / .htaccess
Created October 10, 2016 11:36
Disable directory based file listing in Apache servers where there is not a index file present
Options -Indexes
@isaumya
isaumya / .htaccess
Created October 10, 2016 11:27
Code for doing 301 HTTPS redirection for any site using .htaccess
<IfModule mod_headers.c>
RewriteEngine on
RewriteBase /
RewriteCond %{http_host} !^www.example.com$ [nc,OR]
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
</IfModule>
@isaumya
isaumya / wordpress-svg-support.php
Created September 26, 2016 20:13
Add SVG Support in WordPress Media Uploader
<?php
/*** enable svg support ***/
add_filter('upload_mimes', function( $mimes ) {
$mimes['svg'] = 'image/svg+xml';
$mimes['svgz'] = 'image/svg+xml';
return $mimes;
});
@isaumya
isaumya / show-image.php
Created September 26, 2016 20:08
Showing image in WordPress works for both SVG & non SVG image
<?php
/*** Function to show images whether SVG or non SVG ***/
/*** $size & $attribute both can hold array if you want ***/
function show_image( $image_id, $size = null, $attributes = null ) {
//first lets get the file info sto understand what kind of file it is
//as for svg file we will take different approach
$file_info = pathinfo( wp_get_attachment_url( $image_id ) );
//so, if the file type is SVG
if ( $file_info['extension'] === 'svg' ) {
@isaumya
isaumya / mySTPackageList.txt
Last active October 8, 2017 07:06
My Favorite Sublime Text Packages
## Terminal
https://github.com/wbond/sublime_terminal
https://packagecontrol.io/packages/Terminal
## Material Theme for Sublime Text
https://github.com/equinusocio/material-theme
https://packagecontrol.io/packages/Material%20Theme
## A File Icon
https://github.com/ihodev/a-file-icon