Posts by cantoni • 6,602 points
149 posts
-
5
votes3
answers7306
viewsA: Check if a process is not running and then run it
There are several ways to do this. One of them is by using the pgrep: pgrep gedit If gedit is running, a number will be returned. 17805 This number is the process ID (PID). This number obviously…
-
4
votes2
answers78
viewsA: Difficulty to query in Mysql
I believe that’s what you need: select product_id from products_search_items where search_item_id in (14,20) group by product_id having count(*) = 2 This SQL will only return product_id that has…
-
3
votes1
answer1768
viewsA: What is a loopback interface?
The loopback interface is a virtual network interface used basically for two purposes: Diagnosis; For developing and testing systems that require a network interface with an IP (Webservers, etc). On…
-
2
votes2
answers78
viewsA: script does not write to file
By default, the awk split into a string using the white space character as a separator. So if it’s done: echo "20151223152832_alexsandro_felix.txt" | awk '{print $9}' nothing will be returned,…
-
3
votes3
answers4197
viewsA: Select from two tables without repeating data
If what you want to know is the user data and the amount of photos that exist for each one, then this SQL should solve: SELECT u.id, u.username, u.genero, u.idade, u.local, u.descricao, count(*)…
-
9
votes1
answer3215
viewsA: Perform music in the program in C
The answer below considers using a program via the command line, as asked in the question (for Windows). Another approach would be to use a C library to play the MP3. Surely there is some. The first…
-
3
votes1
answer33
viewsA: Role interpretation
Unlike that reply, in which case there is no way to remove the for loop, as you need to iterate over all users to create an object mensagem for each one. The most you can do is avoid two loops on…
-
5
votes2
answers84
viewsA: Doubt interpretation function
for below will go through all the Hashmap users. To go through it calls the method entrySet() that returns a Set<Map.Entry<K,V>>. for(Map.Entry<String, ObjectOutputStream> mapa :…
-
9
votes1
answer550
viewsA: Number of threads on a 16 processor machine
This graph shows something very important when it comes to parallel algorithms: there is a limit on the performance gain that is obtained with parallel algorithms, that is, the increase in the…
-
1
votes1
answer79
viewsA: Client Server error sending messages
Within the class Panelling, method create, there is the code below: botaoEnviar.addActionListener(e->{ String texto = this.zonaEscreverMensagens.getText(); String nome = this.mensagem.getNome();…
-
1
votes1
answer622
viewsA: Error Case and Group by - Oracle SQL Developer
You cannot use the name of a column nicknamed as at Group By. Try this: select ESCALAO,COUNT(*) AS QTD from ( select case when sal BETWEEN 0 and 100000 then 1 when sal BETWEEN 100001 and 200000 then…
-
1
votes2
answers234
viewsA: Why is the recursive function return not being used?
This happens because the variable array is the type int[]. This is a vector and every vector in Java is an object. That way, whenever you call the function mergeSort recursively as shown below, the…
-
1
votes1
answer31
viewsA: Instance error for class
The problem is occurring because the class constructor User accepts a java.sql.Date and by instantiating an object User is being passed on java.util.Date. Change the import of the User class to…
-
3
votes1
answer156
viewsA: How to prevent Double from turning a large number into exponential?
One of the ways to do this is to use the String class itself. String.format("%.0f", new BigDecimal("123e+23")); The output of this code is: 12300000000000000000000000 Another way using only the…
-
10
votes9
answers41109
viewsA: What is a programming language, IDE and compiler?
To understand, let’s make an analogy with Portuguese. So that we can communicate with each other in Sopt we use written Portuguese. In Portuguese (as in any other language), there are two very…
-
5
votes1
answer49
viewsA: Java - SQL Error Updating All Users
In your SQL string you need to specify which user you want to update using the clause Where for this. Also, you need to pass this user as parameter in your method upgrade. Something like that:…
-
0
votes1
answer1048
viewsA: Multiples serial communication with Atmega328
The Atmega328 has only 2 pins for serial communication, they are: 2.3. On an Arduino board (such as Uno and Duemilinove), these pins are mapped to the 0.1 pins. Serial communication via USB cable on…
-
3
votes1
answer5292
viewsA: How to make an HTTP GET request for a web service with Arduino
Try playing the example described here: https://www.arduino.cc/en/Tutorial/WebClient However, replace the following code snippet for your reality: if (client.connect(server, 80)) {…
-
1
votes1
answer161
viewsA: Doubt pinout Atmega328
Atmega328 analog pins go from 23 to 28. Pin 22 is GND. Note that although the image mentions the Atmega168, it serves for the Atmega328. See here: https://www.arduino.cc/en/Hacking/PinMapping168…
-
1
votes2
answers899
viewsA: How to use Firebird database on network with C#?
The problem is occurring, because in the connection string is being used the localhost. Is used localhost in cases where the database runs on the same application machine. It is a common scenario…
-
3
votes1
answer78
viewsA: Java - How to validate user group in SQL and Save result?
One of the alternatives to solve this problem is the following: instead of returning true or false, return an object of type User if login is successful. Thus, you can popular this user object with…
-
1
votes3
answers499
viewsA: How to force the reading of all existing REST results on a page?
This depends on the application that runs on the server. If the application allows you to pass a parameter so that more records appear per page then you can do this with a request only. If there is…
-
11
votes2
answers3185
viewsA: Binary search in chained list
It is possible to apply the Binary Search to a chained list, however, you will lose the main reason to use the Binary Search, the factor it has complexity O(log n). The fact is that binary searches…
-
4
votes1
answer360
viewsA: Display Average in an SQL query
This can be done using SQL or in the application. I recommend it by SQL as it is simpler and more effective (since the data is in the database). If this is done by SQL, then the aggregator function…
-
8
votes1
answer253
viewsA: How can I record information with Arduino?
Yes, it is possible. There are three very interesting ways to record the information generated by Arduino. Computer (via Serial RS-232 or Ethernet) That’s the most basic way. You turn on the Arduino…
-
8
votes1
answer1709
viewsA: What’s the difference and benefits of using @@IDENTITY and OUTPUT INSERTED.ID
There are 5 methods to get the last inserted ID, are they: @@IDENTITY SCOPE_IDENTITY() IDENT_CURRENT('table name here') OUTPUT SELECT MAX Below each one explored in a brief way. @@IDENTITY Returns…
-
3
votes2
answers200
viewsA: How do you store a chart as a variable and export it later?
You should use recordPlot for this. See how: x<-1:10 y<-10:1 plot(x,y) grafico <- recordPlot() plot.new() grafico The purpose of recordPlot is exactly what the name itself says. Save the…
-
4
votes5
answers1382
viewsA: No return on method?
The fact that you are doing a silent treatment of exception is hurting you to understand what is happening. Exceptions can be handled silently, but as long as they do not prejudice later executions…
-
6
votes2
answers1239
viewsA: What is the difference between *var++ and *var += 1?
This is due to the order of precedence of the operations. The increment operator (++,-) takes precedence over the operator *. Therefore, in order to work the way you want, you first need to have…
-
1
votes1
answer62
viewsA: Select max in nested queries
In chat chat, @Danielamaia said that ROWNUM, only MAX, could not be used. So the original answer has been replaced by this now. To avoid the use of ROWNUM, a CTE (Common Table Expression) can be…
-
1
votes1
answer325
viewsA: Count number of occurrences in a for in loop {Bash}
You can do it: #!/bin/bash total=$(ls -l *.jpg | wc -l); contador=1; for file in *.jpg; do echo "A Processar o ficheiro $file ($contador de $total)"; convert $file -resize 1920x1080! -blur 0x8…
-
1
votes2
answers19521
viewsA: VBA - Counting the number of filled cells in the row
Change your code for this: For b = 1 To rMaior contador = Worksheets("1").Rows(b).Cells.SpecialCells(xlCellTypeConstants).Count MsgBox contador Next b This code considers that you want to count n…
-
1
votes1
answer164
viewsA: When running PUT method on Grails application system inserts new record instead of updating
The record is being entered, because within the action updateJSON a new department instance is being created and passed as a parameter to the method update. The method update, in turn, save this…
-
2
votes3
answers1827
viewsA: Excel - Extract only numeric fields from a selection containing text and numbers
A solution in VBA would be to use the procedure below. Note that it is generic, not only for what is selected. You pass an object of the Range type and it iterates through all cells that make up…
-
4
votes2
answers1188
viewsA: Performance Excel VBA vs. Multhreads Calculation
Microsoft implemented the concept of Multi-threading to solve the formulas of a spreadsheet (I believe from Excel 2007 onwards). Because of this, if a machine has more than one core, Excel will use…
-
3
votes1
answer795
viewsA: Join data from 2 sheets and point differences
This problem can be solved quickly using the PROCV formula, however, to do so, it will be necessary to create an additional column that will serve as the primary key of your data. In addition, an…
-
0
votes2
answers194
viewsA: Instantiate class in a library by method in the Norwegian
The problem is occurring because the variable myKeypad cannot be accessed within getKeyPress, since it is not visible in that scope. Note that the variable is declared in another method, called…
-
0
votes3
answers1265
viewsA: How to fill an array of another class in JAVA
There is something subtle happening and has relation with the concepts of passing parameter by reference and passing parameter by value. Note that although it may seem confusing, Java only has…
-
9
votes2
answers3574
viewsA: Why is set theory so important to computation?
In addition to the context explained by colleague @epx, I think it is important to mention that set theory is the basis for the Relational Model, widely implemented by relational database…
-
1
votes1
answer152
viewsA: Catch max value inside a while that is inside a cursor
The problem is occurring as the @Maxid of PROPADESAO is obtained and, without increasing it, an INSERT is made in PROPADESAO. The increment is done only at the end of the loop. As INSERT is done…
-
1
votes2
answers132
viewsA: check if several fields are created in the database
I understood that you need to check if the seven fields exist, if that’s it, something very simple would be the following: DECLARE @QTE_CAMPOS INT SET @QTE_CAMPOS = (SELECT COUNT(*) FROM ( SELECT…
-
5
votes1
answer462
viewsA: VBA/Excel - Subroutines stop while typing
The timer stops counting, because the moment you are typing in a cell, Excel interrupts any execution of VBA code. I do not know a way to modify this behavior, is part of the Excel design and should…
-
5
votes1
answer408
viewsA: Operations on matrix with no defined size
Vectors are objects in java as well as matrices. This means that there are methods and attributes that you can use. One of these attributes stores the size of the vector and is called length. Let’s…
-
6
votes3
answers8609
viewsA: Run a Shell Script with double click on Ubuntu
No Ubuntu 15.04: Open Nautilus and click the Edit menu then Preferences. In the window that opens, click the Behavior tab and mark one of the options indicated by the arrows. Also, your file needs…
-
1
votes1
answer5403
viewsA: Macro to exclude filtered table row
One option would be to apply the algorithm below. The worksheet does not need to be filtered for the functioning of it. The Sub little erasers receives a column as parameter and, from line 2,…
-
1
votes2
answers519
viewsA: Select only the first record of a column
Record A appears 3x in your example. The only difference between them is Date. For what you want, you must return the Product with the latest Date. Therefore, it is necessary to use a Group By…
-
0
votes1
answer163
viewsA: Resultset GROUP_CONCAT is not recognizing the manipulated values
from the comments, I understood that the goal is to make the sum of the columns Year in Java. The error occurs because the record is being populated with a null Object. Thus, the solution is to test…
-
2
votes3
answers2541
viewsA: RXTX: serial scale port connection
The problem is occurring as it is sending a set of bytes to the balance that does not correspond to the expected hexadecimal character. Is being done: leitura.EnviarUmaString("0x04"); Inside the…
-
2
votes1
answer799
viewsA: How to create POST, PUT and DELETE method in Grails application?
Below is an example that I use in a Grails application (2.2.5) which is a REST service consumed by another application, also developed Grails (2.5.0). In Urlmapping:…
-
3
votes1
answer121
viewsA: Generating new objects using existing objects
The algorithm below works for three attributes. For an arbitrary amount a more elegant solution is to use Reflection in order to discover these attributes on-the-fly. If the attributes are always…