Posts by mgibsonbr • 80,631 points
861 posts
-
3
votes1
answer408
viewsA: Depth Search with Prolog - how to limit depth?
In fact, when using History and check whether the knot is already part of History, you are already limiting the search and avoiding repeated knots. There is no need to artificially limit depth (type…
-
1
votes1
answer276
viewsA: How to represent a matrix in Prolog?
The most common way to represent matrices in programming languages that do not have a native type is through a list of lists: ambiente([[_,_,_,_,_,_,_,_,_,_], [_,_,_,_,_,_,_,_,_,_], ...…
-
0
votes1
answer52
viewsA: Program always returning "false"
Your problem is that you are making concrete value comparisons with variables not yet instantiated. The operator == will succeed only if the terms of both sides are already equal, without any…
-
4
votes1
answer199
viewsQ: How to save a Filefield template using a preexisting file?
I am importing a set of preexisting files to Django, and would like to refer them to my templates (which they use FileField or ImageField). For example, one of my models is like this: class…
-
3
votes1
answer199
viewsA: How to save a Filefield template using a preexisting file?
Yes, it is possible to make these references as long as the files are inside the MEDIA_ROOT. Just pass the way relative as an argument for the objects.create: path_imagem =…
-
2
votes1
answer90
viewsA: Algorithm bugs that encrypt text
You are not going through every letter of the password, but trying to convert the entire password into a number. The line: k = atoi(argv[j]); should be: k = (int)argv[1][j]; // Caractere j do…
-
5
votes2
answers135
viewsA: Why only an Encoding works in the algorithm?
The function of a Character encoding is to encode a certain "text" for bytes and back to text. For a encoding be complete, every possible string of text must have a byte representation (a encoding…
-
6
votes2
answers281
viewsA: What does the term typeof module mean in javascript?
This code snippet is testing whether the variable module exists or not - probably to detect if the code is running on browser or in a Node.js environment. The operator typeof says what is the type…
javascriptanswered mgibsonbr 80,631 -
2
votes2
answers1368
viewsA: HTML component for multiple item selection
I don’t know a ready-made component that does this - either in HTML5 or using some library or framework. The logic, however, is quite simple: On the left and right you have components that allow…
-
5
votes1
answer373
viewsA: Dual cryptography
It’s called cascading encryption (Scade), and is used in real systems (for example, the Truecrypt system offers the option to use up to 3 distinct algorithms - AES, Twofish and Serpent - including…
-
12
votes2
answers6306
viewsA: What is salt when it comes to password encryption?
Salt is used to prevent two identical passwords from producing hashes identical - which would greatly facilitate the work of the attackers. The use of encryption in the protection of passwords…
-
12
votes1
answer605
viewsA: What is required to achieve maximum entropy?
There’s a big difference between perfect security (or perfect confidentiality) and semantic security. The first is more of theoretical interest, and in this context, you can’t "generate" randomness…
-
4
votes1
answer12643
viewsA: can’t Multiply Sequence by non-int of type 'float'
This error means that a variable containing a sequence (list, tuple, string, etc.) is being multiplied by a float. In Python, if you multiply a sequence by an integer number, it repeats that…
-
4
votes1
answer211
viewsQ: How to use regex starting in the middle of the string?
I have a rather large string and would like to check if an excerpt of it house with a regex. The problem is that this stretch is in the middle of the string, in a very specific position. As I will…
-
6
votes1
answer211
viewsA: How to use regex starting in the middle of the string?
This can be done through flag sticky and property lastIndex (the same one used by flag global). Just create the regex with this flag and then assign the position you want to seek: var re = /\w+/y;…
-
12
votes4
answers843
viewsA: How to limit the generation of pseudo-random numbers to non-zero and non-repeating numbers?
Use random.sample: >>> random.sample(range(1,61), 6) [39, 15, 37, 18, 52, 60] Explanation: A method that guarantees a fair draw (i.e. each element has the same chance of being drawn) and…
-
1
votes1
answer72
viewsA: Problem of resourcefulness
Your second append is with the arguments in the wrong order. Note that the output value of test is List, then List is that it has to start with Dir and end with the recursion result: append([Dir],…
-
2
votes1
answer2221
viewsA: Insert an element at the beginning and end of a list in Prolog
Insert at start is trivial - [X|L]. This creates a list whose head is X and whose tail is L (the original list). To enter at the end it is necessary to scroll through the entire list, replacing the…
-
7
votes1
answer499
viewsA: Python "Attributeerror: __exit__" problem
We’re missing a open on the line: with ('arquive.txt', 'wb') as non: Thus, ('arquive.txt', 'wb') is just a tuple. The mistake is because the with expects an object with __enter__ and __exit__, what…
-
2
votes2
answers174
viewsQ: How to write the date and time of an error in the Django log?
I started a project on Django 1.4, and every mistake I picked up via try..except I printed on sys.stderr - making it fall into the same Apache log file (error.log). It worked, but only for the…
-
3
votes1
answer188
views -
11
votes2
answers2875
viewsQ: When should I use disabled, read-only or hidden fields?
If I have a form where some fields are fixed, what is the best way to present these fields to the user, from the UX point of view? A common field, disabled: <label>Foo: <select name="foo"…
-
5
votes2
answers1864
viewsA: Serialize Object to JSON
First, you need to define your fields within the __init__, and not so in the class, otherwise they will be shared by all instances of the class (i.e. they will be "static") instead of having one for…
-
9
votes1
answer101
viewsA: Pros and cons of securing an interface contract through a subclass
Ensuring that a contract is fulfilled is a desirable concept but not always feasible. Because first of all it is necessary express the terms of the contract in logic, then it is necessary prove that…
-
16
votes2
answers240
viewsQ: How do I serve a site in multiple languages in Apache?
I’m developing a website that needs to be available in 3 languages (only static content, to be served by Apache). I would like to make use of the language detection features so that the user already…
-
6
votes1
answer1202
viewsA: How to ignore elements escaped in a rule in regular expression?
You need to make the content to be married consume both the backslash and the subsequent character as if it were one thing: \\.|. That is, it houses a backslash followed by anything (2 characters),…
-
2
votes1
answer139
viewsA: Django generating strange code
The code  matches the Unicode character U+FEFF, widely used in UTF-16 encodings as "byte checkmark" (GOOD). However, some text editors (like Windows Notepad) put this BOM even in UTF-8…
-
4
votes1
answer435
viewsA: Hide Tomcat version on error pages
In itself, it’s not a security breach, but it’s still a good idea to hide that information. Because if in the future vulnerabilities are discovered in this particular version, and your service is…
-
4
votes3
answers1686
viewsA: Is saving the user ID in COOKIES safe?
Any data entered in a cookie is visible the user (if he knows how to access it, of course), as well as liability to be altered by the user. Thus, whether it is safe or not depends on which…
-
4
votes2
answers3711
viewsA: How to store Credit Card data securely?
If you do not need this data routinely, you will only have to access it in exceptional circumstances, so you can safely store it using encryption. The ideal, of course, would be to avoid this…
-
1
votes1
answer538
viewsA: Django Api: How to create a view that reset Password?
The method make_random_password of BaseUserManager can be used to create new random passwords, specifying the size (default: 10) and the alphabet (default: alphanumeric, uppercase and lowercase,…
-
5
votes1
answer118
viewsQ: Filter using calculated value does not work in Django
I have a model in Django with fields largura and comprimento, and would like to filter it by area: class Projeto(models.Model): largura = models.DecimalField(decimal_places=0, max_digits=4,…
-
5
votes5
answers4348
viewsA: How to access the value of an array through the key?
You can iterate over the keys of an object using the for..in: var arr = [ {'David': '1'}, {'Camilla': '2'}, {'Sadat': '3'}, {'Vanuza': '4'}, {'Diego': '5'} ]; arr.forEach(function(objeto) { for (…
-
1
votes2
answers928
viewsA: Typeerror: Incorrect padding
First, you are trying to use a random IV at the time of decrypt. IV must be random when encrypting, but to decrypt you must use the same IV used in the encryption (and therefore you must save IV…
-
15
votes1
answer2699
viewsQ: How does list assignment work using range?
I was reading a documentation on the internet when I came across the following code: sys.path[:0] = new_sys_path I was curious, because I had never seen intervals used on the left side of an…
-
24
votes2
answers517
viewsQ: Fielderror: Relation Fields do not support nested lookups
I’m trying to make a query in Django with several joins, and I came across this mistake that I don’t know what it means: Tag.objects.filter(dset__descendant__entities__entity=e) Fielderror: Relation…
-
2
votes2
answers1965
viewsA: Encrypt passwords as securely as possible
An alternative I think would be to encrypt the password, generate a hash to prevent it from being changed while sending to the server and generate a sort of device signature hash so the server knows…
-
1
votes1
answer614
viewsA: What are free and connected variables in Prolog?
A free variable is a variable that does not yet have a value. A linked variable is one that has (and in the absence of backtracking after a variable receives a value it is linked to it forever, it…
-
19
votes3
answers1372
viewsA: What is "Object-oriented" and what other methods?
I’ve heard a lot about "Object Oriented" programming, what other types of programming exist? Imperative, Declarative, Functional, Logical, Dataflow, Function-level, Competitor, based on Automata,…
-
4
votes1
answer144
viewsA: How does the Bennett & Brassard protocol work?
Firstly, this protocol takes two things: A quantum channel, capable of sending qubits (for example, polarized photons sent by a fiber optic cable) state carries a information (for example, a classic…
-
3
votes1
answer3392
viewsA: Adding character to a string
Even if you reinsert the withdrawn letter, you would still be creating a new string, because as you pointed out they are immutable, so both removing and placing create new objects. This can be…
-
2
votes1
answer1376
viewsA: How to use Jprogressbar while method(returns value) performs reading XML files?
How your calling code is on Event Dispatcher Thread - and it needs to complete before releasing the EDT to continue managing the Swing graphical interface - so you only have two options left: Modify…
-
3
votes1
answer1732
viewsA: replace with regular expression (regex) ignoring accents
Note: I do not know very well ASP, I will respond with the proposed logic, but the code may not be 100% correct. I suggest from the search term you create a regex for it, replacing each letter of…
-
43
votes5
answers56754
viewsA: What is the difference between syntactic error and semantic error?
Just as in natural language, programming languages are expected to arrange the various symbols in a logical way in relation to each other, just as words come together to form expressions, prayers,…
-
5
votes2
answers207
viewsA: Why do you declare yourself PUBLIC and xmlns using W3.org site?
This code example is in XHTML, a pattern that attempts to unify HTML with XML. Both languages are quite similar, but there are some crucial differences, so the need to specify a DOCTYPE. The Doctype…
-
2
votes3
answers966
viewsA: Separate a string in php?
You can use preg_split along with a regular expression. This method accepts a flag that allows the delimiter to be returned as well and included along with the results (I think it needs to be in…
-
4
votes1
answer603
viewsA: Variable type for precise calculations (JAVA)
No kind of data will solve for you the problems of precision, be floating point (double), fixed point (BigDecimal) or any other. You need to identify in what sense your calculations are accumulating…
-
2
votes2
answers230
viewsA: How to implement and use the Binarysearch method?
First, to use this method it is necessary that the list is orderly. This is a precondition for the binary search algorithm, but it doesn’t hurt to remember... Second, the method of BinarySearch with…
-
10
votes1
answer207
viewsA: Is using HTTPS enough to protect a login area?
HTTPS is the HTTP protocol over the SSL/TLS protocol. The function of SSL/TLS is to create a secure communications channel by which all client/server communication will be made. This means that:…
security-guardanswered mgibsonbr 80,631 -
4
votes3
answers1396
viewsA: Check that the mouse is not in the element
Check if the element is suffering Hover, if it is not it is because the mouse is not on it: var mouseFora = !$(meuElemento).is(":hover"); Source…