Support
Quality
Security
License
Reuse
kandi has reviewed walle and discovered the below as its top functions. This is intended to give you an instant insight into walle implemented functionality, and help decide if they suit your requirements.
Android Signature V2 Scheme签名下的新一代渠道包打包神器
Gradle插件使用方式
buildscript {
dependencies {
classpath 'com.meituan.android.walle:plugin:1.1.7'
}
}
License
Copyright 2017 Meituan-Dianping
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
How can I target the inner html of each cell in a table row that I've clicked on?
const save = document.querySelectorAll(".save"); // select all the buttons
const rows = document.querySelectorAll("tr") // select all the rows
console.log(rows)
save.forEach((btn) => {
btn.addEventListener("click", (e) => {
let id = e.target.getAttribute('button-id') // get the clicked buttons id
console.log(id)
console.log(rows[id]) // with id select the row
});
})
<table class="table">
<tr>
<th>Trails</th>
<th>Province</th>
<th>Country</th>
</tr>
<tr>
<td class="tableRow">Lion's Head</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="1" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Pipe Track</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="2" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Skeleton Gorge</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="3" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Table Mountain</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="4" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">King Fisher Trail</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="5" button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Robberg Peninsula</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="6" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Diep Walle Forest Walk</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="7" class="save">Save</button></td>
</tr>
</table>
-----------------------
const save = document.querySelectorAll(".save"); // select all the buttons
const rows = document.querySelectorAll("tr") // select all the rows
console.log(rows)
save.forEach((btn) => {
btn.addEventListener("click", (e) => {
let id = e.target.getAttribute('button-id') // get the clicked buttons id
console.log(id)
console.log(rows[id]) // with id select the row
});
})
<table class="table">
<tr>
<th>Trails</th>
<th>Province</th>
<th>Country</th>
</tr>
<tr>
<td class="tableRow">Lion's Head</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="1" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Pipe Track</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="2" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Skeleton Gorge</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="3" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Table Mountain</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="4" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">King Fisher Trail</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="5" button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Robberg Peninsula</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="6" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Diep Walle Forest Walk</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button-id="7" class="save">Save</button></td>
</tr>
</table>
-----------------------
const table = document.getElementById('myTable');
table.addEventListener("click", (event) => {
if (event.target.matches('button.save')) {
const row = event.target.closest('tr');
console.log(row.innerText);
}
});
<table class="table" id="myTable">
<thead>
<tr>
<th>Trails</th>
<th>Province</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableRow">Lion's Head</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Pipe Track</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Skeleton Gorge</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Table Mountain</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">King Fisher Trail</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Robberg Peninsula</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Diep Walle Forest Walk</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
</tbody>
</table>
-----------------------
const table = document.getElementById('myTable');
table.addEventListener("click", (event) => {
if (event.target.matches('button.save')) {
const row = event.target.closest('tr');
console.log(row.innerText);
}
});
<table class="table" id="myTable">
<thead>
<tr>
<th>Trails</th>
<th>Province</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableRow">Lion's Head</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Pipe Track</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Skeleton Gorge</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Table Mountain</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">King Fisher Trail</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Robberg Peninsula</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Diep Walle Forest Walk</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
</tbody>
</table>
-----------------------
const save = document.querySelectorAll(".save");
save.forEach(s => {
s.addEventListener("click", (e) => {
const row = e.target.parentNode.parentNode;
row.classList.toggle('border');
console.log(row)
//
});
});
.border {
background: red;
}
<table class="table">
<tr>
<th>Trails</th>
<th>Province</th>
<th>Country</th>
</tr>
<tr>
<td class="tableRow">Lion's Head</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Pipe Track</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Skeleton Gorge</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Table Mountain</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">King Fisher Trail</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Robberg Peninsula</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Diep Walle Forest Walk</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
</table>
-----------------------
const save = document.querySelectorAll(".save");
save.forEach(s => {
s.addEventListener("click", (e) => {
const row = e.target.parentNode.parentNode;
row.classList.toggle('border');
console.log(row)
//
});
});
.border {
background: red;
}
<table class="table">
<tr>
<th>Trails</th>
<th>Province</th>
<th>Country</th>
</tr>
<tr>
<td class="tableRow">Lion's Head</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Pipe Track</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Skeleton Gorge</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Table Mountain</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">King Fisher Trail</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Robberg Peninsula</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Diep Walle Forest Walk</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
</table>
-----------------------
const save = document.querySelectorAll(".save");
save.forEach(s => {
s.addEventListener("click", (e) => {
const row = e.target.parentNode.parentNode;
row.classList.toggle('border');
console.log(row)
//
});
});
.border {
background: red;
}
<table class="table">
<tr>
<th>Trails</th>
<th>Province</th>
<th>Country</th>
</tr>
<tr>
<td class="tableRow">Lion's Head</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Pipe Track</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Skeleton Gorge</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Table Mountain</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">King Fisher Trail</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Robberg Peninsula</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Diep Walle Forest Walk</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button id="save" class="save">Save</button></td>
</tr>
</table>
How to paint a component on a JPanel?
src/
images/
happy.png
stackoverflow/
Main.java
package stackoverflow;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Main {
public static void main(String[] args) {
new Main();
}
public Main() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
JFrame frame = new JFrame();
frame.add(new TestPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
public class TestPane extends JPanel {
private BufferedImage image;
public TestPane() throws IOException {
image = ImageIO.read(getClass().getResource("/images/happy.png"));
}
@Override
public Dimension getPreferredSize() {
return image == null ? new Dimension(200, 200) : new Dimension(image.getWidth(), image.getHeight());
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (image == null) {
return;
}
Graphics2D g2d = (Graphics2D) g.create();
int x = (getWidth() - image.getWidth()) / 2;
int y = (getHeight() - image.getHeight()) / 2;
g2d.drawImage(image, x, y, this);
g2d.dispose();
}
}
}
-----------------------
src/
images/
happy.png
stackoverflow/
Main.java
package stackoverflow;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Main {
public static void main(String[] args) {
new Main();
}
public Main() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
JFrame frame = new JFrame();
frame.add(new TestPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
public class TestPane extends JPanel {
private BufferedImage image;
public TestPane() throws IOException {
image = ImageIO.read(getClass().getResource("/images/happy.png"));
}
@Override
public Dimension getPreferredSize() {
return image == null ? new Dimension(200, 200) : new Dimension(image.getWidth(), image.getHeight());
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (image == null) {
return;
}
Graphics2D g2d = (Graphics2D) g.create();
int x = (getWidth() - image.getWidth()) / 2;
int y = (getHeight() - image.getHeight()) / 2;
g2d.drawImage(image, x, y, this);
g2d.dispose();
}
}
}
Gstreamer Android HW accelerated H.264 encoding
rtspsrc location=rtsp://192.168.1.239:8554/test latency=300 ! application/x-rtp,encoding-name=H264 ! decodebin ! autovideosink
Loop through array contain objects and create different arrays from it
$array = [
(object)['length' => 4658, 'user_id' => 1922053, 'user_name' => 'Walled'],
(object)['length' => 5, 'user_id' => 1922053, 'user_name' => 'Walled'],
(object)['length' => 5555, 'user_id' => 19220, 'user_name' => 'Michael'],
(object)['length' => 2552, 'user_id' => 19220, 'user_name' => 'Michael']
];
$new = [];
foreach( $array as $a ) {
if ( ! array_key_exists($a->user_id, $new) ) {
$new[$a->user_id] = $a;
} else {
echo $new[$a->user_id]->length . PHP_EOL;
$new[$a->user_id]->length += $a->length;
}
}
print_r($new);
Array
(
[1922053] => stdClass Object
(
[length] => 4663
[user_id] => 1922053
[user_name] => Walled
)
[19220] => stdClass Object
(
[length] => 8107
[user_id] => 19220
[user_name] => Michael
)
)
-----------------------
$array = [
(object)['length' => 4658, 'user_id' => 1922053, 'user_name' => 'Walled'],
(object)['length' => 5, 'user_id' => 1922053, 'user_name' => 'Walled'],
(object)['length' => 5555, 'user_id' => 19220, 'user_name' => 'Michael'],
(object)['length' => 2552, 'user_id' => 19220, 'user_name' => 'Michael']
];
$new = [];
foreach( $array as $a ) {
if ( ! array_key_exists($a->user_id, $new) ) {
$new[$a->user_id] = $a;
} else {
echo $new[$a->user_id]->length . PHP_EOL;
$new[$a->user_id]->length += $a->length;
}
}
print_r($new);
Array
(
[1922053] => stdClass Object
(
[length] => 4663
[user_id] => 1922053
[user_name] => Walled
)
[19220] => stdClass Object
(
[length] => 8107
[user_id] => 19220
[user_name] => Michael
)
)
Bug in my recursive division algorithm (to generate maze randomly)
class Maze {
static Cell = class {
constructor(x, y, left, above) {
this.x = x;
this.y = y;
this.neighbors = [left ?? null, above ?? null, null, null];
// Also set link in opposite direction
if (left) left.neighbors[2] = this;
if (above) above.neighbors[3] = this;
}
block(direction) {
// Place a wall by clearing neighbor link
if (this.neighbors[direction]) this.neighbors[direction][direction ^ 2] = null;
this.neighbors[direction] = null;
}
}
constructor(parent, numCols, numRows) {
this.parentDiv = parent;
let above = [];
this.maze = Array.from({length: numRows}, (_, y) => {
let left = null;
return above = Array.from({length: numCols}, (_, x) => left = new Maze.Cell(x, y, left, above[x]));
});
this.recursiveDivision(0, 0, numCols, numRows);
}
recursiveDivision(left, top, right, bottom, its=0) {
const randInt = (min, max) => Math.floor(Math.random() * (max - min)) + min;
const width = right - left;
const height = bottom - top;
// Base case: cannot be divided further:
if (width < 2 || height < 2) return;
let choice = randInt(0, (width - 1) + (height - 1));
if (choice >= width - 1) { // Place horizontal wall
const y = top + choice - (width - 2);
const gap = randInt(left, right);
for (let x = left; x < right; x++) {
if (x != gap) this.maze[y][x].block(1);
}
this.recursiveDivision(left, top, right, y, its+1);
this.recursiveDivision(left, y, right, bottom, its+1);
} else { // Place vertical wall
const x = left + choice + 1;
const gap = randInt(top, bottom);
for (let y = top; y < bottom; y++) {
if (y != gap) this.maze[y][x].block(0);
}
this.recursiveDivision(left, top, x, bottom, its+1);
this.recursiveDivision(x, top, right, bottom, its+1);
}
}
display() {
this.parentDiv.innerHTML = "";
const container = document.createElement("div");
container.className = "maze";
for (const row of this.maze) {
const rowDiv = document.createElement("div");
for (const cell of row) {
const cellDiv = document.createElement("div");
cellDiv.className = ["left", "top", "right", "bottom"].filter((_, i) => !cell.neighbors[i]).join(" ");
rowDiv.appendChild(cellDiv);
}
container.appendChild(rowDiv);
}
this.parentDiv.appendChild(container);
}
}
const myMaze = new Maze(document.getElementById("maze-container"), 30, 10);
myMaze.display();
body, html { margin: 0 }
#maze-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.maze {
position: relative;
background-color: #a7c53f;
background-size: 8em 8em;
}
.maze div {
display: flex;
}
.maze div div {
box-sizing: border-box;
position: relative;
width: 1.2rem;
height: 1.2rem;
}
.left { border-left: 1px solid black }
.right { border-right: 1px solid black }
.top { border-top: 1px solid black }
.bottom { border-bottom: 1px solid black }
<div id="maze-container"></div>
-----------------------
class Maze {
static Cell = class {
constructor(x, y, left, above) {
this.x = x;
this.y = y;
this.neighbors = [left ?? null, above ?? null, null, null];
// Also set link in opposite direction
if (left) left.neighbors[2] = this;
if (above) above.neighbors[3] = this;
}
block(direction) {
// Place a wall by clearing neighbor link
if (this.neighbors[direction]) this.neighbors[direction][direction ^ 2] = null;
this.neighbors[direction] = null;
}
}
constructor(parent, numCols, numRows) {
this.parentDiv = parent;
let above = [];
this.maze = Array.from({length: numRows}, (_, y) => {
let left = null;
return above = Array.from({length: numCols}, (_, x) => left = new Maze.Cell(x, y, left, above[x]));
});
this.recursiveDivision(0, 0, numCols, numRows);
}
recursiveDivision(left, top, right, bottom, its=0) {
const randInt = (min, max) => Math.floor(Math.random() * (max - min)) + min;
const width = right - left;
const height = bottom - top;
// Base case: cannot be divided further:
if (width < 2 || height < 2) return;
let choice = randInt(0, (width - 1) + (height - 1));
if (choice >= width - 1) { // Place horizontal wall
const y = top + choice - (width - 2);
const gap = randInt(left, right);
for (let x = left; x < right; x++) {
if (x != gap) this.maze[y][x].block(1);
}
this.recursiveDivision(left, top, right, y, its+1);
this.recursiveDivision(left, y, right, bottom, its+1);
} else { // Place vertical wall
const x = left + choice + 1;
const gap = randInt(top, bottom);
for (let y = top; y < bottom; y++) {
if (y != gap) this.maze[y][x].block(0);
}
this.recursiveDivision(left, top, x, bottom, its+1);
this.recursiveDivision(x, top, right, bottom, its+1);
}
}
display() {
this.parentDiv.innerHTML = "";
const container = document.createElement("div");
container.className = "maze";
for (const row of this.maze) {
const rowDiv = document.createElement("div");
for (const cell of row) {
const cellDiv = document.createElement("div");
cellDiv.className = ["left", "top", "right", "bottom"].filter((_, i) => !cell.neighbors[i]).join(" ");
rowDiv.appendChild(cellDiv);
}
container.appendChild(rowDiv);
}
this.parentDiv.appendChild(container);
}
}
const myMaze = new Maze(document.getElementById("maze-container"), 30, 10);
myMaze.display();
body, html { margin: 0 }
#maze-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.maze {
position: relative;
background-color: #a7c53f;
background-size: 8em 8em;
}
.maze div {
display: flex;
}
.maze div div {
box-sizing: border-box;
position: relative;
width: 1.2rem;
height: 1.2rem;
}
.left { border-left: 1px solid black }
.right { border-right: 1px solid black }
.top { border-top: 1px solid black }
.bottom { border-bottom: 1px solid black }
<div id="maze-container"></div>
-----------------------
class Maze {
static Cell = class {
constructor(x, y, left, above) {
this.x = x;
this.y = y;
this.neighbors = [left ?? null, above ?? null, null, null];
// Also set link in opposite direction
if (left) left.neighbors[2] = this;
if (above) above.neighbors[3] = this;
}
block(direction) {
// Place a wall by clearing neighbor link
if (this.neighbors[direction]) this.neighbors[direction][direction ^ 2] = null;
this.neighbors[direction] = null;
}
}
constructor(parent, numCols, numRows) {
this.parentDiv = parent;
let above = [];
this.maze = Array.from({length: numRows}, (_, y) => {
let left = null;
return above = Array.from({length: numCols}, (_, x) => left = new Maze.Cell(x, y, left, above[x]));
});
this.recursiveDivision(0, 0, numCols, numRows);
}
recursiveDivision(left, top, right, bottom, its=0) {
const randInt = (min, max) => Math.floor(Math.random() * (max - min)) + min;
const width = right - left;
const height = bottom - top;
// Base case: cannot be divided further:
if (width < 2 || height < 2) return;
let choice = randInt(0, (width - 1) + (height - 1));
if (choice >= width - 1) { // Place horizontal wall
const y = top + choice - (width - 2);
const gap = randInt(left, right);
for (let x = left; x < right; x++) {
if (x != gap) this.maze[y][x].block(1);
}
this.recursiveDivision(left, top, right, y, its+1);
this.recursiveDivision(left, y, right, bottom, its+1);
} else { // Place vertical wall
const x = left + choice + 1;
const gap = randInt(top, bottom);
for (let y = top; y < bottom; y++) {
if (y != gap) this.maze[y][x].block(0);
}
this.recursiveDivision(left, top, x, bottom, its+1);
this.recursiveDivision(x, top, right, bottom, its+1);
}
}
display() {
this.parentDiv.innerHTML = "";
const container = document.createElement("div");
container.className = "maze";
for (const row of this.maze) {
const rowDiv = document.createElement("div");
for (const cell of row) {
const cellDiv = document.createElement("div");
cellDiv.className = ["left", "top", "right", "bottom"].filter((_, i) => !cell.neighbors[i]).join(" ");
rowDiv.appendChild(cellDiv);
}
container.appendChild(rowDiv);
}
this.parentDiv.appendChild(container);
}
}
const myMaze = new Maze(document.getElementById("maze-container"), 30, 10);
myMaze.display();
body, html { margin: 0 }
#maze-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.maze {
position: relative;
background-color: #a7c53f;
background-size: 8em 8em;
}
.maze div {
display: flex;
}
.maze div div {
box-sizing: border-box;
position: relative;
width: 1.2rem;
height: 1.2rem;
}
.left { border-left: 1px solid black }
.right { border-right: 1px solid black }
.top { border-top: 1px solid black }
.bottom { border-bottom: 1px solid black }
<div id="maze-container"></div>
How can i refactor these functions?
public enum WallPlacementResult{
Success,
NotOnTheSameLine,
TooLong
...
}
WallPlacementResult CheckWallRequirements(){
if (WallIsNotOnTheSameLine()) return WallPlacementResult.NotOnTheSameLine;
if (WallIsTooLong()) return WallPlacementResult.TooLong;
...
return WallPlacementResult.Success;
}
void SendAppropriateMessage(WallPlacementResult result)
{
switch(result){
case WallPlacementResult.NotOnTheSameLine:
_player.output?.DisplayWallHasPositionBeyondBoardMessage();
break;
case WallPlacementResult.TooLong:
...
}
}
Terraform filter based on map's minor key on lists of maps
variable "values_default" {
default = [
{A="abc", B="10"},
{A="cdea", B="111"},
]
}
# FOR CASE 3, but works for other cases as well
variable "new_config" {
default = []
}
locals {
# get keys avaiable in our vars
keys_default = [for v in var.values_default: v.A]
keys_new = [for v in var.new_config: v.A]
keys_all = distinct(concat(local.keys_default, local.keys_new))
# find common keys that need to be potentailly overwritten
# using min of B values
keys_common = setintersection(local.keys_default, local.keys_new)
# construct overwritten values, if there are any
# keys must be unique in both vars (no duplicates present)
overwritten_values = [ for idx, key in local.keys_common:
{
A = key
B = min([for v in var.values_default: v.B if v.A == key][0],
[for v in var.new_config: v.B if v.A == key][0])
}
]
keys_different = setsubtract(local.keys_all, local.keys_common)
new_values = [ for idx, key in local.keys_different:
{
A = key
B = concat([for v in var.values_default: v.B if v.A == key],
[for v in var.new_config: v.B if v.A == key])
}
]
}
output "test" {
value = concat(local.overwritten_values, local.new_values)
}
test = [
{
"A" = "abc"
"B" = [
"10",
]
},
{
"A" = "cdea"
"B" = [
"111",
]
},
]
-----------------------
variable "values_default" {
default = [
{A="abc", B="10"},
{A="cdea", B="111"},
]
}
# FOR CASE 3, but works for other cases as well
variable "new_config" {
default = []
}
locals {
# get keys avaiable in our vars
keys_default = [for v in var.values_default: v.A]
keys_new = [for v in var.new_config: v.A]
keys_all = distinct(concat(local.keys_default, local.keys_new))
# find common keys that need to be potentailly overwritten
# using min of B values
keys_common = setintersection(local.keys_default, local.keys_new)
# construct overwritten values, if there are any
# keys must be unique in both vars (no duplicates present)
overwritten_values = [ for idx, key in local.keys_common:
{
A = key
B = min([for v in var.values_default: v.B if v.A == key][0],
[for v in var.new_config: v.B if v.A == key][0])
}
]
keys_different = setsubtract(local.keys_all, local.keys_common)
new_values = [ for idx, key in local.keys_different:
{
A = key
B = concat([for v in var.values_default: v.B if v.A == key],
[for v in var.new_config: v.B if v.A == key])
}
]
}
output "test" {
value = concat(local.overwritten_values, local.new_values)
}
test = [
{
"A" = "abc"
"B" = [
"10",
]
},
{
"A" = "cdea"
"B" = [
"111",
]
},
]
How do I use rule in another rule in prolog
extends(A, C) :- rel1(A, C).
extends(A, C) :- rel1(A, B), extends(B, C).
?- extends(X, 'Human').
X = 'Hunter' ;
false.
?- extends(X, 'Machine').
X = 'Robot' ;
X = 'WallE' ;
false.
provides_action(X, L) :-
findall(Y, rel2(Y,X), L1),
findall(C, (member(A, L1), extends(C, A)), L2),
append(L1, L2, L).
?- provides_action('Run', L).
L = ['Human', 'Machine', 'Hunter', 'Robot', 'WallE'].
-----------------------
extends(A, C) :- rel1(A, C).
extends(A, C) :- rel1(A, B), extends(B, C).
?- extends(X, 'Human').
X = 'Hunter' ;
false.
?- extends(X, 'Machine').
X = 'Robot' ;
X = 'WallE' ;
false.
provides_action(X, L) :-
findall(Y, rel2(Y,X), L1),
findall(C, (member(A, L1), extends(C, A)), L2),
append(L1, L2, L).
?- provides_action('Run', L).
L = ['Human', 'Machine', 'Hunter', 'Robot', 'WallE'].
-----------------------
extends(A, C) :- rel1(A, C).
extends(A, C) :- rel1(A, B), extends(B, C).
?- extends(X, 'Human').
X = 'Hunter' ;
false.
?- extends(X, 'Machine').
X = 'Robot' ;
X = 'WallE' ;
false.
provides_action(X, L) :-
findall(Y, rel2(Y,X), L1),
findall(C, (member(A, L1), extends(C, A)), L2),
append(L1, L2, L).
?- provides_action('Run', L).
L = ['Human', 'Machine', 'Hunter', 'Robot', 'WallE'].
-----------------------
extends(A, C) :- rel1(A, C).
extends(A, C) :- rel1(A, B), extends(B, C).
?- extends(X, 'Human').
X = 'Hunter' ;
false.
?- extends(X, 'Machine').
X = 'Robot' ;
X = 'WallE' ;
false.
provides_action(X, L) :-
findall(Y, rel2(Y,X), L1),
findall(C, (member(A, L1), extends(C, A)), L2),
append(L1, L2, L).
?- provides_action('Run', L).
L = ['Human', 'Machine', 'Hunter', 'Robot', 'WallE'].
How to remove the arrows icons from a Material UI TextField
return (
<Autocomplete
style={{ width: 300 }}
options={top100Films}
freeSolo
getOptionLabel={(option) => option.title}
renderInput={(params) => (
<TextField
{...params}
variant="outlined"
margin="normal"
required
fullWidth
autoFocus
classes={{ notchedOutline: classes.input }}
// onChange={handlePhoneNumberChange}
placeholder="Search..."
type="search"
InputProps={{
...params.InputProps,
startAdornment: (
<InputAdornment position="start">
<SearchIcon />
</InputAdornment>
),
classes: { notchedOutline: classes.noBorder }
}}
/>
)}
renderOption={(option, { inputValue }) => {
const matches = match(option.title, inputValue);
const parts = parse(option.title, matches);
return (
<div>
{parts.map((part, index) => (
<span
key={index}
style={{ fontWeight: part.highlight ? 700 : 400 }}
>
{part.text}
</span>
))}
</div>
);
}}
/>
);
-----------------------
.MuiAutocomplete-popupIndicator {
display: none !important;
}
Material UI Autocomplete not working using modified TextField
renderInput={(params) => (
<TextField
{...params}
variant="outlined"
margin="normal"
required
fullWidth
// disableUnderline={false}
autoFocus
classes={{notchedOutline:classes.input}}
// onChange={handlePhoneNumberChange}
className={classes.textField}
placeholder="Search..."
InputProps={{
...params.InputProps, // this is new
startAdornment: (
<InputAdornment position="start">
<SearchIcon />
</InputAdornment>
),
classes:{notchedOutline:classes.noBorder}
}}
/>
// <TextField {...params} label="Highlights" variant="outlined" margin="normal" />
)}
QUESTION
Why do I receive this ReferenceError?
Asked 2022-Mar-25 at 11:34ReferenceError: array is not defined
I've been trying to add click event listeners to multiple buttons but when I run it in the console it gives me the referenceError above.
Below is my javascript code:
let buttons = document.querySelectorAll(".save");
console.log(array);
buttons.forEach((button) => {
button.addEventListener("click", () => {
alert("forEach worked");
});
});
I have looked at other questions on StackOverFlow for an answer, but they basically all say that I should put the tag at that the end of the html body so that the html can load before. I tried this and it doesn't work still.
Here is my html code for reference:
<body>
<div class="Container1">
<li class="dropdown">
<ul class="dropdown-menu dropdown-menu--animated">
</li>
<a class="dropdown-items" href="equiptment.html">Equiptment</a> <a class="dropdown-items" href="gallery.html">Gallery</a>
<a class="dropdown-items" href="trails.html">Trails</a><a class="dropdown-items" href="signup.html">Sign Up</a><a class="dropdown-items" href="saveForLater.html">Saved For Later</a><a class="dropdown-items" href="/index.html">Back to Menu</a>
</li>
</ul>
Hiking</li>
</div>
<div class="text-container">
</div>
<h1 class="trails-head">Trails</h1>
<h2 class="trails-h2">One of the things that makes hiking so exciting is endless options of trails you can take,each each is a very different experience. Hiking is also an incredible way to keep fit while discoering new places. Additionally it is a very social activity and is an amazing activity for friends, work colleagues or any other group.</h2>
<h3 class="trails-h3">Different Terrain</h3>
<h4 class="trails-h4">With different terrain comes a different experience. But it also comes with different preparations and equiptment. With a dry and rocky hike it is better to wear good hiking boots with decent grip. You could also bring a walking stick to help with stability in the more difficult patches of the hike. If you are planning hiking in a snowy and frozen climate it is of course better to wear hiking boots with ice grip or spikes. It is of course going to be colder and then it is smart to pack some warm but lightweight clothes.</h4>
<div class="tableDiv">
<h5 class="trails-h5">South African Hikes</h4>
<table class="table">
<tr>
<th>Trails</th>
<th>Province</th>
<th>Country</th>
</tr>
<tr>
<td class="tableRow">Lion's Head</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Pipe Track</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Skeleton Gorge</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Table Mountain</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">King Fisher Trail</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Robberg Peninsula</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
<tr>
<td class="tableRow">Diep Walle Forest Walk</td>
<td class="tableRow">Western Cape</td>
<td class="tableRow">South Africa<button class="save">Save</button></td>
</tr>
</table>
</div>
<!-- <input class="radio" type="submit">Radio</input> -->
<img class="trails-img" src="/norway.jpeg">
<img src="hiking7.jpg" class="hiking7" />
<p class="newsletter">Sign up to our news letters at the bottom of the this page</p>
<div class="radio-div">
<label>Age</label><br>
<input type="radio" id="under_13" name="user_age"><label><label for="under_13" class="light">Under 13</label><br>
<input type="radio" id="over_13" name="user_age"><label><label for="under_13" class="light">Over 13</label><br>
<label>Gender</label><br>
<input type="radio" id="under_13" name="user_gender"><label><label for="under_13" class="light">Male</label> <br>
<input type="radio" id="under_13" name="user_gender"><label><label for="under_13" class="light">Female</label> <br>
<label>Sign up to news letter</label> <br>
<input type="radio" id="under_13" name="newsletter"><label><label for="under_13" class="light">Yes</label> <br>
<input type="radio" id="under_13" name="newsletter"><label><label for="under_13" class="light">No</label> <br>
<label>Recieve emails of new trails and hikes</label> <br>
<input type="radio" id="under_13" name="recieve-emails"><label><label for="under_13" class="light">Yes</label> <br>
<input type="radio" id="under_13" name="recieve-emails"><label><label for="under_13" class="light">No</label> <br>
</div>
<script src="saveForLater.js"></script>
</body>
ANSWER
Answered 2022-Mar-25 at 11:34The problem is console.logging an array object, that doesn't exist. After deleting the line, ReferenceError shouldn't be a problem.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Save this library and start creating your kit