Posts by mgibsonbr • 80,631 points
861 posts
-
8
votes3
answers167
viewsA: What is the meaning of this definition of values?
That’s a object literal being passed as argument to an initializer function. A literal is a way of defining/constructing a data structure in the program’s own source code, rather than through a…
javascriptanswered mgibsonbr 80,631 -
4
votes1
answer561
viewsA: How to convert jQuery’s . on function to pure Javascript
Normally convert from on for native Javascript is simple - for each event handled by on (ex.: click, blur, keyup) there is a corresponding native functionality (eg.: onclick, onblur, onkeyup); can…
-
3
votes4
answers329
viewsA: What’s wrong with my map version for a JS array?
In your first code, you are trying to choose a method dynamically, but the operator . is not the right way to do it. When you do objeto.algo it always looks for a property/method named algo, it…
javascriptanswered mgibsonbr 80,631 -
1
votes1
answer154
viewsA: Error searching in Django
On the line: idTaginfo = tag.taginfo_idtaginfo1 You should use: idTaginfo = tag.taginfo_idtaginfo1.idtaginfo For though in the model taginfo_idtaginfo1 is a foreign key (and in the BD is represented…
-
3
votes1
answer382
viewsA: How does Python interpret multiple comparison operators in sequence?
In fact, your last interpretation is correct. A common idiomatic expression in programming is to test whether a number belongs to an interval, i.e. whether it is greater (or equal to) a and less (or…
-
4
votes2
answers1296
viewsA: Open ID Connect and Oauth 2
The purpose of Openid Connect is to add a authentication the functions of authorization oauth (Source). That is, in fact the purpose of Openid and Oauth are different, and the problem is precisely…
-
2
votes2
answers804
viewsA: How do you calculate (easily) total and subtotal in Django?
For Django 1.8 or later, see response from Orion. Django version 1.7 or earlier cannot be used F as a parameter of annotate, aggregate or values (see ticket #14030), so that the only way to do this…
-
2
votes1
answer616
viewsA: Queryset on Django without case-sensitive
Several Django filters have a variant that takes uppercase/lowercase and another variant that does not. In the case of contains is the icontains: Node.objects.filter(nome__icontains = keyword) There…
-
33
votes4
answers14202
viewsA: How are prime numbers important in cryptography?
There are two types of encryption: the symmetrical (where both participants share a secret) and the asymmetrical (where one has a secret that the other does not possess). The symmetric makes no use…
cryptographyanswered mgibsonbr 80,631 -
3
votes2
answers962
viewsA: What is the difference between Encoding, Encryption and Hashing?
Encoding, sometimes called "serialization", is to take some information (e.g., a set of characters) and represent it ("encode it") by means of a sequence of symbols (e.g., an array of bytes).…
-
3
votes2
answers573
viewsA: Script to remove GOOD signature from UTF-8 files
A file UTF-8 with GOOD is simply a file in UTF-8 encoding in which the first 3 bytes are EF BB BF. Identifying the BOM is therefore a matter of reading the first 3 bytes and seeing if they…
-
1
votes1
answer978
viewsA: Reading files in PROLOG
The command read/1 serves to read terms of a file with the same syntax as Prolog. To read arbitrary content (i.e. strings) you will need the methods of primitive character reading, such as the…
-
3
votes2
answers445
viewsA: Diffie-Hellman group key exchange
That’s an open problem. While doing with two participants is trivial, and with three possible (although it involves a little more advanced mathematics), there is no known way to do this for four or…
cryptographyanswered mgibsonbr 80,631 -
4
votes2
answers571
viewsA: How to transmit data securely?
What is time synchronization (timestamp)? I’m not sure if we’re thinking of the same concept, but one technique that uses the watch to bolster security is the "Unique Time-Based Use Password"…
-
7
votes2
answers521
viewsQ: How to serve files with access control in Django?
When studying Django, the typical way to handle uploading files was to create a folder media on the server - establishing a MEDIA_ROOT and a MEDIA_URL in the settings.py - where any uploaded file…
-
4
votes2
answers1591
viewsA: What happens when I convert String to an array of bytes?
A "string" is a abstract type of data, representing a finite sequence of "characters". The implementation of this type on any platform - and even the semantic interpretation of what is a "character"…
-
5
votes1
answer335
viewsA: Error in multiplication and division (java)
Your problem is you’re never assigning memoria explicitly, only through operations with leitura. In addition this is not a problem, because: You type 2, the code makes leitura = 2; memoria is zero;…
-
4
votes1
answer1296
viewsA: How to accent in Python
When you open a Python file for writing using built-in open: with open("arquivo.txt", mode="w") as f: f.write("blá") He assumes that this file is in the system’s default encoding (in Python 2, it…
-
5
votes1
answer81
viewsQ: How to transfer a file with corrupted name?
A client of mine is having a problem to upload file on my system, and from what I could notice it is his file that is with corrupted name (it is relatively common, on Windows systems, the accented…
-
4
votes1
answer114
viewsA: Going from one point to another
Your high-level logic would be as follows:: If there is a journey of Partida to Destino, do it and that’s it; Otherwise travel to a point X that you haven’t visited yet, and then try to travel from…
-
5
votes1
answer369
views -
14
votes4
answers36247
viewsA: List files from a Python folder
os.listdir. You pass a path (relative or absolute) and it gives you the names of all the files, folders and links contained in it. There you can filter by file if you want (using os.path.isfile), or…
-
3
votes1
answer112
viewsA: Attraction of objects in python
First, you are calculating the absolute value of the force between the two objects (i.e. making up the distance from the positions x and y), but is not decomposing this force again in coordinates…
-
15
votes2
answers2102
views -
3
votes2
answers357
viewsA: How to avoid SQL Injection attack in this query?
Whether it can occur or not I do not know answer, will depend on framework used. But avoid should be much easier, it’s just validate the field, see if its format matches what you expect from it (and…
-
1
votes1
answer1075
viewsA: Decrypt XML with digital certificate private password
Partial response I don’t have an answer to your question, but reading the quoted documentation I can see what you’re doing wrong (which is a first step to fixing). I don’t know how to use this type…
-
1
votes1
answer470
viewsA: How to sort a query in Django by ignoring accents?
I can’t talk about the recent versions of Django, but in the last system I developed (I think it was 1.4 or 1.5) I had found nothing, and I ended up using this one workaround: Attribute the locale…
-
3
votes1
answer1333
viewsA: javascript zoom function
If you want the canvas whole increase in size, including your designed content, you can use the CSS property transform (which applies to any HTML element). If on the other hand what you want is that…
-
1
votes1
answer49
viewsA: When is the right time to include plugins in a program?
What’s the best time to add plugins? If you predict that certain features are interesting to your system but would look better outside your "core", then it helps to design it from the start so…
-
0
votes1
answer51
viewsA: Extract arguments from a Erlang URL
The module http_uri has a function parse able to interpret a URL. Calling it with the default options: parse("http://example.com:8080/path/to/resource?q1=foo&q2=bar#fragmento") Upshot:…
-
1
votes2
answers1278
viewsA: Defined variable, but shows as undefined
You are trying to access from within a more internal function the variables of a more external function. This - when supported - is called closure, and although in many languages every function can…
-
8
votes5
answers17941
viewsA: How to use the loop for(for) in Portugol?
The "to" loop is one of the forms of conditional deviation, that is, test whether a particular condition is met, and depending on the outcome, divert to a different instruction or proceed to the…
-
2
votes1
answer49
viewsA: Why is my regex not working as expected?
The problem is not in regex, as you well noticed, but in the functions of Javascript handling regexes. The function match of the kind String returns: The first marriage found, along with their…
-
1
votes1
answer424
viewsA: How to show a jPopupMenu just below a jTextfield?
I suggest instead of taking the position of Caret (that goes forward as you type the text...) you pick up the position (getLocation or getLocationOnScreen, I can’t remember which is correct) and the…
-
8
votes2
answers6972
viewsA: Leave two Divs always at the same height
I found a solution in this article (in English): "Bootstrap 3 Responsive Columns of same height". It creates a set of classes to ensure that all columns in a row are the same height. Those that…
-
2
votes1
answer793
viewsA: Code structure problem within switch case
All your code is contained within a loop that tests through an input invalid: // Pede uma porta System.out.println ("Elige una Puerta: Tenemos las puertas 0, 1 y 2"); String tentaStr = in.readLine…
-
9
votes1
answer72
viewsA: Why does the Regex result have two values?
When you include expressions in parentheses, you form a catch group, signalling that she is interested not only in marriage as a whole but also in that particular passage. The result then brings in…
-
7
votes2
answers400
viewsA: Compatibility, legality and possible problems with the open source license change
I don’t know how to help you with the specifics, so for your own safety I suggest you consult a lawyer. In the meantime, I would like to clarify some general principles on such licences copyleft to…
-
4
votes1
answer2068
viewsA: Check if more tabs of site X is open
As suggested in the comments, you can use local Storage/Session Storage to make this check. I’ll give a very simple example: Check if there is a count; if there is no count, start from 1, otherwise…
javascriptanswered mgibsonbr 80,631 -
6
votes1
answer1244
viewsA: Using multiple databases
When you have a single application and several different clients, it can be advantageous to have a single database serving everyone (as you claim to be the case with Wordpress and Joomla). This does…
-
39
votes3
answers23304
viewsQ: What is the difference between "passing by value" and "passing by reference"?
I know that in the first the object passed as an argument to a function is copied, and in the second not. I also know that it is extremely unusual in modern languages to pass complex objects by…
-
11
votes2
answers1558
viewsA: Does the passage of objects in Java simulate passage by reference?
"References" and "reference passage" are two different things. Unlike C/C++, in Java every variable that refers to a complex object does so by means of a reference, not a pointer and not a value…
-
1
votes1
answer189
viewsA: Create input fields according to the size of an array
There are some problems with your code: First you iterate on the JSON elements, then you iterate on the estates of each element; in my opinion, it would be enough to iterate on the elements, not?…
-
4
votes1
answer308
viewsA: Convert to hexadecimal colors
First of all, you should wear 16777216 (256 * 256 * 256 - Red x Green x Blue) instead of 65535 (256 * 256 - missing one). Second, it is necessary to fill the result with zeros on the left, if the…
-
1
votes1
answer246
viewsA: Assign id according to text content
As the content seems to me very uniform, a set of substitutions via regular expressions should be sufficient to achieve its goal. These replacements can be made in any of the three ways mentioned:…
-
29
votes3
answers1996
viewsA: What do I need to do to measure password strength?
To determine the strength of a password, you need to analyze how attackers proceed when trying to break a password. This excellent article by Bruce Schneier (in English) describes the state of the…
-
3
votes1
answer45
viewsA: Variable does not call function, Webworker and Scope functions
The function getKey does not belong to JSEncrypt, and yes to JSEncrypt.prototype. That means that all instance of JSEncrypt - maid new JSEncrypt(...) - is who will have this method. Create an…
javascriptanswered mgibsonbr 80,631 -
4
votes3
answers4053
viewsA: How to add list values in tuples?
In itertools there is a variant of zip which, by combining lists of different sizes, does not discard the elements further, but uses None for your values: >>> teste =…
-
4
votes1
answer263
viewsA: Set of 3 Java ports
The class java.util.Random has a method nextInt(int) that returns an integer in the range [0,n[, given a n input. Using 3, it will return a number on [0,1,2]. Then just assign the port with that…
-
3
votes2
answers227
viewsA: Use Promise in a Web Worker
The method WebWorker.postMessage does not return anything ("Void"), so that it cannot be used directly this way. If you want to use promises, you’ll have to implement it yourself. One way to do this…