Posts

php plugin dev

vite config export default defineConfig({   plugins: [react()],   build: {     rollupOptions: {       output: {         entryFileNames: `assets/[name].js`,         chunkFileNames: `assets/[name].js`,         assetFileNames: `assets/[name].[ext]`       }     }   } })  

WP query posts

 Find by title $args = array(             'post_per_page' => -1,             'post_type' => 'acf_webhook',             'title' => $post_type         );

Nextjs essencials

Server component query params props type type Props = {      params: {},     searchParams: { [key: string]: string | string[] | undefined }, }

PHP nested json into 1-D array

   $data = array();          flatit('',$source);          function flatit($name,$object){         global $data;         foreach($object as $key => $value){             if(is_array($value)){                 flatit($name."_".$key,$value);             }else{                  $name = $name."_".$key;                  echo $name;                  echo "\n";                  echo $value;                  echo "\n";                 $data[substr($name, 1)] = $value;             }        ...

JS random string for api key

Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);

Coinbase commerce api sample code and common errors in Node

The followings are some code relevant to the title. Create Charge A charge is something that the frontend needs to send users to the payment page. Just add the following code to your nodejs route: import CoinbaseCommerce from 'coinbase-commerce-node'; const Charge = CoinbaseCommerce.resources.Charge; CoinbaseCommerce.Client.init(process.env.COINBASE_API_KEY);  if (req.method === 'POST') {         try {             const { amount, currency, user_id,user_email} = req.body;             // create a charge             const chargeData = {                 name: 'Your Awesome Comany',                 description: 'Deposit to Your Awesome Comany',                 local_price: {                     amount,   ...

Useful powershell commands

List all environment variables ls env:\ Set environment variables $Env:NODE_ENV= "development"

MongoDB local machine connection error with nodjs (mongoose)

mongoose.connect("mongodb://localhost/test"); or mongoose.connect("mongodb://localhost:27017/test"); results in  MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 Solutions use MONGOURL="mongodb://127.0.0.1/test"

Access External CSS or JS on Local Machine Without Express for Node.js

Using any web development framework for any programming languages is fast. When creating a website with node, we can also use one of the web framework, Express.js. We can use middleware app.use to link CSS or JS files in the project directory.  Just out of curiosity, I want to find out how to do the same without using any framework. Here is a way how. Modules I use only the node's budilt-in modules, http and fs modules. Logic Use http module to create a server. Use fs. the file system, to read html, css, and js files. the local css or js file link will send request to the node server, so we need to use these request URLs to serve corresponding files to the client.  Example Code In this example, css and js files are located in the same folder as the htnl file. We create a variable reqUrl to send corresponding files. We use the if(data) to check if any data after reading files are not undefined, which happens when there ...

How to Complile TypeScript in Browser Via CDN

To complie and run TypeScript, one just need to add stand-alone Babel CDN in the HTML file. Example code <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> <script type="text/babel"> function call(name:string){ return "hi " + name + "."; }; console.log(call('John')); //hi John. </script>