Posts by Luiz Felipe • 32,886 points
746 posts
-
1
votes1
answer2620
viewsQ: How to check if file exists (asynchronous)
In Node.JS, I use this method of fs to check if a file exists: const fs = require('fs'); // [...] if (fs.existsSync(path)) { /** Do stuff. */ } The question is, how can I do the same thing, but in a…
-
0
votes2
answers59
viewsQ: Create expressions in strings
Suppose I have the following string: const str = `Eu sou @if (1 + 1 === 2): um dois @endif !`; How do I execute expressions like that if? I don’t want a solution to exactly that problem, just the…
-
2
votes1
answer440
viewsQ: Relationship between Mongodb collections
I wonder if it is good practice to create a relationship between two collections (Collections) in Mongodb. Suppose I have a collection for users, with a scheme like this: { "_id": ObjectId(...),…
-
1
votes0
answers270
viewsQ: Best way to store images?
How best to store images? In a special directory, for example: public/images; In base64, on a data basis; Another way (which I did not quote earlier). And why? Note: I am using a Mongodb database.…
-
2
votes2
answers113
viewsA: Detect click on the same dynamic and non-dynamic item
The second parameter in the method .on jQuery, how you used it is just for this kind of problem. Create listeners event in dynamic elements. For example: $('.my-element').on('click', function() {…
-
2
votes2
answers405
viewsA: How to leave the footer with relative position and at least at the bottom of the page?
I also have this problem. The solution I use is to use flexbox, a new CSS3 feature. Basically, like this: * { box-sizing: border-box; margin: 0; padding: 0; } html, body { min-height: 100vh; } body…
-
1
votes1
answer193
viewsA: Selected in dynamic select
You can do it like this: <select> <?php $ano_atual = date("Y"); for ($i = 2014; $i <= $ano_atual; $i++) { $selected = (intval($ano_atual) === $i) ? 'selected' : ''; echo "<option…
phpanswered Luiz Felipe 32,886 -
10
votes1
answer1927
viewsQ: What and what are the types of development environment?
Occasionally I see something like this in several projects: env: 'production' What is this? What are the other conventional options (besides "Production") and what is it for? Why should I use this…
-
0
votes1
answer2759
viewsQ: How to close Node.js in the application?
How do I stop a Node.JS application? For example, in PHP, we have something like this: exit; Or: die('Mensagem.'); Is there any way to stop the Node.js application this way (or similar), without…
node.jsasked Luiz Felipe 32,886 -
1
votes1
answer65
viewsA: Can Expressjs be used in production?
Why wouldn’t it be? Express is a great tool for this, although there are more advanced options like Sails (which is made based on Express). If you are starting, use Express; there will be nothing…
-
3
votes1
answer70
viewsQ: How to protect myself against "Mongoinjection"
Use Mongodb in a front-end application that runs on Node.JS through the Express framework. I would like to know how to create protections against Mongodb "Injection" (similar to sql Injection).…
-
2
votes1
answer523
viewsQ: How to use other HTTP methods in HTML forms?
I’m using Express.JS to make a CRUD in Nodejs. I was trying to make use of the new HTTP methods, such as put , but when I put it in the attribute method of the apparently not certain form. The code…
-
0
votes1
answer92
viewsA: Use imported js file in html in an ES6 application
First, you should install jQuery via npm (or Yarn): npm install jquery There in the Javascript file, you do: import $ from 'jquery'; So your final file would look like this: import $ from 'jquery';…
-
1
votes1
answer620
viewsQ: Create button effect pressed
I have the following component in React: import React, { Component } from 'react'; class Counter extends Component { constructor(props) { super(props); this.state = { count:…
-
0
votes3
answers187
viewsA: Listing links from a page
You can trade for this: // Capturamos todos os links: const links = document.getElementsByTagName('a'); // Criamos a div que irá conter todos os links. const div = document.createElement('div');…
javascriptanswered Luiz Felipe 32,886 -
12
votes4
answers2933
viewsQ: Difference between operators && e ||
I’d like to know the difference between: window.RM = window.RM || {}; And: window.RM = window.RM && {}; Perhaps the examples are not correct, but I would like to know the difference between…
-
1
votes3
answers709
viewsA: Replace javascript Alert
If you use jQuery, you can create a script more or less like this (I just did it, but you can adjust it to your needs): (function ($) { 'use strict'; $(function () { $('form').each(function () { var…
-
1
votes3
answers372
viewsA: What are these two dots at the beginning of a CSS URL?
That’s called a way (path) relative! What have you done (url(../img/sobre-background.jpg)) will consider the image in the previous directory. Suppose you have the following directory structure: main…
-
0
votes1
answer37
viewsA: Event Listenter and Ajax
You can use jQuery to do this by using the method .on(), for example: /** Seu arquivo JavaScript separado. */ (function ($) { 'use strict'; $(function () { $('#ajax-button').on('click', function ()…
-
1
votes2
answers149
viewsA: PHP how to let select set
You can use the attribute selected, and make a ternary condition to print the selected. For example: <select name="veiculo"> <option <?php echo ($condicao === true) ? 'selected' : '';…
-
4
votes1
answer195
viewsQ: Difference between exporting a function and an IIFE in Javascript
Is there any difference between: module.exports = (function() { // Code. })(); And: module.exports = function() { // Code. }; Taking into account the context of exporting and importing modules?…
-
0
votes1
answer271
viewsQ: Instantiate dynamic named class in Javascript
There is a way to instantiate a Javascript class whose name is contained in a string type variable? For example: class User { constructor(...args) { console.log(args); } } const className = 'User';…
-
2
votes1
answer505
viewsQ: Pass variables on all renders
I have an application using Nodejs, Express (and a few more dependencies). I reduced the application to the file below to explain my question: app js.: // Dependências. const express =…
-
1
votes1
answer648
viewsA: Take a URL parameter with Jquery
Assuming the element you want to capture is always on final from the URL, you can do so: var url = 'http://localhost/admin-ativo.com/public/evento/edit4/id_menu/8/id_evento/22054'.split('/'); var…
jqueryanswered Luiz Felipe 32,886 -
2
votes1
answer581
viewsQ: Use require() (or other method) in Nodejs as in PHP
In PHP Suppose I have a constant file, in a root directory, called const.php: define('CONST_1', BASE_CONST_1 || 'Value 1'); define('CONST_2', 'Value 2'); define('CONST_3', 'Value 3'); And another…
-
2
votes2
answers176
viewsA: Repeat selected data in a select in a text input
You can do it like this (without jQuery): (function () { var sel = document.getElementById('destino_in'); var inp = document.getElementById('destino_out'); sel.addEventListener('change', function ()…
-
1
votes1
answer337
viewsA: Check database changes correctly
Really. Sending a request every millisecond is something wrong, even absurd to do in a real application. It is recommended, so that you use a new technology called Websockets. You can check more…
-
0
votes1
answer1772
viewsA: Uncaught Referenceerror when passing values via JS
In the HTML referred by you, which is the source of the error: <td><a href='#' onclick="setaDadosModal(aaaa, 107)" data-toggle="modal" data-target="#con-close-modal-altera"><i…
javascriptanswered Luiz Felipe 32,886 -
3
votes3
answers1047
viewsA: Apply effect when changing value of an input
You can do it like this: (function () { 'use strict'; var min = 10; // Usaremos este como um valor relativo para o efeito. var input = document.getElementById('my-range'); var p =…
-
1
votes1
answer372
viewsA: Create a select of cities, when choosing the city goes to the site specific to the chosen city
You can put the HTML like this: <form action="cid.php" method="get"> <select name="cidade" id="cidade"> <option>Selecione</option> <option value="city1">Cidade…
-
0
votes2
answers186
viewsA: Display items from a list in the Django html
Try trading the code for this: {% for item in saldo %} <div>{{item}}</div> {% endfor %} I’ve never dealt with Django, but I imagine that can solve.…
-
1
votes1
answer45
viewsQ: Equivalent of . test() (js) in php
In Javascript, we have the function test(), for example: /Test \[(\d+)\]/gi.test(string); // Pode retornar true ou false. php has some similar function?…
-
4
votes2
answers419
viewsA: Is it possible to instantiate a class without storing it in a variable?
You can do it like this: (new MyClass()); You can also run methods, for example: (new MyClass())->init(); And even use within functions, as in a echo: echo (new Auth())->getToken();…
-
3
votes1
answer105
viewsA: Separation of a php string
You can use the explode to transform the string into an array, thus: $turno = '15:00-19:00'; $turno_separado = explode('-', $turno); $hora_inicio = $turno_separado[0]; // 15:00 $hora_final =…
phpanswered Luiz Felipe 32,886 -
2
votes1
answer273
viewsA: How to perform an action when scroll reaches the top of the page?
You can do it like this: const execute = function () { console.log('Cheguei no topo!'); }; $(window).on('scroll', () => { if ($(this).scrollTop() === 0) execute(); });…
-
3
votes1
answer81
viewsQ: How to use more than two types in function parameters?
Suppose the following function in PHP: function parse (string $text, array $callback) { # ... } In theory the parameter $callback must be a array, but it can also be accepted as string. How do I get…
-
3
votes2
answers906
viewsQ: How to avoid user logout when closing your browser with PHP?
I currently use SESSION. When I close the browser, it disconnects. How can I make a way in login by clicking on continue connected, user not disconnect after close?
-
1
votes1
answer79
viewsA: Round up float value?
Use: ceil($number); If you use: ceil(3.6); The result will be 4.
phpanswered Luiz Felipe 32,886 -
1
votes1
answer1447
viewsQ: PHP with sockets
How do I use PHP with socket? Can be any type... I need to create notifications and a chat. I’ve tried many ways, but I can never. :/
-
2
votes2
answers204
viewsA: Recover jQuery date variables
Exchange the Javascript code for this: $('#abrir-imagem').on('show.bs.modal', function() { var pasta = $(this).attr('data-pasta'); var imagem = $(this)attr('data-imagem'); $("#imagem").html("<img…
jqueryanswered Luiz Felipe 32,886 -
1
votes1
answer334
viewsA: Ajax does not send the data to another php page
The problem is, through the dial: $('enviar_para_carrinho') You are selecting all the elements that have the tag <enviar_para_carrinho>. So, since there probably aren’t any of these elements,…
-
4
votes1
answer222
viewsQ: htaccess that hides only directories
I created a directory assets in order to place the Assets of my project. So far so good, however, I found that when typing in the URL localhost/project/assets, it shows the directory structure of…
-
1
votes1
answer146
viewsQ: Scroll over an object and its properties
Supposing I had this piece code: let obj = { lang: { hi: 'Olá, mundo!' }, engine: { functions: { init: function () { return this.lang.hi; } } } }; console.log(obj.engine.functions.init()); How I do…
-
2
votes1
answer100
viewsA: jQuery - Id() and show() does not run correctly
Try to change the code trigger of the function by: $j('input[name=isgift]').on('click', function () { if ($j('#isgift1').is(':checked')) { $j('.numberOriginal').hide();…
-
0
votes1
answer177
viewsQ: How to loop, capturing the keys and values of an object
I would like to loop an object in order to capture the key and the corresponding value. For example: const obj = { 'Chave 1': 'Valor 1', 'Chave 2': 'Valor 2', 'Chave N': 'Valor N' }; I’d like to…
-
2
votes1
answer49
viewsA: Count fields as they are included with Jquery
Exchange Javascript for this: /*globals jQuery*/ (function($) { $(".adicionarCampo").on('click', function() { var novoCampo = $("tr.linhas:first").clone();…
jqueryanswered Luiz Felipe 32,886