Posts by Leandro Amorim • 1,865 points
59 posts
-
1
votes2
answers66
viewsA: Promise executed out of order, how to resolve?
The call then must receive a function (which can be anonymous) function wait(time) { return ( new Promise(resolve => setTimeout(resolve, time)) ) } wait(3000).then(() => console.log('wating…
-
0
votes3
answers127
viewsA: Cloning elements with Javascript
When working with dynamic object creation, we usually place the event in the form and then locate the descending objects within that form. $(document).ready(function(){…
-
3
votes5
answers7016
viewsA: How to delete all duplicates except one?
In Mysql 8.0 there is the possibility to use RANK() SELECT id, usuario_id, status FROM ( SELECT id, usuario_id, status, RANK() OVER (PARTITION BY usuario_id ORDER BY id DESC) AS intRow FROM Table1…
-
1
votes2
answers3297
viewsA: How to set data in localStorage
localStorage records only texts, so it is necessary to have the information in text format that can be obtained with the JSON.stringify if necessary. var test = ["Hello", "World", "Item 3", 5]; if…
-
1
votes3
answers1108
viewsA: Manipulating with Update Panel
You can do this processing via javascript the code below is an example of how to avoid a new postback (ajax) of the same "object" before the current one ends. Insert after the form runat="server"…
-
0
votes5
answers1021
viewsA: Pick first name with Regular Expression
Try to use this code: <?php preg_match('/[^\s]*/', 'Qualquer Nome', $matches); return $matches[0]; ?>
-
1
votes3
answers7147
viewsA: Stop executing a Javascript function to perform another function
You can use a callback for that next "for" only be executed at the end of drawLatLong. function drawLatLong(i, arrayIdColetor, callback) { ..... (não exibi o código por ser grande e achar…
-
5
votes2
answers531
viewsA: Organize columns in rows for equal ID in SQL server
Using the approach PIVOT and with an indefinite number (not limited to 5) of columns follows example: DECLARE @MaxCount INT, @a CHAR(10) = 'fornecedor', @f NVARCHAR(MAX), @b CHAR(11) =…
-
3
votes2
answers155
viewsA: How to notify people that they have been invited to install an APP
Having user code linked to phone number I would use the following strategy. 1. User headers have the application In this case the user is in your database, so would send the message (push) directly…
androidanswered Leandro Amorim 1,865 -
1
votes2
answers1264
viewsA: Send message to browser
You can use the onbeforeunload javascript, it presents this window that asks if the user really wants to leave the page. window.onbeforeunload = function(e){ e = e || window.event, msg = 'Você tem…
-
0
votes2
answers180
viewsA: Field sorting of Join with Line in Mysql (C#, MVC)
You can use Where with Max, but you don’t need to sort a list by date if there will be only one date on the list. query = query.Where( w => w.contato.data == query.Max( m => m.contato.data ) )…
-
1
votes1
answer742
viewsA: Improve the performance of a query
If I understand your SQL correctly, the Subquerys are not dependent on the main Query. This way you can use "pre defined" variables with the values of the Subquerys thus ensuring a single execution…
-
1
votes3
answers381
viewsA: Chrome [v44] - Bug in tables inside a div with overflow
I couldn’t emulate your mistake, so I can’t guarantee that this answer will help. Working with Viewport You must enter the meta tag viewport <head> of your document <meta name="viewport"…
-
2
votes1
answer85
viewsA: I would like that bar when scrolling the page
Using your example I did another, there is a lot that can be changed, but the basics are there. Is in the Jsfiddle You must use the $(window).on("scroll", function() { }); to be able to "catch" the…
-
4
votes1
answer1120
viewsA: How to identify the type of request sent to the server?
You can use $_SERVER['REQUEST_METHOD'] <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $nome = $_POST['nome']; $email = $_POST['email']; $senha = $_POST['senha']; if (!$nome) {echo 'Escreva seu…
-
1
votes2
answers675
viewsA: Fold transition effect with CSS
You can change the background-color of the effect to yellow combined with opacity of css3. .curl-top-left:before { /*alteração*/ background: linear-gradient(135deg, transparent 45%, #fc0 30%, #fc0…
-
2
votes2
answers2102
viewsA: Dynamically change the text color based on a background color
Using a very good library for color treatment called Chroma.js you can easily manipulate the background color of the gift and apply it in the color style of the text. Follows a function that returns…
-
1
votes2
answers158
viewsA: activating background overlay with link
To activate only on LINK will require a major change, this way to avoid having to redo all the code it is activating when you put on top of the <div class="over-text-feature"> containing the…
-
3
votes1
answer2559
viewsA: Read HTML file
You can use the Htmlagilitypack PM> Install-Package HtmlAgilityPack Follow a small example code HtmlDocument doc = new HtmlDocument(); doc.Load("arquivo.html") foreach (HtmlNode certidao in…
-
1
votes6
answers17792
viewsA: Accentuation problem while recovering records in SQL Server
You can use sqlsrv_connect in which the parameter exists CharacterSet UTF-8. $host="xxxxxx"; $user="xxxxx"; $database="xxxxx"; $pass="xxxxx"; $connArr = array( "Database" => $databae, "UID" =>…
-
1
votes1
answer311
viewsA: Send form without reloading page being from different domains
The problem must be on the server that is receiving the post. You must use Access-Control-Allow-Origin on the server that will receive the data. header('Access-Control-Allow-Origin:…
-
2
votes2
answers162
viewsA: Counter in M:S format, javascript
I did a little function that you can control time. (Jquery is not required for script operation, I only used to manipulate textbox and Buttons). var Clock = { minutosStop: 10, //pode "setar"o tempo…
-
1
votes1
answer32
viewsA: Problem with a field in Regex
What you are looking for is the parameter RegexOptions.Singleline, with this parameter the regular expression is interpreted as a single line. Regex.Matches(input, "(?!.*\");",…
-
2
votes2
answers320
viewsA: Installation of Namespace
That one Namespace can be installed using the NuGet in the way visual or using the console. For more information about this package visit website. To open the console you can use ALT + T N O (ALT +…
-
4
votes5
answers26385
viewsA: What is the best practice to know if an Row exists in a SELECT in Mysql?
The option LIMIT 1 makes SQL end when it finds the first record, is the fastest way to check if a record exists. SELECT 1 FROM tabela WHERE usuario = 'exemplo' LIMIT 1 ;…
-
2
votes3
answers442
viewsA: Date 01 day of the month returns as last
I did not find a reference for this bug, but apparently it is performing a subtraction, because the format passed is YYYY-MM-DD, concatenating with a string " " the date is converted correctly. You…
-
1
votes1
answer233
viewsA: My ajax form does not validate
Instead of putting the event on input type="submit" treat the submit form, so that the Html5 validations function correctly. $("form").submit(function(e) { e.preventDefault(); var _name =…
-
2
votes4
answers646
viewsA: Perform function by clicking except on specific item with jQuery
You can capture the event target, if it is a link vc returns true; $('.teste').on('click', function(e) { if($(e.target).is('a')) return true; alert('Click'); return false; }); .teste { height:…
-
4
votes2
answers209
viewsA: Create Fibonacci in a linear function with delegate
You can use two online functions, or only one more complex, one to calculate Fibonacci. //função 1 recursividade (usando duas funções em linha) Func<int, int> calcFib = null; calcFib = x =>…
c#answered Leandro Amorim 1,865 -
0
votes6
answers2762
viewsA: How to walk an Enum?
You can do using LINQ Func<string, int> Contador = x => x.Select(c => Char.ToLower(c) - 98).Where(c => c > 0 && c < 27).Sum(); Example in Dotnetfiddle…
-
2
votes2
answers1247
viewsA: How to implement a function to return the sum of squares in the proposed form?
You can also use a online function List<int> list = new List<int> {1,2,3,4,5}; Using the proposed list: Func<List<int>, int> Qd = null; Qd = x => (x.Count == 0) ? 0 :…
c#answered Leandro Amorim 1,865 -
6
votes8
answers2805
viewsA: How to know which is the last element on a list?
You can use the string.Join to do this. List<string> campos = new List<string>(); campos.Add("id"); campos.Add("descricao"); campos.Add("Titulo"); string sql = "INSERT INTO teste(" +…
-
2
votes2
answers4878
viewsA: Javascript function does not wait for another to start
You can also use Ajax synchronously. function buscando_dados(){ $.ajaxSetup({async: false}); $.post('ajax.php',{},function(dados){ alert(dados); }); $.ajaxSetup({async: true}); } function…
-
2
votes3
answers216
viewsA: CSS selector for tables
Let’s go in pieces, that code table, thead, tbody, th, td, tr { display: block; } is putting diplay block on all these elements: table thead tbody th td tr Using the pattern of W3 to have the…
-
5
votes5
answers844
viewsA: What is the shortest and most performative way to write Fibonnaci in Javascript?
Using simple recursiveness function fib1(n) { if (n < 2) return n; return fib1(n - 1) + fib1(n - 2); } Using array function fib2(n) { var i, f = [0, 1]; for (i = 2; i <= n; i++) f.push(f[i -…
-
0
votes4
answers3446
viewsA: Javascript function for zeros on the left with MVC 5
In javascript you can use slice provided you know number of characters nm = 'txtNome' + ("0"+i).slice(-2); // txtNome01 I made an example in jsfiddle One approach I would also take is:…
-
5
votes5
answers8743
viewsA: Center a form vertically
jsfiddle (fullscreen) you can make the following changes: Put the form inside a div with the class "area" <div class="area"></div> and use display as table. body, html { height:100%; }…
-
6
votes4
answers3455
viewsA: Is it possible to communicate Client-Server in real time via HTTP?
Push Technology (Ajax Push) 1. Using connection without "end" In this technique you can use Ajax leaving it perennial with the server, when receiving the information should treat it and show in the…
-
1
votes3
answers2277
viewsA: How to check if user has left the window
Some time ago I looked for a script that did just that. He adds listeners for various types of browsers. Calling the function functionHidden when the page loses its "focus". And functionVisible when…
javascriptanswered Leandro Amorim 1,865 -
2
votes3
answers7891
viewsA: How to create a click event that is only called when clicking outside a div?
You can add the event click in the document shooting all over the page. In a if within the click verify which the target of the clicked location, if the ID is equal to the one of the div return…
-
1
votes6
answers11947
viewsA: How to create a password reset link?
Option 1 (simple) Generate a random password write it to your database using your encryption script, and send the user this new random password. If there is an attempt to exchange password for…
-
6
votes5
answers2395
viewsA: Strategy to find out if your web application is being partially or fully censored by an ISP
How the "reliability" of files is validated today? Using MD5 and generating a hash code. An interesting way to validate whether there was content modification between the server and the client would…
-
3
votes4
answers6297
viewsA: Form inserting twice in the bank (F5)
One option is you redirect the user to another page other than the one you use to "save" the form, you can do this with header. header("Location: http://www.seusite.com.br/cadastroEfetuado.php");…
-
5
votes8
answers16873
viewsA: How to invert a string in Javascript?
A function to do the reverse of text including for UTF-16 Jsfiddle function Reverso(input) { var s = input, c = 1, r = '', l = '', h = /[\uD800-\uDFFF]/; var b =…
-
0
votes3
answers162
viewsA: Use . on() instead of . bind() in Cakephp’s Jshelper
No apparent reason not to work in IE look at the internal bind code in jquery bind: function( types, data, fn ) { return this.on( types, null, data, fn ); } Now the call of on on: function(types,…
-
4
votes3
answers331
viewsA: Unknown cause error: "Syntaxerror: invalid range in Character class"
Is a regular expression error. [a-Z]{2,35} não é vlálido Use [a-zA-Z]{2,35} Try to use <input type="text" required="" pattern="[a-zA-Z]{2,35}" tabindex="6" name="edtCidade" id="edtCidade">…
-
2
votes4
answers1804
viewsA: Should I check dates with Datetime or regex?
Regular expression is not very good to validate dates, since you do not only want to validate if there are numbers or strokes you also want to validate the date. The expression you put on…
-
3
votes1
answer489
viewsA: How to link models (with Association), Forms, and grids in Extjs 4?
You can mount a grid using renderer of columns. Ext.create('Ext.grid.Panel', { title: 'Usuários', store: store, columns: [{ text: 'Nome', dataIndex: 'nome' },{ text: 'Telefones', renderer: function…
-
1
votes3
answers955
viewsA: How to effectively remove the metatag refresh from a page?
I only see one approach, your script should reload the whole page by removing the meta refresh. Search for Ajax o Content of the page. Opens (open) the document window.document.open(); Save the new…
-
10
votes4
answers2731
viewsA: Is it possible to change the mouse cursor color via CSS?
The color is not possible. But you can switch the mouse pointer with CSS: .novoCursos { cursor: url(ponteiroVermelho.gif), auto; } The html code would look like this: <div…