Skip to content

Instantly share code, notes, and snippets.

@kheniparth
kheniparth / ExternalLinkAnchorReplacer.js
Created November 12, 2019 17:10
JavaScript - Find external link anchor tag and replace html content
var regex = /<a(.+?(?=href))href="((http|https):\/\/(?!www.techmuzz.com)[\w\.\/\-=?#]+)"(.*?)>(.*?)<\/a>/g;
var replaceAnchor = '<a$1href="$2"$4>$5 <img src="https://techmuzz.com/favicon.ico"></a>';
var htmlElement = jQuery('.entry-content');
var updatedHtml = htmlElement.html().replace(regex, replaceAnchor);
htmlElement.replaceWith(updatedHtml);
@kheniparth
kheniparth / policy.xml
Created July 21, 2019 01:17
Moviepy policy.xml file with commented line (<policy domain="path" rights="none" pattern="@*"/>) to avoid Permission errors while importing the module.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policymap [
<!ELEMENT policymap (policy)+>
<!ELEMENT policy (#PCDATA)>
<!ATTLIST policy domain (delegate|coder|filter|path|resource) #IMPLIED>
<!ATTLIST policy name CDATA #IMPLIED>
<!ATTLIST policy rights CDATA #IMPLIED>
<!ATTLIST policy pattern CDATA #IMPLIED>
<!ATTLIST policy value CDATA #IMPLIED>
]>
@kheniparth
kheniparth / andOpCond
Created January 27, 2018 21:38
AND operator with cond in Elixir
#Given an integer, , perform the following conditional actions:
#If is odd, print Weird
#If is even and in the inclusive range of to , print Not Weird
#If is even and in the inclusive range of to , print Weird
#If is even and greater than , print Not Weird
#Complete the stub code provided in your editor to print whether or not is weird.
defmodule Solution do
@kheniparth
kheniparth / wpWidgetRedirectToExcerptURL.php
Last active October 14, 2015 05:27
Redirect From WordPress Widget to URL in excerpt of the post.
<?php
$excerpt = get_the_excerpt();
$categories = get_the_category();
$cat = "";
$flag1=false;
$flag2=false;
if ( ! empty( $categories ) ) {
$cat=esc_html( $categories[0]->name );
echo "Category=".$cat."</br>";
if($cat == "News"){
@kheniparth
kheniparth / SocialButtonsWP
Created March 31, 2015 06:43
Add Beautiful Social Buttons To Your Website Without Plugins
<div style="position:relative; display:inline-block;">
<a href="http://www.facebook.com/techmuzz" style="text-decoration:none;" target="_blank"><img src="http://www.techmuzz.com/wp-content/uploads/2015/03/facebook-grey.png" onmouseover="this.src='http://www.techmuzz.com/wp-content/uploads/2015/03/facebook.png'" onmouseout="this.src='http://www.techmuzz.com/wp-content/uploads/2015/03/facebook-grey.png'" /> </a>
<a href="http://twitter.com/techmuzz" style="text-decoration:none;" target="_blank"><img src="http://www.techmuzz.com/wp-content/uploads/2015/01/twitter-grey.png" onmouseover="this.src='http://www.techmuzz.com/wp-content/uploads/2015/03/twitter1.png'" onmouseout="this.src='http://www.techmuzz.com/wp-content/uploads/2015/03/twitter-grey.png'"/> </a>
<a href="https://plus.google.com/105036750019432721144/posts" style="text-decoration:none;" target="_blank"><img src="http://www.techmuzz.com/wp-content/uploads/2015/03/gplus-grey.png" onmouseover="this.src='http://www.techmuzz.com/wp-content/uploads/2015/03/
@kheniparth
kheniparth / PublishPostWP.php
Last active August 29, 2015 14:18
PHP Function to publish a post in WordPress
function publishPost($title,$description,$category,$keywords,$encoding,$excerpt)
{
$content = array(
'title'=>$title,
'description'=>$description,
'mt_allow_comments'=>0, // 1 to allow comments
'mt_allow_pings'=>0, // 1 to allow trackbacks
@kheniparth
kheniparth / FixmsginPost.php
Created March 21, 2015 11:22
Add a fixed message into all WordPress posts.
function TM_add_to_post_content($content) {
if (is_single()) {
$content .= '<div style="text-align:right;width:700px;font-size:15px;clear:both;margin-bottom:10px;"><a style="text-decoration:none;color:#999;" title="Report an Error" href="http://www.techmuzz.com/report-an-error/">Report an Error</a></div>';
}
return $content;
}
add_filter ('the_content', 'TM_add_to_post_content', 0);
@kheniparth
kheniparth / battery_status.js
Created February 16, 2015 14:29
Get battery status of your website visitors
<script>
if (navigator.getBattery) {
navigator.getBattery().then(function(battery) {
display(battery);
});
} else if (navigator.battery) {
display(navigator.battery);
} else {
console.log("Sorry, Battery Status API is not supported");
@kheniparth
kheniparth / embedflipboard.js
Created November 27, 2014 19:17
Script to embed flipboard magazine on any webpage.
<script>
(function () {
var width = 0,
flipboard = document.getElementById('flipboard');
width = flipboard.getBoundingClientRect().width ? flipboard.getBoundingClientRect().width : flipboard.offsetWidth;
if (width > 800) {
flipboard.innerHTML = '<iframe width="100%" frameborder="0" height="600px" marginheight="0" marginwidth="0" scrolling="no" src="https://flipboard.com/section/the-internet-of-things-bn8l9H"></iframe>'
}
})();
</script>
<?php
//* Do NOT include the opening php tag
//* Enqueue scripts and styles
add_action( 'wp_enqueue_scripts', 'custom_scripts_styles_mobile_responsive' );
function custom_scripts_styles_mobile_responsive() {
wp_enqueue_script( 'beautiful-responsive-menu', get_bloginfo( 'stylesheet_directory' ) . '/js/responsive-menu.js', array( 'jquery' ), '1.0.0' );
wp_enqueue_style( 'dashicons' );