Posts by epx • 8,191 points
241 posts
-
1
votes3
answers5035
viewsA: When to use Sqlite?
Sqlite can be used whenever you have to store data locally in a structured and corruption resistant way. The Sqlite code is considered one of the best in dealing with local files so as to minimize…
-
3
votes2
answers1256
viewsA: Client and server programming: How to achieve numerous data exchanges per client and multiple clients simultaneously?
This program has several socket usage errors. 1) In TCP, bytes are sent and received, not complete messages. There is no guarantee that a send() will send the entire provided string, nor that recv()…
-
2
votes3
answers5608
viewsA: What does "immutable" really mean?
I wrote an article about this (https://epxx.co/artigos/imutavel.html). The basic idea is as follows: in some languages, there is no distinction between "value of" and "reference to" an object. For…
-
13
votes9
answers31327
viewsA: How to hash passwords safely?
A very simple example. I take a word (which could be a password) and I take MD5 from it: $ echo "teste" | md5sum 1ca308df6cdb0a8bf40d59be2a17eac1 - If you search the string…
-
0
votes5
answers8000
viewsA: What is the difference between pointer and reference?
In C++, a reference is a pointer that assuredly points to the type object. For example, A* can point to an A object or can be null, and can even be invalid, since A& is guaranteed by the…
-
8
votes1
answer5346
viewsA: Difference between "<iostream>" or "<stdlib. h> <stdio. h>" in #include
One is the I/O of the standard C library, another is the I/O of the Standard Template Library (STL) for C++. There should be no substantial difference in performance between them. As a professional…
-
-5
votes2
answers245
views -
2
votes1
answer190
viewsA: When should I wear a patch?
Patches are used when you want to send a Git commit via email, so much so that Git has tools even for sending. This has to do with the Linux kernel developers' practice of exchanging patches and…
-
0
votes6
answers7903
viewsA: When should we allow a column of a table from a database to accept NULL?
Ideally a column should never accept NULL. The primary utility of NULL is so you can do LEFT OUTER JOIN, by exepmlo SELECT * from CLIENTES LEFT OUTER JOIN PEDIDOS ON CLIENTES.ID = PEDIDOS.ID_CLIENTE…
-
4
votes1
answer72
viewsA: Very large array - Android
In this order of magnitude (1000), you don’t have to worry. If it were a million elements... but don’t do premature optimizations. Test, profile and then draw your conclusions. The container issue…
-
3
votes1
answer41
viewsA: How to avoid php file running when it is being processed?
You can try to create a temporary file, if it is Linux it could be something like /tmp/exe.php.lock, and delete when processing ends. But there is a great risk that the file will not be removed if…
-
3
votes2
answers75
viewsA: How do I define Operator= for a c++ struct?
You must declare the method in the class or struct if you want to implement it. Include PATH& operator=(const PATH& p1); within the struct statement, along with the member variables.…
-
-1
votes1
answer49
viewsA: Difficulty in 1:n
The first major error is that while more mysql_fetch_array() makes no sense. Or you use while($sql = mysql_fetch($limite)) or uses mysql_fetch_array() and executes a loop (for) on top of the…
-
2
votes2
answers700
viewsA: How to remove an entire div in Jquery and then add it back?
You can take the content with . html(), store it in any string, remove it from the DOM, then recreate the DIV and fill it with . html(string). I don’t know how efficient it is, but it works.
-
0
votes1
answer45
viewsA: variable cannot admit another value
You are assigning lance_computer with == instead of =.
-
2
votes1
answer1626
viewsA: double free or corruption(out) - Dynamic Allocation in C
The error is as follows: int **matriz = ( int** )( malloc( linhas * sizeof( int ) ) ); You would have to use sizeof(int*) instead of sizeof(int), as it is allocating a matrix of matrices, not an…
-
-1
votes3
answers3080
viewsA: Check the line containing a string inside a TXT file
#!/usr/bin/env python3 import sys lines = open("arquivo.txt").readlines() for i in range(0, len(lines)): if sys.argv[1] in lines[i].strip(): print("%s na linha %d" % (lines[i].strip(), i + 1)) break…
-
6
votes1
answer1365
viewsA: Big O notation - Complexity O(log n)
The basis doesn’t really matter much, because a logarithm of a base can be converted to another base by multiplying by a constant. For example: log2 10 = log10 10 / log10 2 (of which log10 2 is a…
-
0
votes1
answer23
viewsA: TCP server with select(), does not work because printf shows 3x to msg and msg comes with trash at the end and ends automatically
An error you can see at first: you are receiving data in buffer using recv(), but you are using buffer in printf() as if it were a string ending in 0, and recv() does not guarantee this. A simple…
-
10
votes3
answers101378
viewsA: What are the main differences between SOAP, REST?
Short answer SOAP is old-fashioned, complicated and boring. In some languages, SOAP support is getting decadent, there are libraries that work but have not been played for almost 10 years. REST (and…
web-serviceanswered epx 8,191 -
1
votes2
answers236
viewsA: Promises in Nodejs
I’ve got a couple of examples lined up, two timers, hopefully useful. The first uses Promises, waiting a while, returning a random result and simulating failures so you see what happens when the…
-
0
votes1
answer45
viewsA: Async request problem with variables
Directly, the way it is, you can’t use foo out of the callback passed by information(). There are two ways to make the main asynchronous code more readable. One is to turn your original method into…
-
0
votes1
answer1688
viewsA: Develop IOS on Windows
Unfortunately, it’s not possible. You could try a "Hackintosh" - PC running a modified version of macOS, but it’s risky and the development and emulation software are the most annoying in relation…
-
2
votes1
answer162
viewsA: Animations in high quality
Web animations are not necessarily unfriendly. Animations that make use of CSS animations, or other CSS tricks, are excellent. What gets a little bad are those jQuery-style animations, because…
-
1
votes1
answer33
viewsA: How to ensure data entry and update in different databases
It is a complicated problem to ensure a perfect solution. Look for the "Problem of the Byzantine Generals". One way to solve this is to use the "two-Phase commit" technique, or 2-phase commit. In…
-
2
votes2
answers360
viewsA: Why are primitive types with floating points divided or multiplied by certain multiples of 10 displayed in scientific notation?
It is purely arbitrary, each language has its criterion, and aims to prevent a very large or very small number from generating a very large string (imagine 10 300, which is 1 followed by 300 zeros).…
-
5
votes2
answers1231
viewsA: Can the operators ==, ==, != and !== be considered as "fuzzy logic"?
It has nothing to do with one another. The presence of different equality operators has to do with "weak typing". == e != test equality, and if necessary implicitly convert the type of one of the…
-
1
votes1
answer283
viewsA: How to share/pass data between activities other than Intent?
There is no (secure) way for an Activity to "chat" directly with another Activity. The way Android is architected, different Activities and Services can be in separate processes. If you wanted to…
-
1
votes5
answers1899
viewsA: Is dealing with business rules in the model bad practice?
It fits in the Model yes, the problem is that some frameworks have equated the Model with the database, or a representation of it (ORM), then automatically it seems that the Controller should…
-
1
votes1
answer389
viewsA: Python GUI: request interface and or ide tips for this
Tkinter is the "common denominator" of the graphical interface for Python. This means that a Python script that makes use of TK will run on any platform. For simple applications, it is a good…
-
0
votes2
answers885
viewsA: To what extent should I follow the conventions, where can I apply specific style patterns of my own?
The ideal is to use what your IDE (e.g. Eclipse, Android Studio) uses, because then self-training does the work for you. As far as I know Java does not have an official coding style with ubiquity…
-
1
votes3
answers9114
viewsA: What are the differences between printf, fprintf, sprintf, snprintf, printf_s and fprintf_s?
Everyone’s operation is similar, so I don’t see the need for examples. I assume you know how to use printf(). All use the convention of a "mask" string followed by a vararg, i.e., a variable number…
-
4
votes2
answers601
viewsA: How to take the path of the open executable in C
The main() function, where the program starts running, has the following prototype: int main (int argc, char *argv[]) The argv[0] string contains the name of the executable, the other strings of the…
-
0
votes1
answer120
viewsA: Percentage of Interest on Price
It is not possible to isolate the interest rate ("i") in this formula. It is necessary to find the interest rate using linear interpolation or the bisection method. The bisection method works more…
-
11
votes2
answers2381
viewsA: What is the difference between static and dynamic linkage?
Static linkage means that the libraries required to run the program are embedded in the executable file itself. That’s Inker, hence the name. In dynamic linkage libraries remain outside the…
-
2
votes1
answer2883
viewsA: How do you make a socket that actually connects to other computers?
Here it worked perfectly well, including running the server on a computer on the Internet, and using a HOST with name instead of IP on client. The server you tried is leaking? Sometimes the…
-
11
votes4
answers14489
viewsA: Invert string in C
The problem is that "size - i" will pick up a character beyond the length of the string. For example, a string with size 5 (size=5) will have characters in s[0], s[1], s[2], s[3] and s[4], but s[5]…
-
3
votes3
answers296
viewsA: Function that converts this string to a json
No split() or simple regular expression will do what you want. You need to develop a mini-interpreter, with state machine. Something like this (in pseudocode): estado = 0; nome = ""; valor = ""; //…
-
0
votes3
answers2490
viewsA: What are the differences between pointer and reference in c++?
A reference is "secure": it cannot be null and the compiler ensures that it points to a valid object. You cannot simply declare a variable Objeto &x; because then the variable would be null or…
-
0
votes4
answers5293
viewsA: How to check if the user is online?
The ideal would be to use Node.js (with the chat inside an iframe, connecting to Node.js which would be a separate PHP server), and Sockets.io as basic technology. There are even several example…
-
6
votes1
answer933
viewsA: Update application every 5 seconds
I suggest nay use threads to schedule the periodic request, after having handled the previous request. Something in style: final int delay = 5000; final int period = 5000; final Runnable r = new…
-
1
votes2
answers156
viewsA: Use separate threads or programs?
It is always advisable to use separate processes. (Nowadays, with the trend of microservices, the "fashion" is to use even separate virtual machines, but this is beyond the scope of the question.) I…
-
-2
votes2
answers6247
viewsA: How to get the current date/time, independent of the device?
Actually Date() is a timestamp, so internally it is already independent of spindle. No need to pick up the date of another Internet service, because the date/time of the mobile phone is usually the…
-
1
votes3
answers738
viewsA: Hybrid applications optimize webview?
When you use a hybrid architecture, you may need to create "bridges" between the HTML5 layer and the native layer to access native platform resources. For example, access mobile contacts. Normally…
-
3
votes1
answer48
viewsA: non-zero getpid and getuid for root
You seem to be declaring the functions (and not calling) in the first two lines, and then you are declaring two variables without throwing any value at them, so naturally they will contain random…
-
2
votes2
answers76
viewsA: Strict Aliasing do c
Strict aliasing is when the compiler assumes that two different pointers do not point to the same memory area. It is a presumption created in the C99 standard that aims to improve performance. For…
-
4
votes4
answers569
viewsA: In Object Orientation, does an inheritance violate encapsulation?
Inheritance, as taught in OO in the 1990s (at the time they said OO would end world hunger), has surprisingly few legitimate uses. I would not use the expression "violates encapsulation", I would…
-
1
votes1
answer134
viewsA: C++ smart pointers and functions
Yes, the way the Processlargeobject() function is declared, the object is passed as an immutable reference. Because it is immutable, it is no less secure than passing by value, and faster for…
-
0
votes1
answer54
viewsA: Stretch canvas without interpolar image
CSS3 has a property called image-Rendering, which you arrow as Pixelated. At least Chrome supports: https://www.chromestatus.com/feature/5118058116939776 It just won’t look too pretty, except when…
-
1
votes1
answer1992
viewsA: Show profit or loss in negative percentage
The case of $expense = 0 you would have to filter with an "if" condition because it represents an infinite profit (revenue without any expense). To eliminate division by zero when the recipe is…