Draw on an Icosahedron faces with RenderText (three.js)

I was looking at a three.js example where the writer draws numbers on each of the faces of an icosahedron using a canvas and a Three.CanvasTexture:

https://hofk.de/main/discourse.threejs/2021/NumberedIcosahedron/NumberedIcosahedron.html

I wondered if it was possible to extend the example to have more complex drawings on each face, or even animations. I discovered the RenderTexture component in drei and the example shown there:

https://drei.docs.pmnd.rs/portals/render-texture

It shows how to use RenderTexture to draw a complex animation on the faces of a cube.

I am attempting to combine the two examples to use RenderTexture to draw on an Icosahedron. I imagine I need to use RenderTexture to create a similar 1024×64 texture, just like in the first example. Then adopt the same uv mapping. I imagine that will produce the same result as the first example, but with the power of whatever RenderTexture can render. I got to the following point:

import { Canvas } from '@react-three/fiber'
import {
  RenderTexture,
  OrbitControls,
  Text,
  OrthographicCamera
} from '@react-three/drei'
import { suspend } from 'suspend-react'

const inter = import('@pmndrs/assets/fonts/inter_regular.woff')

export default function App() {
  return (
    <Canvas camera={{ position: [5, 5, 5], fov: 25 }}>
      <ambientLight intensity={0.5} />
      <directionalLight position={[10, 10, 5]} />
      <Icosahedron />
      <OrbitControls />
    </Canvas>
  )
}

const numbers = [
  ...Array(20)
    .keys()
    .map((n) => n + 1)
]

const step = 1024 / 20
const start = step * 0.5

const uvs = new Float32Array(120)
for (let i = 0; i < 20; i++) {
  uvs[i * 6] = (0.067 + i) / 20
  uvs[i * 6 + 1] = 0.25
  uvs[i * 6 + 2] = (0.933 + i) / 20
  uvs[i * 6 + 3] = 0.25
  uvs[i * 6 + 4] = (0.5 + i) / 20
  uvs[i * 6 + 5] = 1
}

function Icosahedron() {
  return (
    <mesh>
      <icosahedronGeometry args={[1, 0]}>
        <bufferAttribute
          attach="attributes-uv"
          count={60}
          array={uvs}
          itemSize={2}
        />
      </icosahedronGeometry>
      <meshStandardMaterial>
        <RenderTexture attach="map" width={1024} height={64}>
          <OrthographicCamera
            makeDefault
            args={[0, 1024, 0, 64, 1, 10]}
            position={[0, 0, 5]}
          />
          <color attach="background" args={['#111']} />
          <ambientLight intensity={0.5} />
          <directionalLight position={[10, 10, 5]} />
          {numbers.map((n, i) => (
            <Text
              key={`text_${i}`}
              position={[start + step * i, 0, 0]}
              color="#FFF"
              anchorX="center"
              anchorY="middle"
              font={suspend(inter).default}
              fontSize={20}>
              {`${n}`}
            </Text>
          ))}
        </RenderTexture>
      </meshStandardMaterial>
    </mesh>
  )
}

However, the numbers draw are distorted and not in the correct positions. Am I approaching the problem in the correct way? Is RenderTexture even the right thing to use here? With the goal of drawing complex, animating faces on an icosahedron or similar shape.

How can you get the operator’s precedence as a value in Javascript?

I am creating a calculator and need to determine precedence. My algorithm involves checking if the current operator input is a greater precedence than the previous ones entered.

Is there a function that takes an operator and returns its precedence value?

My current code involves matching the operator

if ( (item == "*" || item = "/") 
  && (compare == "+" || compare == "-")
  ){
  greaterPrecedence = True;
}

I am getting this particular error that i can’t use it before initialization.Help me trouble shoot it [closed]

I just want that the application work according to my expectation.If you figure out any other flaws in my just mention it so i can improve it.

The entire webpage is too wide

My entire webpage is too wide, for context, im trying to make a webpage that has a form on one side, and an image on the other and it has to be under two divs.

I have tried my best so far to find a solution but I keep getting stumped.
I tried the flex thing, I have tried putting a parent div, but nothing seemed to work, until it did however after getting it to work, my form and div were too wide I have to scroll to the side to get it visible which Is something I do not want.

Dynamically update variable in Spreadsheet popup UI element from google Apps Script

I have a google Apps Script function containing a forEach loop having a variable rowIndex which is to be displayed and updated in the popup (in a SpreadSheet) as the loop runs, but it only shows the last rowIndex in popup. As of now, only the title is dynamic but content of html is only displayed only for last rowIndex.

Here is my html:

<!DOCTYPE html>
<html>

<head>
  <base target="_top">
</head>
<body>
  <p align="center">
    <?!=htmlVariable?> This is htmlVariable.
  </p>
  <p align="center"><button onclick="google.script.host.close()">Close</button></p>
  <script>
    function closer(){
        google.script.host.close();
      }
  </script>
</body>

</html>

Apps Script function:

function extractTestCases(ProgressUIInstance, _startTime) {

  const ui = SpreadsheetApp.getUi();

  // .....Some Code......

  let tempHtmlOutput = HtmlService.createTemplateFromFile('html_file');
  tempHtmlOutput.htmlVariable = "Starting. . ."
  const dialog = ui.showModelessDialog(tempHtmlOutput.evaluate(), "Extractingg Test Cases");
  
  // .....Some Code......

  // 6. Processing Each Row
  values.forEach((row, rowIndex) => {
    
    // .....Some Code......
    let dialogCount = 1;
    while ((match = regex.exec(testCaseText)) !== null) {
      
      // .....Some Code......

      let endTime = new Date();
      const elapsedSeconds = endTime - _startTime;

      Utilities.sleep(500);

      tempHtmlOutput.htmlVariable = rowIndex;
      ui.showModelessDialog(tempHtmlOutput.evaluate(), `EXTRACT - Row ${rowIndex + 1} - Dialog ${dialogCount}`);

      SpreadsheetApp.flush();
      Utilities.sleep(500);
      dialogCount++;
    }
    // .....Some Code......
  });

// .....Some Code......
}

Screencast for reference: Screencast

While loop not printing message on screen

I’m writing a simple loop to prompt a word from the user.
When user enters a word, we print “Hi” on the screen.
When I’m running this code, I’m getting prompted, but I don’t see “Hi” being printed.

let name = ""

while (name !== "Quit") {
  name = prompt("Enter a name")
  console.log("Hi " + name)
}

Accessing parent level prop using child prop – Javascript [closed]

Consider that i have the following structure

categories = [
  {
    id: 1,
    name: "Marketing",
    url_key: "marketing",
    parent_id: null,
    children: [
      {
        id: 2,
        name: "board",
        url_key: "board",
        parent_id: 1,
        children: [
          {
            id: 3,
            name: "photo",
            url_key: "phototext-boards",
            parent_id: 2,
            children: [
              {
                id: 4,
                name: "pforce",
                url_key: "force",
                parent_id: 3,
                children: [],
              },
            ],
          },
        ],
      },
    ],
  },
  {
    id: 148,
    name: "Office Stationery",
    url_key: "office-stationery",
    children: [
      {
        id: 149,
        name: "Envelopes",
        url_key: "envelopes",
        parent_id: 148,
        children: [
          {
            id: 150,
            name: "paper",
            url_key: "paper",
            parent_id: 149,
            children: [],
          },
        ],
      },
    ],
  },
];

How do i get the top most parent url_key from a chid level?

For example

  • If i have the key “pforce”, how do i get the parent url key as “marketing”
  • If i have the key “paper”, how do i get the parent url key as “office-stationary”

Any help would be appreciated.

What are the minimum skills one should know before applying in Google Summer of Code? I’m doing web development mostly in front-end [closed]

I want to participate in the upcomming Google Summer of Code. But I don’t have any idea how it works and how I can prepare myself for open source contribution. I know Javascript & React.js. I have some projects using it. Can I apply for Gsoc? I don’t know dbms and operating system yet.

I am expecting to get a clear idea about Google Summer of Code, how it works and how I can participate in it.

Word Add-in – How to Include Custom Properties in OOXML with Office.js API

I’m using the Office.js client API to add a custom property key to a Word document through context.document.properties.customProperties. However, when I export the document to OOXML format using context.document.body.getOoxml(), the custom properties are not present in the OOXML data.

Is there a way to include custom properties in the OOXML when reading it via Office.js? Or is there an alternative approach to access custom properties within the OOXML structure?

context.document.properties.customProperties.load();
context.document.properties.customProperties.add(property, value);
await context.sync();
        

var body = context.document.body;
var ooxml = body.getOoxml();

I also tried saving the document but nothing : context.document.save();

Thanks!

How to pass the component as a component prop in Qwik

In react we can pass the component as a component property. For example

Link to the codesandbox.

interface IButtonProps {
  icon?: React.ComponentType;
  children: React.ReactNode;
}

const Button = ({ icon: Icon, children }: IButtonProps) => (
  <button>
    {Icon && <Icon />}
    {children}
  </button>
);

const DotIcon = (props) => {
  return (
    <svg
      xmlns="http://www.w3.org/2000/svg"
      viewBox="0 0 24 24"
      fill="currentColor"
      width="24"
      height="24"
      {...props}
    >
      <circle cx="12" cy="12" r="5" />
    </svg>
  );
};

export default function App() {
  return <Button icon={DotIcon}>Example button</Button>;
}

I notice the PropFunction<(value: T) => void> trick for callbacks but how do I pass the component as a prop exactly?

Important! I am using the Qwik framework, not a react

sweetalert and form submit [duplicate]

I have a form and I want to trigger an alert (using sweetalert) on submit:

<form id="verbale" class="verbale" action="editor_conferma.php" method="post">
...
<input id="submit" type="submit" name="submit" value="go" class="swa-confirm">
</form>

<script>
$(document).on("click", ".swa-confirm", function (e) {
                e.preventDefault();
                var $myForm = $('.verbale');
                if (!$myForm[0].checkValidity()) {
                    $myForm[0].reportValidity()
                } else {
                    swal({
                        title: "Are you sure?",
                        text: "Did you check?",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonText: "Yes, Submit!",
                    }).then(function (result) {
                        $myForm.submit();
                    });
                }
            });
</script>

The sweetalert dialog appears but when I confirm, the form is not passed on and submit does not seem to work.

Any hints?

Rails 7 – ExecJS::RuntimeError: SyntaxError: Unexpected token: operator (=) – production assets:precompile error

Upgrading chart.js from version 2.9.4 to 4.4.4.
Locally(Machine is MAC OS), rails app is generating charts with upgraded version.

When deploying to AWS EC2, Jenkins build is failing with this error during assets pre-compilation step –

rails aborted!
ExecJS::RuntimeError: SyntaxError: Unexpected token: operator (=)
JS_Parse_Error.get ((execjs):3538:621)
(execjs):4077:53
(execjs):1:32
Object.<anonymous> ((execjs):1:50)
Module._compile (node:internal/modules/cjs/loader:1364:14)
Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
Module.load (node:internal/modules/cjs/loader:1203:32)
Module._load (node:internal/modules/cjs/loader:1019:12)

Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
node:internal/main/run_main_module:28:49

/usr/local/rvm/gems/ruby-3.1.0/gems/execjs-2.9.1/lib/execjs/external_runtime.rb:40:in `exec'
/usr/local/rvm/gems/ruby-3.1.0/gems/execjs-2.9.1/lib/execjs/external_runtime.rb:22:in `eval'
/usr/local/rvm/gems/ruby-3.1.0/gems/execjs-2.9.1/lib/execjs/external_runtime.rb:47:in `call'
/usr/local/rvm/gems/ruby-3.1.0/gems/uglifier-3.2.0/lib/uglifier.rb:195:in `run_uglifyjs'
/usr/local/rvm/gems/ruby-3.1.0/gems/uglifier-3.2.0/lib/uglifier.rb:157:in `compile'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/compressing.rb:84:in `block in js_compressor='
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:84:in `call_processor'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:65:in `call_processors'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:184:in `load_from_unloaded'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:59:in `block in load'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:339:in `fetch_asset_from_dependency_cache'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:43:in `load'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/cached_environment.rb:44:in `block in load'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:207:in `block in fetch_or_store'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:187:in `fetch'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:206:in `fetch_or_store'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/cached_environment.rb:44:in `load'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/bundle.rb:32:in `block in call'
/usr/local/rvm/gems/ruby-3.1.0/gems/set-1.1.0/lib/set.rb:501:in `each_key'
/usr/local/rvm/gems/ruby-3.1.0/gems/set-1.1.0/lib/set.rb:501:in `each'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/bundle.rb:31:in `call'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:84:in `call_processor'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:65:in `call_processors'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:184:in `load_from_unloaded'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:59:in `block in load'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:339:in `fetch_asset_from_dependency_cache'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:43:in `load'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/cached_environment.rb:44:in `block in load'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:207:in `block in fetch_or_store'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:187:in `fetch'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:206:in `fetch_or_store'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/cached_environment.rb:44:in `load'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/base.rb:81:in `find_asset'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/base.rb:88:in `find_all_linked_assets'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/manifest.rb:125:in `each'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/manifest.rb:125:in `to_a'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/manifest.rb:125:in `block (2 levels) in find'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:48:in `block in synchronize'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:48:in `synchronize'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:48:in `synchronize'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:22:in `execute'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promise.rb:564:in `block in realize'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:359:in `run_task'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:350:in `block (3 levels) in create_worker'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:341:in `loop'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:341:in `block (2 levels) in create_worker'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:340:in `catch'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:340:in `block in create_worker'
Tasks: TOP => assets:precompile

Also, when chart.js version is downgraded to 2.x then it’s working.

I tried couple of solutions :

  • Set Production ENV variable EXECJS_RUNTIME="Node"
  • Upgrading Node & Yarn version similar to local machine
  • js_compressor = Uglifier so codebase already have js_compressor = Uglifier.new(harmony: true, output: { ascii_only: false })
  • Uglier gem version upgrade to 4.2
  • Also checked for RubyRacer gem but have memory issue

It seems runtime dependency for Linux environment need to be tweaked.

Please guide.

How to shift line bar graph in chart.js

I am using chart.js to render a bar graph with a line graph overlay. Basically I’m showing revenue vs expenses with the line graph being the net income for the period. I’m showing last year as a second bar graph next to the this year bar graph and I’m having troubles setting the line graph to be ‘over’ a certain bar graph. It keeps centering in the ‘column’ (see picture). How do I move the position of the line graph to be like the yellow line in the picture?

enter image description here

Here’s my code for rendering the graphs:

new Chart(document.getElementById(_this.chartNetId), {
            type: 'bar',
            data: {
                datasets: [
                    {
                        label: 'Revenue',
                        data: oRev,
                        borderWidth: 1,
                        backgroundColor: oRev.map((data, index) => data.bgcolor), 
                        stack: '1',
                        order: 1,

                    },
                    {
                        label: 'Rev. Last Per',
                        data: oRevLastPer,
                        borderWidth: 1,
                        backgroundColor: oRevLastPer.map((data, index) => data.bgcolor), 
                        stack: 'previous',
                        order: 1,
                    },
                                          
                    {
                        label: 'Expense',
                        data: oExp,
                        borderWidth: 1,
                        backgroundColor: oExp.map((data, index) => data.bgcolor), 
                        stack: '1',
                        order: 1,
                    },
                    {
                        label: 'Exp. Last Per',
                        data: oExpLastPer,
                        borderWidth: 1,
                        backgroundColor: oExpLastPer.map((data, index) => data.bgcolor), 
                        stack: 'previous',
                        order: 1,
                    },
                    {
                        label: 'Net',
                        data: oNI,
                        borderWidth: 1,
                        type: 'line',
                        backgroundColor: 'black',
                        borderColor: niCol,
                        borderWidth: 3,
                        tension: .25, // how curved the line is
                        order: 0,
                        stack: 'current'
                    },
                                           
                ]
            },

});

How do I create photo grid with fixed height for each row?

I am currently struggling to create an image grid where each row has a set height and the image should use 100% of the width. All the images are 4:3 or 9:16. The thing I am trying to avoid is having any part of the photo overflow and be hidden. I am using next js 15.

An example of what I meant to describe can be seen on https://www.skylerknutzen.com/stills
enter image description here

I am using next js and this is my current code for the collage component and it’s css:

import Image from 'next/image';
import styles from '@/components/collage.module.css';

const images = [
  { src: '/images/vertical1.jpg', alt: 'Vertical Image 1', orientation: 'vertical' },
  { src: '/images/horizontal1.jpg', alt: 'Horizontal Image 1', orientation: 'horizontal' },
  { src: '/images/vertical2.jpg', alt: 'Vertical Image 2', orientation: 'vertical' },
  { src: '/images/horizontal2.jpg', alt: 'Horizontal Image 2', orientation: 'horizontal' },
  { src: '/images/horizontal2.jpg', alt: 'Horizontal Image 2', orientation: 'horizontal' },
  { src: '/images/vertical2.jpg', alt: 'Vertical Image 2', orientation: 'vertical' },
  { src: '/images/vertical2.jpg', alt: 'Vertical Image 2', orientation: 'vertical' },
];

const Collage: React.FC = () => {
  return (
    <div className={styles.collageGrid}>
      {images.map((image, index) => (
        <div
          key={index}
          className={`${styles.imageWrapper} ${image.orientation === 'vertical' ? styles.vertical : styles.horizontal}`}
        >
          <Image
            src={image.src}
            alt={image.alt}
            layout="responsive"
            width={1}
            height={1}
            className={styles.image}
          />
        </div>
      ))}
    </div>
  );
};

export default Collage;
.collageGrid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 50px; /* Adjust as needed for even spacing */
    padding: 50px;
  }
  
  .imageWrapper {
    position: relative;
    overflow: hidden;
    width: 100%;
  }
  
  .vertical {
    grid-row: span 2; /* Vertical images span two rows */
  }
  
  .horizontal {
    height: 100%; /* Horizontal images fit within a single row */
  }
  
  .image {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

enter image description here