Skip to content

Instantly share code, notes, and snippets.

View HarishChaudhari's full-sized avatar

Harish Chaudhari HarishChaudhari

  • Bitwise Global
  • Pune
View GitHub Profile
@HarishChaudhari
HarishChaudhari / call-dom-manipulator.js
Created December 7, 2022 05:06
JavaScript DOM Manipulator
const manipulator = new DOMManipulator();
// Create a new div element with an ID of "myDiv", a class of "myClass", and some content
const myDiv = manipulator.createElement('div', 'myDiv', 'myClass', 'Hello, world!', {
'data-id': 123,
'data-name': 'John Doe'
});
// Modify the div element to update its class and content, and add a new attribute
manipulator.modifyElement(myDiv, null, 'myOtherClass', 'Hello, world! How are you?', {
@HarishChaudhari
HarishChaudhari / passwordRegex.js
Created August 1, 2016 13:29
Password validation RegEx for JavaScript
/**
* Password validation RegEx for JavaScript
*
* Passwords must be
* - At least 8 characters long, max length anything
* - Include at least 1 lowercase letter
* - 1 capital letter
* - 1 number
* - 1 special character => !@#$%^&*
*
@HarishChaudhari
HarishChaudhari / polishcalculator_test.php
Created June 24, 2015 14:15
Polish Calculator Unit tests
<?php
/**
* First, download phpunit.phar from www.phpunit.de
* Navigate to PHP bin folder and enter following command to execute tests:
*
* php.exe phpunit.phar --bootstrap c:\wamp\www\unit\src\polishcal\polishcalculator.php c:\wamp\www\unit\tests\polishcal_test\polishcalculator_test.php
*
*/
class polishcalculatorTest extends PHPunit_Framework_Testcase {
<?php
class polishcalculator {
/**
* Variables
*/
private $expected;
private $polishexprestion;
private $token;
@HarishChaudhari
HarishChaudhari / ctrl-key-detection.js
Created February 6, 2015 11:23
CTRL + key detection in JavaScript
/* This may not work with default browser shortcuts. Need to give it a try though. */
/* Create function */
$.ctrl = function(key, callback, args) {
$(document).keydown(function(e) {
if(!args) args=[]; // IE barks when args is null
if(e.keyCode == key.charCodeAt(0) && e.ctrlKey) {
callback.apply(this, args);
return false;
}
@HarishChaudhari
HarishChaudhari / cf7-custom-validation.php
Created November 5, 2014 08:08
Contact Form 7 custom validation
<?php
// Add custom validation for CF7 form fields
function custom_text_validation_filter($result,$tag){
$type = $tag['type'];
$name = $tag['name'];
$the_value = $_POST[$name];
if($name == 'firstname'){
if( empty($the_value) ) {
$result['valid'] = false;
/**
* Form Validation
*
* @since 11/04/2014
* @author Harish
*/
function enformValidation() {
var i = 0;
// Validate
@HarishChaudhari
HarishChaudhari / cpt-to-cpt.php
Last active March 20, 2017 14:46
code to transfer from CPT to CPT
<?php
function foo_duplicate_posts(){
# Only allow admins to run the script
if(!current_user_can('manage_options'))
return;
# Check if keyword is set
if(!isset($_GET['duplicate-posts']))
@HarishChaudhari
HarishChaudhari / cpt-to-cpt.php
Last active August 17, 2021 12:13
Copy posts from one Custom Post Type to another. (It doesn't handle post attachments for now)
<?php
add_action('admin_init', 'foo_duplicate_posts', 99999);
function foo_duplicate_posts(){
// Only allow admins to run the script
if(!current_user_can('manage_options'))
return;
// Check if keyword is set
if(!isset($_GET['duplicate-posts']))
@HarishChaudhari
HarishChaudhari / us-states-json-array.json
Last active November 2, 2023 09:38
US State names with ISO 3166-2 Codes in JSON array, can be useful while working with Google Maps
[
{"name":"Alabama","iso_code":"US-AL"},
{"name":"Alaska","iso_code":"US-AK"},
{"name":"Arizona","iso_code":"US-AZ"},
{"name":"Arkansas","iso_code":"US-AR"},
{"name":"California","iso_code":"US-CA"},
{"name":"Colorado","iso_code":"US-CO"},
{"name":"Connecticut","iso_code":"US-CT"},
{"name":"Delaware","iso_code":"US-DE"},
{"name":"District of Columbia","iso_code":"US-DC"},