Skip to content

Instantly share code, notes, and snippets.

View m-muhsin's full-sized avatar
🎯
Focusing on React and WordPress

Muhammad Muhsin m-muhsin

🎯
Focusing on React and WordPress
View GitHub Profile
@m-muhsin
m-muhsin / stopwatch-script.js
Created February 22, 2024 15:56
Script for the mini stopwatch app using the WordPress block editor
// Stopwatch class
class Stopwatch {
constructor(displayCallback) {
this.startTime = null;
this.elapsedTime = 0;
this.timerInterval = null;
this.displayCallback = displayCallback; // Function to update the display
}
// Starts or resumes the stopwatch from 0
@m-muhsin
m-muhsin / stopwatch-markup.html
Last active February 22, 2024 16:02
Markup for the mini stopwatch app using the WordPress block editor
<!-- wp:group {"className":"stopwatch","layout":{"type":"constrained","contentSize":"400px"}} -->
<div class="wp-block-group stopwatch"><!-- wp:group {"style":{"spacing":{"padding":{"top":"var:preset|spacing|30","bottom":"var:preset|spacing|30","left":"var:preset|spacing|30","right":"var:preset|spacing|30"}},"border":{"radius":"15px"}},"backgroundColor":"accent-5","layout":{"type":"constrained","contentSize":"400px"}} -->
<div class="wp-block-group has-accent-5-background-color has-background" style="border-radius:15px;padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--30);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--30)"><!-- wp:group {"layout":{"type":"flex","orientation":"vertical","justifyContent":"center"}} -->
<div class="wp-block-group"><!-- wp:outermost/icon-block {"iconName":"wordpress-swatch"} -->
<div class="wp-block-outermost-icon-block"><div class="icon-container" style="width:48px"><svg xmlns="http://www.w3.org/2000/svg" v
@m-muhsin
m-muhsin / woocommerce-add-multiple-products-to-cart.js
Last active August 10, 2022 06:57
Add Multiple Products to Cart using Promises.
const productsToAdd = [
{ 'add-to-cart': 68, 'quantity': 2 },
{ 'add-to-cart': 69, 'quantity': 3 },
{ 'add-to-cart': 70, 'quantity': 4 }
];
for (const product of productsToAdd) {
try {
const response = await fetch(window.location.pathname, {
method: 'POST',
{
resolve: `gatsby-source-wordpress-experimental`,
options: {
url:
process.env.WPGRAPHQL_URL ||
`https://dev-gatsby-source-wordpress-v4.pantheonsite.io/graphql`,
verbose: true,
schema: {
queryDepth: 5,
typePrefix: `Wp`,
<template>
<div class="container">
<h1>{{ msg }}</h1>
<div class="calculator">
<div class="display">
{{ display }}
</div>
<div class="buttons">
<div class="one">
<button class="delete" @click="del()">DEL</button>
@m-muhsin
m-muhsin / index.html
Last active November 1, 2016 13:45
A meat JS Promises example
<!DOCTYPE html>
<html>
<head>
<title>JS Promises</title>
<meta charset="UTF-8">
</head>
<body style="padding: 20px;">
I want
<input type="text" name="count" id="count">
@m-muhsin
m-muhsin / AdjustRGB.ino
Created January 1, 2016 03:59
This sketch is a follow up to my last one 'AdjustBrightness'
/*
Adjust RGB - Choose exactly what colour you want!
This sketch is a follow up to my last one 'AdjustBrightness'
The code receives the analog sensor value of the potentiometer from analog pin 0,
maps it from a range of 0 - 511 and uses this value choose what colour to light up.
created 26 Dec 2015
by Muhammad Muhsin
@m-muhsin
m-muhsin / AdjustBrightness.ino
Last active December 26, 2015 08:01
Works like the light dimmer at you home!
/*
Adjust Brightness - Works just like the light dimmer at you home!
A little sketch I came up with after going through a couple of examples.
This code receives the analog sensor value of the potentiometer from analog pin 0
and uses this value to set the brightness of the output of pin 9.
Based on the following example projects:
Read Analog Voltage - https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
Fade - https://www.arduino.cc/en/Tutorial/Fade