How do I render the same data to multiple views?

I’m working on a blog and I have a form where I fill out a title and a body of content. When I hit submit the data is rendered and can be viewed in my article_list ejs form. What I’m trying to accomplish is getting that data and having it display on another page.

On my home page (index.ejs) I have a section called “Most Recent Article”. I need the data sent from article_list to also be sent to index so my home page can display my most recent article.

Article Schema

const ArticleSchema = new Schema({
  title: { type: String, required: true },
  content: { type: String, required: true },
});

Here is the function that takes the data from my form and renders it to that page.

exports.article_list = function (req, res, next) {
  Article.find({}, "title author")
    .sort({ title: 1 })
    .populate("author")
    .exec(function (err, list_articles) {
      if (err) {
        return next(err);
      }
      res.render("article_list", {
        title: "Article List",
        article_list: list_articles,
      });
    });
};

When I click submit and view the list of articles, everything works as intended.

index.ejs

<div class="main__content-recent">
  <h2 class="main__tabs-title">Most Recent Article</h2>
  <p class="main__article-p">
    <%= article_list.content[-1] %>   (Read More...)</span>
  </p>
</div>

Because I can only render to one ejs file, the article_list.content[-1] is showing as undefined. I’m wondering if there is any way to render the same data twice to multiple ejs files or if not, what I should do.

Can Anyone Help Me Understand the YATA Paper? [closed]

I’ve recently been reading the YATA paper, and there’s a part with some mathematical derivations that I don’t quite understand. I hope someone can explain to me how the formula (o1 ≤ o2 ∧ o2 ≤ o1) ∧ (o1 ≡ o2 ∨ (o1 <c o2 ∧ o2 <c o1)) is derived from o1 ≤ o2 ∧ o2 ≤ o1.
enter image description here

I hope someone can provide me with the complete detailed derivation process. Thank you!

Error when including Tailwind UI components in Next.js 13 application

I’m working on a personal Next.js 13 + TypeScript + Tailwind CSS project. For mocking up the app I am trying to use Tailwind UI components. However, I keep getting the following JSON parsing error in a nested dependency:

Console output on implementation

I made a new blank Next project with only this App Shell component used. to be sure it was not due to another custom file. The app shell code as a client component (“use client”):

"use client"

import { Fragment } from 'react'
import { Disclosure, Menu, Transition } from '@headlessui/react'
import { Bars3Icon, BellIcon, XMarkIcon } from '@heroicons/react/24/outline'

const user = {
  name: 'Tom Cook',
  email: '[email protected]',
  imageUrl:
    'https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80',
}
const navigation = [
  { name: 'Dashboard', href: '#', current: true },
  { name: 'Team', href: '#', current: false },
  { name: 'Projects', href: '#', current: false },
  { name: 'Calendar', href: '#', current: false },
  { name: 'Reports', href: '#', current: false },
]
const userNavigation = [
  { name: 'Your Profile', href: '#' },
  { name: 'Settings', href: '#' },
  { name: 'Sign out', href: '#' },
]

function classNames(...classes) {
  return classes.filter(Boolean).join(' ')
}

export default function AppShell() {
  return (
    <>
      {/*
        This example requires updating your template:

        ```
        <html class="h-full bg-gray-100">
        <body class="h-full">
        ```
      */}
      <div className="min-h-full">
        <Disclosure as="nav" className="bg-gray-800">
          {({ open }) => (
            <>
              <div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
                <div className="flex h-16 items-center justify-between">
                  <div className="flex items-center">
                    <div className="flex-shrink-0">
                      <img
                        className="h-8 w-8"
                        src="https://tailwindui.com/img/logos/mark.svg?color=indigo&shade=500"
                        alt="Your Company"
                      />
                    </div>
                    <div className="hidden md:block">
                      <div className="ml-10 flex items-baseline space-x-4">
                        {navigation.map((item) => (
                          <a
                            key={item.name}
                            href={item.href}
                            className={classNames(
                              item.current
                                ? 'bg-gray-900 text-white'
                                : 'text-gray-300 hover:bg-gray-700 hover:text-white',
                              'rounded-md px-3 py-2 text-sm font-medium'
                            )}
                            aria-current={item.current ? 'page' : undefined}
                          >
                            {item.name}
                          </a>
                        ))}
                      </div>
                    </div>
                  </div>
                  <div className="hidden md:block">
                    <div className="ml-4 flex items-center md:ml-6">
                      <button
                        type="button"
                        className="rounded-full bg-gray-800 p-1 text-gray-400 hover:text-white focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-800"
                      >
                        <span className="sr-only">View notifications</span>
                        <BellIcon className="h-6 w-6" aria-hidden="true" />
                      </button>

                      {/* Profile dropdown */}
                      <Menu as="div" className="relative ml-3">
                        <div>
                          <Menu.Button className="flex max-w-xs items-center rounded-full bg-gray-800 text-sm focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-800">
                            <span className="sr-only">Open user menu</span>
                            <img className="h-8 w-8 rounded-full" src={user.imageUrl} alt="" />
                          </Menu.Button>
                        </div>
                        <Transition
                          as={Fragment}
                          enter="transition ease-out duration-100"
                          enterFrom="transform opacity-0 scale-95"
                          enterTo="transform opacity-100 scale-100"
                          leave="transition ease-in duration-75"
                          leaveFrom="transform opacity-100 scale-100"
                          leaveTo="transform opacity-0 scale-95"
                        >
                          <Menu.Items className="absolute right-0 z-10 mt-2 w-48 origin-top-right rounded-md bg-white py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
                            {userNavigation.map((item) => (
                              <Menu.Item key={item.name}>
                                {({ active }) => (
                                  <a
                                    href={item.href}
                                    className={classNames(
                                      active ? 'bg-gray-100' : '',
                                      'block px-4 py-2 text-sm text-gray-700'
                                    )}
                                  >
                                    {item.name}
                                  </a>
                                )}
                              </Menu.Item>
                            ))}
                          </Menu.Items>
                        </Transition>
                      </Menu>
                    </div>
                  </div>
                  <div className="-mr-2 flex md:hidden">
                    {/* Mobile menu button */}
                    <Disclosure.Button className="inline-flex items-center justify-center rounded-md bg-gray-800 p-2 text-gray-400 hover:bg-gray-700 hover:text-white focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-800">
                      <span className="sr-only">Open main menu</span>
                      {open ? (
                        <XMarkIcon className="block h-6 w-6" aria-hidden="true" />
                      ) : (
                        <Bars3Icon className="block h-6 w-6" aria-hidden="true" />
                      )}
                    </Disclosure.Button>
                  </div>
                </div>
              </div>

              <Disclosure.Panel className="md:hidden">
                <div className="space-y-1 px-2 pb-3 pt-2 sm:px-3">
                  {navigation.map((item) => (
                    <Disclosure.Button
                      key={item.name}
                      as="a"
                      href={item.href}
                      className={classNames(
                        item.current ? 'bg-gray-900 text-white' : 'text-gray-300 hover:bg-gray-700 hover:text-white',
                        'block rounded-md px-3 py-2 text-base font-medium'
                      )}
                      aria-current={item.current ? 'page' : undefined}
                    >
                      {item.name}
                    </Disclosure.Button>
                  ))}
                </div>
                <div className="border-t border-gray-700 pb-3 pt-4">
                  <div className="flex items-center px-5">
                    <div className="flex-shrink-0">
                      <img className="h-10 w-10 rounded-full" src={user.imageUrl} alt="" />
                    </div>
                    <div className="ml-3">
                      <div className="text-base font-medium leading-none text-white">{user.name}</div>
                      <div className="text-sm font-medium leading-none text-gray-400">{user.email}</div>
                    </div>
                    <button
                      type="button"
                      className="ml-auto flex-shrink-0 rounded-full bg-gray-800 p-1 text-gray-400 hover:text-white focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-800"
                    >
                      <span className="sr-only">View notifications</span>
                      <BellIcon className="h-6 w-6" aria-hidden="true" />
                    </button>
                  </div>
                  <div className="mt-3 space-y-1 px-2">
                    {userNavigation.map((item) => (
                      <Disclosure.Button
                        key={item.name}
                        as="a"
                        href={item.href}
                        className="block rounded-md px-3 py-2 text-base font-medium text-gray-400 hover:bg-gray-700 hover:text-white"
                      >
                        {item.name}
                      </Disclosure.Button>
                    ))}
                  </div>
                </div>
              </Disclosure.Panel>
            </>
          )}
        </Disclosure>

        <header className="bg-white shadow">
          <div className="mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8">
            <h1 className="text-3xl font-bold tracking-tight text-gray-900">Dashboard</h1>
          </div>
        </header>
        <main>
          <div className="mx-auto max-w-7xl py-6 sm:px-6 lg:px-8">{/* Your content */}</div>
        </main>
      </div>
    </>
  )
}

And this is the root page.ts file:

import { Inter } from "next/font/google";
import AppShell from "./components/AppShell";

const inter = Inter({ subsets: ["latin"] });

export default function Home() {
  return (
    <main className="flex min-h-screen flex-col items-center justify-between p-24">
      <div className="z-10 w-full max-w-5xl items-center justify-between font-mono text-sm lg:flex">
        <AppShell></AppShell>
      </div>
    </main>
  );
}

I installed all the dependencies and followed the configuration setup. Does it have something to do with client vs server components?

Object.freeze() get both worlds

const AnimeState = Object.freeze({
    Idle = 1,
    Walking=2,
    Running=3,
    Attacking = 4,
    Dead = 0,
    Uninitialized: -1
});

this.state = AnimeState.Uninitialized

Trying to get the name of the state, console.log(AnimeState[this.state]) — this doesn’t work however, maybe because of me using the Object.freeze() method here. Is there a way to get both worlds?

Desire:
console.log(AnimeState[this.state]) if state === AnimeState.Uninitialized, give me Uninitialized as string.

I followed this link: How to get names of enum entries? and there, they pointed:

enum colors { red, green, blue };

Will be converted essentially to this:

var colors = { red: 0, green: 1, blue: 2,
               [0]: "red", [1]: "green", [2]: "blue" }

Because of this, the following will be true:

colors.red === 0
colors[colors.red] === "red"
colors["red"] === 0

This creates a easy way to get the name of an enumerated as follows:

var color: colors = colors.red;
console.log("The color selected is " + colors[color]);

Sharp image processing without in-memory buffering using stream

I need to create a /api/lqip route to create base64 encoded image placeholders. Also, the question concerns normal image resizing.

I came across a technique for image processing without in-memory buffering using PassThrough (i.e. less server load) while exploring the remix image resizing example (https://github.com/remix-run/examples/blob/main/image-resize/app/routes/assets/resize/$.ts).

I’m not an expert in the backend, so I’m wondering should I use the sharp processing as regular or with stream.

sharp processing using PassThrough

regular sharp processing

How to output items in JSX from an array of items?

I have a small similar array of

const arr = [{ "0": "First Item", "1": "Second Item", "2": "Third Item"}]

And I want to output that in JSX.

This is what I have https://codesandbox.io/s/focused-bose-wgmbny?file=/src/App.js. As you can see, it only outputs the first element of the array.

I have tried using forEach and for loops to no avail. (And developers tell me you should use .map for JSX)

I also tried this:

arr.map((item, index) => (
    <p>{item[index]}</p>
))

I just want the map to output:

“First Item”
“Second Item”
“Third Item”

but it just stops at “First Item”

I cannot post api’s data locally

Im trying to make a simple APi web app and i cannot post the data into localhost!

I tried to find answers accros the web but i couldnt make it

const express = require("express");
const app = express();
const https = require("node:https");
const bodyParser = require("body-parser");

app.use(bodyParser.urlencoded({ extended: false }));


app.get("/", (req, res) => {
  res.sendFile(__dirname + "/index.html");
});

app.post("/", (req, res) => {
  const url = "https://favqs.com/api/qotd?856edacaf39b0dc9be175cb84bd3f072";
  
  https.get(url, (response) => {
    console.log("statusCode:", response.statusCode);

    response.on("data", (data) => {
      const quotesData = JSON.parse(data);
      //const author = quotesData.quote.author;
      const quotes = quotesData.quote.body;

      res.write(quotes);
      res.send();
    });
  });
});

app.listen(3000, () => {
  console.log("app listening on port 3000");
});

Firestore query Cursors Generating Dynamic Queries

In Firestore when i am writing the query and executing like this , it is working fine

_query =   query(collectionTestingRef  , 
where('name','==', 'him') , 
 limit(4));

But when i am taking the query in some variable and then using (required because i need to run a loop and add unknown where condition) , it is not working .

var _localWherequery = “where(‘name’,’==’, ‘him’)” ;
_query = query(collectionTestingRef ,
_localWherequery,
limit(4));

How can i achieve this dynamism , knowing that i dont know number of where clauses and i want to use query cursors only in firestore .

React native ios build failed showing multiple instances of the same simulator and same UDID, “com.apple.compilers.llvm.clang.1_0.compiler” flagged

`2023-04-10 12:54:39.743 xcodebuild[37229:209830] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
— xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:iOS Simulator, id:F74E3465-A58E-4B17-BF2B-1CB79F225F2F, OS:16.4, name:iPhone 14 }
{ platform:iOS Simulator, id:F74E3465-A58E-4B17-BF2B-1CB79F225F2F, OS:16.4, name:iPhone 14 }
** BUILD FAILED **

The following build commands failed:
CompileC /Users/devansh/Library/Developer/Xcode/DerivedData/RN_App-eibylxcwymbqneczxtsodzlvaqxg/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-Codegen.build/Objects-normal/arm64/FBReactNativeSpec-generated.o /Users/devansh/Desktop/rn-temp-engin2.0/ios/build/generated/ios/FBReactNativeSpec/FBReactNativeSpec-generated.mm normal arm64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler (in target ‘React-Codegen’ from project ‘Pods’)
(1 failure)`

When trying to build the ios project in a react native project, I am encountered with this error. I have uninstalled and reinstalled the XCode_14.3, followed the commands to clear the npm cache, deleted Pods, cleared Derived_Data of XCode and even deleted the devices which were highlighted, but this error is shown with every next device in the list shown by xcrun simctl list devices.

when I compare array and copy of array its showing Flase Why?

why copy of array and array showing flase when compare the even their type is same and values too

    const array1 = [1, 30, 4, 21, 100000, 99];
    console.log(typeof[...array1]);
    console.log(typeof(array1));
    console.log(array1);
     console.log([...array1]);
    console.log([...array1] === array1);
    console.log(array1 === array1);

OUTPUT

object

object

1, 30, 4, 21, 100000, 99

1, 30, 4, 21, 100000, 99

false

true

console.log([...array1] === array1);
This result Must Be True

How can i display meta data in the stripe

I used this metadata as array of object [{},{},{}]

const sessionData = {
      payment_method_types: ["card"],
      shipping_address_collection: {
        allowed_countries: ["US", "CA", "KE"],
      },
      line_items: [
        {
          price_data: {
            currency: "USD",
            product_data: {
              name: title,
              description: description,
              metadata: {
                endpoints: JSON.stringify(data),
              },
            },
            unit_amount: totalPrice.toFixed(0) * 100,
          },
          quantity: 1,
        },
      ],
      mode: "payment",
      customer: customer.id,
      success_url: `${getBaseClientUrl}/stripe/success`,
      cancel_url: `${getBaseClientUrl}/stripe/cancel`,
    };

    const session = await createCheckoutSession(sessionData);

but it render only title price and description on the checkout session on stripe ui , any one can help me over there ,
thank you in advance.

i want to return the metadata on the stripe checkout session ui

Use copyfiles with file path as attribute

I want to copy this color.ini file to this location %appdata%/spicetify/Themes/Nord-Spotify, so i put this in package.json and it works

"build-colors": "copyfiles --flat theme/color.ini %appdata%/spicetify/Themes/Nord-Spotify",

But i dont want to specify the folder instead want to specify the file path %appdata%/spicetify/Themes/Nord-Spotify/color.ini

facing issue to get xpath of the element present in Shadow DOM

enter image description here

I am using robot framework for automation and want to click on element print button(Please refer attach image for Html Code) on Shadow Dom. I have created variable using js path but it is not working. Can any one help to find exact xpath of the element

*** Variables ***

${chrome} chrome

${print} ${printIRCF1}

${JSPath}=  document.querySelector('print-preview-app').shadowRoot           
       ...  .querySelector('print-preview-sidebar')  
       ...  .querySelector('print-preview-button-strip').shadowRoot  
       ...  .querySelector('controls')  
       ...  .querySelector('action-button').shadowRoot

Can any one help me with the correct JsPath or with xpath so that I can use it in my code