Posts by Guilherme Bernal • 20,024 points
220 posts
-
2
votes6
answers293
viewsA: How to visually indicate which fields are fillable?
Finally, using a little of each answer (I accepted the utluiz for being the most complete), I arrived at the following layout: Added a pencil icon to the editable fields. I preferred to do so…
-
12
votes6
answers293
viewsQ: How to visually indicate which fields are fillable?
I am developing an application, in which there is the following form to be filled: The goal is to obtain the necessary data to form the "Code of Action" that must be created. This code is formed by…
-
14
votes2
answers4341
viewsA: What are rvalues, lvalues, xvalues, glvalues and prvalues?
After some hard reading I reached the following conclusions: lvalue (Locator value): Denotes an addressable value. A value whose address can be obtained directly (through the operator &). int a…
-
1
votes1
answer1134
viewsA: How to calculate the difference between two different hours in milliseconds?
According to the documentation, the substation between two times returns a number of seconds. So you can get the value in milliseconds like this: delta_time = (Time.now - start_time) * 1000 To…
rubyanswered Guilherme Bernal 20,024 -
47
votes5
answers9524
viewsA: Receive an expression and calculate in C
In C there is no "Eval" or anything similar to execute Runtime code. So the only way to execute an expression like this is to create a sub-language. You need to define a grammar, write a parser and…
-
25
votes2
answers4341
viewsQ: What are rvalues, lvalues, xvalues, glvalues and prvalues?
Prior to C++11 there were only two value categories for expression tree types: lvalue and woodland. Quite simply, the first represents a reference that can be changed and whose address can be read,…
-
17
votes5
answers453
viewsQ: Is it legal to delete this in a member function?
The language delete this serves for an object to commit suicide. For example: void Recurso::release() { --refs; if (refs == 0) delete this; // Aqui o 'this' pode ser um ponteiro inválido, // tocar o…
-
8
votes1
answer165
viewsA: What is the difference between `for x in y` and `Enumerable#each`?
Are equivalent. for a in b; code end is a syntax sugar for b.each {|a| code }, with the difference that the variable a does not have its scope limited to the block. A simple proof for this is as…
-
13
votes3
answers5043
viewsA: How to block the browser console using javascript?
It’s not possible. The page is browser submissive and the javascript console is not something you can really control, it’s an extra. It would be like preventing them from viewing your html or…
-
24
votes3
answers1024
viewsQ: Should I free up all the allocated memory when finishing a program?
It is commonly accepted that when I allocate a block of memory I am responsible for releasing it. This is particularly true when programming based on RAII. However the following program works…
-
7
votes3
answers1024
viewsA: Should I free up all the allocated memory when finishing a program?
In any modern operating system the virtual memory pages feature. In this model each process owns an entire address space and the system has the responsibility to map the address that the process…
-
2
votes1
answer472
viewsA: gcc is not found when Makefile is run by Travis-CI
It is good practice to make a Makefile that does not depend on a specific compiler. In your case, you explicitly used the gcc to compile, always. Instead, take the standard compiler of C of the…
-
6
votes2
answers144
viewsA: How to make a constructor equal to Qobject?
Qt’s Qobject were made to work on the heap without so much difficulty with memory handling. They are uncopyable (private or deleted copy builder). In addition each object may have a relative will…
-
43
votes4
answers1480
viewsQ: What is the correct way to simulate a <script> with a new language?
Suppose I implemented a new language and I have a functional interpreter written in javascript. Something like mylang.interpret(code_as_string). Now I would like to create an interface in which I…
-
2
votes3
answers346
viewsA: How to make a polymorphic pointer with the this pointer in the parameter?
The expression this results in a pointer to the object in which you are calling the member function at the moment. It makes no sense to write this out of a member function since there is no object…
-
2
votes3
answers435
viewsA: How to loop in openMp to count lines from a text file?
The problem is that it is not possible to determine the number of iterations at the beginning of the loop. Knowing where each line starts requires having read the previous line and knowing the total…
-
5
votes4
answers7006
viewsA: Doubt with Regex with new line
Most Engines use the . as "any character other than line break". There is usually the option m, that switches on multiline mode and removes the restriction on .. Usually the syntax is this:…
-
15
votes8
answers59138
viewsA: How to raise a number to a power without using the Math. h library?
If the goal is to learn how the function works, a good way is to read the source code of some implementation of libc, I will take for example the glibc. The function powf (internally called __powf)…
-
35
votes2
answers1202
viewsA: What is the name of this 'effect' of selecting objects and how to do it in pure JS?
Step 1 - Creating the "rectangle selector" The main characteristic of this "effect" is to have a rectangle created during the selection process to demarcate the area being selected. It has one…
javascriptanswered Guilherme Bernal 20,024 -
3
votes2
answers20308
viewsA: How to read a text file and take the values as integers?
When it comes to C++ you can use the std::fstream and the operators reading from std::istream. An example: #include <fstream> int main() { std::ifstream file("matriz.txt"); if (!file) {/*…
c++answered Guilherme Bernal 20,024 -
4
votes1
answer125
viewsA: How to apply a texture without distorting?
Go to your XML drawable and add property tileMode="repeat". For example: drawable/imagem_de_fundo.xml: <?xml version="1.0" encoding="utf-8"?> <bitmap…
androidanswered Guilherme Bernal 20,024 -
4
votes2
answers654
viewsA: Pointer logic
Arrays and pointers are quite different concepts. A pointer has nothing to do with an "unlimited array". Come on: int lista[10][10]; Here you are declaring a two-dimensional array with 100 elements.…
-
2
votes3
answers85
viewsA: Allocator and placement new
To your allocator be valid, it must behave in a manner equivalent to std::allocator. I see some problems with your: T* my_allocator<T>::allocate(size_t n) Here the documentation of…
-
1
votes2
answers354
viewsA: What architecture and operating system properties allow a buffer overflow attack?
When compiling a program in C the characteristic of what is each byte of memory is lost. The size of each array is simply removed by performance and it is not possible to determine where each object…
-
1
votes1
answer203
viewsA: How to treat screen orientation in QML?
You can deduce the screen orientation by the ratio width/height. An example: Item { id: root property int isVertical: width/height < 1 Text { text: root.isVertical ? "Vertical" : "Horizontal"…
-
5
votes2
answers2140
viewsA: How to "clean" static variables?
If you need it, there’s something wrong with your design. Static variables in functions should be used to store a state global, not a momentary state of operation. First, you don’t need a state for…
-
5
votes3
answers784
viewsA: Set the threads priority in C++11
There is no way to change the priority of a std::thread on C++11 or C++14. The only way to do this would be by using (non-portable) linux functions. Get a native identifier with…
-
4
votes3
answers942
viewsA: Undefined Reference when compiling multiple files
You must compile each file .cpp in an object .the. In sequence link the objects in a final binary. Your problem is because you only compiled the main file and at the time of creating the executable…
-
15
votes1
answer398
viewsA: What is the difference between these ways of indexing a pointer to an array of structs in c?
The three ways to access a struct in an array are equivalent. a[b] is equal to (*(a+b)) (more details) (*a).c is equal to a->c Therefore: (*(a+b)).c is (a+b)->c (*(a+b)).c is a[b].c…
-
11
votes7
answers43303
viewsA: How do I know if a variable is of the Javascript Number type?
If you’re not looking to verify something is a number, but if it behaves as if it were, can use this function: function isNumber(n) { return !isNaN(parseFloat(n)) && isFinite(n); } The idea…
-
7
votes3
answers739
viewsA: What does ":-!!" mean in C language?
In a bitfield structure you can specify the bit size of each member, keeping its original features. Example: struct bitfield { signed int a : 3; // Um inteiro usando complemento de dois com 3 bits.…
-
9
votes3
answers308
viewsA: How to "create" a variable in "Runtime"?
You can use a std::map to save your variable table. Example: #include <map> #include <string> #include <iostream> typedef std::string Variable; std::map<std::string,…
-
15
votes3
answers29291
viewsA: Creating your own header file
The compilation of a program written in C is done briefly in two steps: Compilation: Translate each source (.c) (called translation unit) on an object (.o) Linking: Merge all objects into an…
canswered Guilherme Bernal 20,024 -
8
votes4
answers1879
viewsA: Is it necessary to add prefixes to some CSS properties?
When the browser is implementing a new standard property, it makes it available with the prefix at first. This prefix (called prefix vendor) is removed only when the property’s behavior is exactly…
-
8
votes5
answers48166
viewsA: How to increase or decrease the div proportional to 720x540?
The simplest way to create this effect is to add the style padding-bottom with the equivalent percentage of the height divided by the desired width. div#slide { padding-bottom: 75%; /* 540/720 */ }…
-
15
votes4
answers309
viewsQ: How to deal with a comet process?
Analyzing the linux API I noticed that an interesting structure is possible: #include <unistd.h> #include <stdlib.h> int main() { while (1) { if (fork()) exit(0); // Altera meu pid…
-
4
votes2
answers1093
viewsA: How to compile a *.c file with Clang to signal problems?
The Clang is built quite modularized so that the command line processor (called driver) is completely separate from the compiler itself. There are basically two drivers. One that has identical…
-
4
votes1
answer1745
viewsA: Syntax error, Unexpected keyword_end, expecting end-of-input
The first word of your code is Class. I suppose it should just be class. So you have one end additional in your code, which should be closing the class. just fix the capitalization.…
-
0
votes4
answers594
viewsA: How to create a URL redirector?
A simple way to implement what you search with Javascript could be: <html> <script> function redirect() { var match = /\?url=(.+)/.exec(window.location); if (match) window.location =…
-
7
votes4
answers1099
viewsA: When to implement header functions?
When including functions in headers you should mark them with the inline, and there is no need to reimplement them at source. Just once is enough. Perks: Speed: The compiler will be able to perform…
-
28
votes1
answer443
viewsQ: Why is processing an ordered list faster than an unordered one?
I have a C++ code that for some inexplicable reason seems to run much faster when my data is previously sorted. I was able to reproduce the behavior with the following code: #include…
-
31
votes1
answer443
viewsA: Why is processing an ordered list faster than an unordered one?
You are a victim of branch predictor. What is branch prediction? Consider a railway junction: Image by Mechanism, by Wikimedia Commons Now, for my argument to make any sense suppose we’re in the…
-
2
votes3
answers273
viewsA: How to implement Std::to_string for floating point?
The simplest way to implement the function is to rely on std::stringstream using the operators of std::ostream which will already be implemented for the standard types and several custom types. This…
-
20
votes3
answers523
viewsA: Why does C array[6] equal 6[array]?
Referencing the C standard: 6.5.2.1 Subscripting array Constraints One of the Expressions Shall have type "Pointer to complete Object type", the other Expression Shall have integer type, and the…
-
2
votes3
answers3415
viewsA: How to interpret the use of the CPU through the monitor of the options of Android developers?
In the developer options there is the option "Show CPU usage", which will display in the upper right corner of the screen some statistics. In the first line there is the medium load of the system,…
-
2
votes4
answers1418
viewsA: How do I programmatically respond to a command on the Linux terminal?
On *Nix systems you can input data to another command using Pipes |. The idea is that when you write cmd1 | cmd2 The output of Command 1 will be the input of Command 2, that is, they are connected.…
-
8
votes2
answers609
viewsA: Could current Javascript engines optimize "tail" recursive calls?
Firstly, I would like to highlight an important difference in terms: Tail Call Optimization: When an implementation optimizes a tail call so that a new stack frame is not allocated and the Caller be…
-
6
votes1
answer205
viewsA: Waiting for a signal within a Qquickimageprovider
I don’t know how to wait for the signal there. It is also not possible to make the thread sleep in a loop by checking if the data arrived manually because the QNetworkReply depends on the Event loop…
-
15
votes1
answer205
viewsQ: Waiting for a signal within a Qquickimageprovider
I’m creating an application using QML and the Qt 5.2. In her a ListView displays multiple items, each with an image and associated text. The image is built based on data uploaded from a server by…
-
10
votes2
answers6568
viewsA: "placeholder" of "textarea" does not appear
The problem is that the placeholder appears only when the textarea is empty, without any text. Yours is not, you have inserted the indentation spaces in it. Try: <form action="" method="post">…