Posts by Guilherme Lautert • 15,097 points
356 posts
-
1
votes3
answers496
viewsA: php function to invert data
Using REGEX, I think it makes everything simpler. function reverseDate($date, $hours = true){ $patternBR = '~(\d{2})/(\d{2})/(\d{2,4})( (\d{2}):(\d{2}):(\d{2}))?~'; $patternEUA =…
phpanswered Guilherme Lautert 15,097 -
4
votes2
answers9412
viewsA: Is it possible to make an INSERT INTO SELECT + other values outside of SELECT?
You can create the commands to be executed: SELECT 'INSERT INTO ACCESSO (user, hora, url) VALUES ('||U.nome||','||P.hora||','||P.url||');' FROM usuario U LEFT JOIN pagina P ON P.user_id = U.user_id…
sqlanswered Guilherme Lautert 15,097 -
18
votes3
answers881
viewsA: Is there a difference between reporting the size in the loop condition or outside it?
Yes, even though the difference may be small. The logic is simple, comparing a value will be faster than having to run a method to get the value. In case it is a property like commented by @Marco,…
-
4
votes4
answers541
viewsA: Concatenate 2 PHP variables into SQL statement
I used Extract to generate the variable test passo_X, but the applied logic would be for. $arrayPassos = array( 'passo_1' => 'teste1', 'passo_2' => 'teste2', 'passo_3' => 'teste3',…
-
1
votes1
answer38
viewsA: Google MAP - Exchanging comma per point using native JS
This operation is very simple, just use the replace and the toFixed. var num = '12,3'; console.log(parseFloat(num.replace(',', '.')).toFixed(3)); Explanation The replace makes substitutions, in this…
javascriptanswered Guilherme Lautert 15,097 -
8
votes4
answers187
viewsQ: How to not lose the "this" of the current object
I had already made one similar question, however this time I am with a problem a little more complex : ObjectTest1 = (function(){ var init = function(){ this.callback = null; } init.prototype = {…
javascriptasked Guilherme Lautert 15,097 -
1
votes2
answers724
viewsA: How to make links with sub-links
You can do it using the property :active of css. Example ul{ list-style:none; } ul a{ text-decoration:none; } li{ cursor:pointer; float:left; position:relative; width:150px; height:20px;…
htmlanswered Guilherme Lautert 15,097 -
5
votes3
answers960
viewsA: How to find a String from Regular Expressions
The problem with an open field for user input is that even though it looks obvie/default, you can’t trust its content. The ideal would be to update the system and create address tables: CREATE TABLE…
-
1
votes5
answers1065
viewsA: Remove duplicated names with regular expression
I don’t understand the language r, but as I have I explained here, you can do a simple search that finds the same duplicate sequence, and replace it with a. Pattern : ([a-z]+)\1 replace : $1 flag :…
-
4
votes2
answers535
viewsA: preg_match(...) for various text types
In a another question have a reply that can be of help. In your case it is a little vague, because you do not specify if the numerals can come before, then be in the middle, if it can be mixed.…
-
0
votes1
answer157
viewsA: Find comma in the parameters of a function using regex
For this your case you can use the following REGEX : [a-z]\((([a-z]+,?)*)\) See on REGEX101 Explanation The logic used was that a method would have the pattern LETTERS(PARAMETERS), understands that…
-
3
votes1
answer142
viewsA: Negation operator returns value that should be discarded
Your logic is almost certain, I say almost, because it lacks a small interpretation. In REGEX you should analyze that it can start/end wherever you want, unless you explicitly define how it should…
regexanswered Guilherme Lautert 15,097 -
5
votes3
answers112
viewsA: swap Z for S char between vowels in a string
Via Lookback preg_replace('~(?<=[a-zA-Z])Z(?=[a-zA-Z])~', 'S', $str); Explanation (?<=[a-zA-Z]) - will observe those who come before but not capture. Z - literal character that must be…
-
11
votes4
answers209
viewsA: How to capture textarea tag with new line?
The problem with this REGEX is that by default the . does not include the \n, this way would have to circumvent this lack, may be with denial [^...], that captures anything that is not in the group.…
regexanswered Guilherme Lautert 15,097 -
4
votes2
answers411
viewsA: Where in integer field[] Postgresql
Array In the documentation we have : To search for a value in an array, each value needs to be checked. This can be done manually if you know the size of the array. Example SELECT * FROM sal_emp…
-
4
votes3
answers481
viewsA: How to make preventDefault links at the angle?
Change the href="#" for href="javascript:void(0)".
-
2
votes3
answers15821
viewsA: REGEX - find expressions that DO NOT contain specific words
Taking into account that the sentences will be separated by \n, and that you don’t want to capture the ones that don’t have the words REV and LIB, note that then REVENDEDOR and LIBERADO would…
-
9
votes2
answers215
viewsQ: How is the reading of sentences with comma in Javascript?
Today I was testing minify my code and I was in doubt about the conversion Original Code Loader = (function(Configure){ var CurrentAction = null; var loaded = []; loader = function(){}…
-
0
votes1
answer353
viewsA: Regex - Regular Expression to get a text block
I don’t know Delphi but from what I understood from logic the region of variables starts with var and ends with some other reserved word like function or begin. Using this concept one can make an…
-
3
votes2
answers205
viewsA: Javascript function becomes "Undefined" in addeventlistener
The reason for this error is that when using addEventListener the this is changed to who shot the event or is the button. So the this who is in the role close is not what you expect Dialog, and yes…
javascriptanswered Guilherme Lautert 15,097 -
3
votes4
answers1025
viewsA: How to make a LOOP run according to the return of a Promise (promise)?
Similar to Reply from @Wallacemaxters, but in practice with the script you are using. function loopPromise(url, start, end, callSuccess, callError){ $http = new $http(url); // Gera a promise para a…
-
1
votes2
answers591
viewsA: Change background to an element via jquery
$(document).ready(function(){ // Espera para executar ate o dom ter sido renderizado $('.change_color').on('click', 'li', function(){ // Cria um evento de click para os li do elemento ul var color =…
-
3
votes3
answers154
viewsA: Doubt Normalizer + Regex
Analyzing the sentence [^\\p{ASCII}] She’s in a String which will be converted into REGEX, and \ in String is an escape character, which makes near literal, so after conversion the result will be…
-
3
votes3
answers18768
viewsA: Regular Expression - Numbers only, no space
Remove everything except numbers "teste 123456 teste".replace(/\D/g, ''); // 123456 "teste 12 345 6 teste".replace(/\D/g, ''); // 123456 Capture all that is number and space, but consider the…
regexanswered Guilherme Lautert 15,097 -
1
votes2
answers453
viewsA: Change the home page via htaccess
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ NomeDoArquivoAqui/$1 [L] In Nameanquivoaqui you put the name of the file you…
-
6
votes1
answer2505
viewsA: How to configure Postgres to accept date in PT-BR format?
Researching a little I found this answer. The steps are simple : Check your current datestyle "ISO, DMY" or "IOS, MDY". Now Depending on what you want in the postgres MDY or DMY ALTER DATABASE…
-
3
votes1
answer2505
viewsQ: How to configure Postgres to accept date in PT-BR format?
Situation Let’s say I have one form in which the user fills a field date, DD-MM-YYYY. Question How can I do the postgres accept this format normally? No need to do to_timestamp('14/06/2016',…
-
2
votes3
answers296
viewsA: Function that converts this string to a json
Everything is easier with REGEX. ([a-zA-Z_]\w*?)=(\d+|"[^"]*")( |$) Explanation ([a-zA-Z_]\w*?) Variable name part - Group 1 [a-zA-Z_] = will ensure that it starts with a letter or underline \w*? =…
-
3
votes1
answer1553
viewsQ: CSS - How to avoid multiple file conflicts?
Situation I have several files css, some of mine, some of libraries. Doubt What is the best way to block the css external to certain elements? Example Current Effect /***** CSS EXTERNO *****/ form…
cssasked Guilherme Lautert 15,097 -
2
votes1
answer220
viewsA: Why does the expression "$a->b->c->d->e->f->g->h->i->j =& $null;" return several objects within each other, and it doesn’t even exist?
First you have different things: In the first case you are assigning a reference to an object, in short that is what it is, a reference, no matter what has there, it just "bet". The second case is a…
-
2
votes4
answers2166
viewsA: How to know the number of lines a large file has in php?
As lover of REGEX I propose: $content = file_get_contents("file_name"); // LE TODO ARQUIVO $content = preg_replace('~[^\n]~', '', $content); // REMOVE TUDO QUE NÃO SEJA QUEBRA DE LINHA (\n)…
-
4
votes1
answer2735
viewsA: Calculate with select output
Turn into a subquery : SELECT (qtd_tipo_0 + qtd_tipo_1 + qtd_tipo_2) as qtdTotal, (total_tipo_0 + total_tipo_1 + total_tipo_2) as total, (total_tipo_0 + total_tipo_1 + total_tipo_2) / (qtd_tipo_0 +…
-
36
votes4
answers39339
viewsQ: How to apply readonly in a select?
I believe most of you here know the difference between readonly and disabled. Select Readonly The readonly does not apply properly to the select <select name="field" readonly="readonly">…
-
1
votes2
answers468
viewsA: Regular expression to replace src attribute contents of html <img> tag
From what I was seeing it will depend on library of REGEX that you are using Assuming you’re using the PCRE REGEX pattern : (<img.*src=")([^"]*)(".*>) replace : $1"URL ALTERAÇÃO"$3 See in…
-
2
votes1
answer117
viewsA: Why do they say that the use of global variables is bad practice?
As this covers several languages I will respond with a simple example in JS: i = null; function contador1(){ for(i = 0; i < 60; i++){ if((i%5) == 0){ contador2(); } } } function contador2(){…
-
2
votes4
answers8648
viewsA: Remove space and break string lines
You can resolve the issue of the excesses of line breaking and space with REGEX : Removing excesses pattern : (\s){2,} replace : $1 Will capture spacing characters repeat more than twice and replace…
-
2
votes2
answers663
viewsA: Create an animation on canvas over video
The problem of canvas is that she is like a painting canvas, what you painted will stay there, unless you yourself "erase" (paint over). The method you are using clearRect serves to clear an area, I…
-
2
votes2
answers1119
viewsA: Auto select a select option from an input
To perform this action you must have some kind of value link with the option of select function onEstadoChange(value){ var regex = new RegExp(value, 'i'); // CRIA UM REGEX QUE VAI IGNORAR…
-
3
votes3
answers878
viewsA: sort multidimensional array php
The logic to order this type of structure is to assemble a simple array that will be ordered, keeping the association keys. $dados = array( // DADOS TESTE 'dataTable' => array( 'lista' =>…
-
1
votes2
answers119
viewsA: I converted a two-dimensional array to an object in PHP. How to access the values?
As @rray said in their comment You can even define numeric properties on an object but you can’t access them this is the problem. Using the functionality of get_object_vars that is very clear:…
-
1
votes1
answer607
viewsA: To select a switch/case statement each click on the button
var c = 0 var result = document.getElementById('result'); function a() { result.innerHTML = ''; switch (c.toString()) { case "1": for (i = 1; i < 9; i++) { ler = String.fromCharCode(i + 64);…
-
1
votes1
answer270
viewsA: Regex with STD::REGEX in C++
What is going wrong? PHP, this dynamic language makes everything very simple, and even corrects errors that you might not even notice. Problem { and } in REGEX is a reserved Character, what PHP must…
-
57
votes3
answers1826
viewsQ: Why use getElementById if id is in the window?
Recently in my study I noticed an object that manipulated the DOM of the element that had the same name in its id. teste.style.border = '1px solid #CCC'; teste.style.width = '500px';…
-
4
votes4
answers1407
viewsA: How to make elements appear and disappear with Js
jQuery(document).ready(function(){ var toggle = function(){ jQuery('#event_toggle').children().hide(); // ESCONDE TODOS ELEMENTOS FILHOS var current = jQuery('#event_toggle').find('.current'); //…
-
1
votes1
answer50
viewsA: Htaccess does not correctly validate the redirect rule
The reason is that he is not falling into rule 2 but into rule 1. Look at ([a-zA-Z0-9-]{1,30}) this passage contemplates exactly nome-com-numero-2-3 To solve this problem you must change the order…
-
0
votes2
answers166
viewsA: How to edit this chart to work with more lines
First it would be interesting to try to understand the API you are using, just read the documentation. Solution To add a new column is quite simple just use the addColumn: data.addColumn('number',…
-
1
votes3
answers940
viewsA: Compare the same variable in PHP
A mode I use whenever a variable can assume several values is: $possibilidades = array( '[email protected]', '[email protected]', ); if(in_array($email, $possibilidades)){ // O valor assumir alguma…
-
1
votes1
answer776
viewsA: .htaccess - Special character friendly urls
Possible Solution RewriteRule ^usuario\/([a-z,0-9,A-Z,._@:=!\?-]+)?$ index.php?pg=usuarios&usuario=$1 Notes [] works as a capture by verification, "in the character I am testing 'I' I accept…
-
6
votes3
answers9575
viewsA: Allow only letters, numbers and hyphen
Code $pattern = '~^[[:alnum:]-]+$~u'; $str = 'teste-1'; vr((boolean) preg_match($pattern, $str)); // true $str = 'teste_2'; vr((boolean) preg_match($pattern, $str)); // false $str = 'maça';…
-
33
votes3
answers21328
viewsQ: Create HTML element with Javascript (appendchild vs innerHTML)
Recently I’m creating a lot of HTML dynamically. Example var table = document.createElement('table'); table.style = 'width:500px;border:1px solid #CCC;'; var tbody = document.createElement('tbody');…