Today I start to set up the next js. Also, for the CSS framework, I will use Tailwind CSS. For the need for UI framework, I will use https://daisyui.com/. Let’s begin the game,
Continue reading “Headless WordPress with Next.js – day 2”Author: Mrinal
Headless WordPress with Next.js – day 1
WordPress without Head is the latest trend. This workflow is better in several ways. There are plenty of resources about the pros of the Headless WordPress approach. This is just one: Why WordPress Users Should Consider Headless
Continue reading “Headless WordPress with Next.js – day 1”How to import meta for WooCommerce multiple products
In some situations, you have to import some meta for hundreds of products. Then, manually it can do by
1. Open a product.
2. Update the meta.
3. Update the product.
If there are hundreds of products, we have to repeat this process a hundred times. Which is really complex to maintain.
There are plugins for import custom meta for existing products. But, they are costly.
There is a way that will save repeating work and save cost. Here it is:
Continue reading “How to import meta for WooCommerce multiple products”About strictly increasing sequence
Problem:
You are given an array of integers. On each move you are allowed to increase exactly one of its element by one. Find the minimal number of moves required to obtain a strictly increasing sequence from the input.
Solution:
function arrayChange($inputArray) { $count = 0; foreach ( $inputArray as $key => $value ) { $is_less = isset( $key ) && isset( $inputArray[ $key-1 ] ) && $value <= $inputArray[ $key-1 ]; if ( $is_less ) { $inputArray[ $key ] = ( $inputArray[ $key - 1 ] ) + 1; $count += $inputArray[ $key-1 ]- $value + 1; } } return $count; }
Calculator in PHP
To develop a simple calculator class in the context of PHP is more fun with __call()
magic method.
class Calculator { public function __call($method, $args) { if (isset($this->$method)) { $func = $this->$method; return call_user_func_array($func, $args); } } } $calculator = new Calculator(); $calculator->add = function ( $a1, $a2 ) { echo $a1 + $a2; }; $calculator->subs = function( $a1, $a2 ) { echo $a1 - $a2; }; $calculator->multi = function( $a1, $a2 ) { echo $a1 * $a2; }; $calculator->div = function( $a1, $a2 ) { echo $a1 / $a2; };
Is two arrays are similar?
Problem:
Two arrays are called similar if one can be obtained from another by swapping at most one pair of elements in one of the arrays.
Given two arrays a
and b
, check whether they are similar.
Example
- For
a = [1, 2, 3]
andb = [1, 2, 3]
, the output should beareSimilar(a, b) = true
.The arrays are equal, no need to swap any elements. - For
a = [1, 2, 3]
andb = [2, 1, 3]
, the output should beareSimilar(a, b) = true
.We can obtainb
froma
by swapping2
and1
inb
. - For
a = [1, 2, 2]
andb = [2, 1, 1]
, the output should beareSimilar(a, b) = false
.Any swap of any two elements either ina
or inb
won’t makea
andb
equal.
Solution:
function areSimilar($a, $b) { $array_difference = array_diff_assoc($a, $b); if( empty( $array_difference )) return true; if( count($array_difference) === 2) { $b_a_array_difference = array_diff_assoc($b, $a); $is_equal = array_diff($array_difference, $b_a_array_difference); if(!empty($is_equal)) { return false; } return true; } return false; }
Counting Vowels
In JavaScript:
let str = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum"; const vowels = /[aeiouy]/g; let vowelCount = str.match(vowels).length; console.log(`Total Vowel ${vowelCount}`);
Output: Total Vowel 174
In PHP
$str = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.'; $vowels = "/[aeiouy]/"; echo $vowel_count = preg_match_all( $vowels, $str );
Output: 174
How to add serial
Problem: How to add numbers between 1 to 100?
This obey arithmetic sequence. Mathematical formula wise this is 100*(1+100)/2=1050. Here is details.
Let see how to implement this in PHP.
function sum( $n, $a1, $a2 ) { return $n * ( $a1 + $a2 ) / 2; } echo 'Total=' . sum( 100, 1, 100 );
WordPress install with Docker
Docker enables to separate your applications from your infrastructure so you can deliver software quickly.
This post aims to setup WordPress with Docker Compose. Why Docker Compose?
With Compose, you use a YAML file to configure your application’s services.
docker-compose.yaml or docker-compose.yml is file where services are defined. So, lets crack the nuts.
Continue reading “WordPress install with Docker”Custom WP-CLI command
To develop custom WP-CLI command in plugin is handy tool if want to run a task without go to admin panel and perform a bunch of clicks to do a task. WP-CLI can save time by just type one line of commands.
Continue reading “Custom WP-CLI command”