logic

General rules for simplifying SQL statements

假如想象 提交于 2019-11-29 18:42:10
I'm looking for some "inference rules" (similar to set operation rules or logic rules) which I can use to reduce a SQL query in complexity or size. Does there exist something like that? Any papers, any tools? Any equivalencies that you found on your own? It's somehow similar to query optimization, but not in terms of performance. To state it different: Having a (complex) query with JOINs, SUBSELECTs, UNIONs is it possible (or not) to reduce it to a simpler, equivalent SQL statement, which is producing the same result, by using some transformation rules? So, I'm looking for equivalent

PHP check to make sure request is either xmlhttp from my site or normal request from a certain domain

孤街醉人 提交于 2019-11-29 18:09:24
How would the condition be written to ensure a page is either accessed by xmlhttp request from my site or from an allowed outside domain? <?php $referrer = $_SERVER['HTTP_REFERER']; if($_SERVER["HTTP_X_REQUESTED_WITH"] !== 'XMLHttpRequest') { if(preg_match("/accepteddomain.com/",$referrer) { header("Location: http://www.domain.com/desiredpage.php"); } else { header("Location: http://www.domain.com/nondesiredpage.php"); } } ?> Considering that both Referer and X-Request-With headers are sent (or not sent) by the client (the browser, or anything else that can send an HTTP request) , they cannot

Java program to find the character that appears the most number of times in a String?

…衆ロ難τιáo~ 提交于 2019-11-29 17:58:18
So here's the code I've got so far... import java.util.Scanner; class count{ public static void main(String args[]){ Scanner s=new Scanner(System.in); System.out.println("Enter a string"); String sent=s.nextLine(); int len = sent.length(); int arr[]=new int[len]; int count=1; char ch[] = new char[len]; for(int i = 0; i <= len-1; i ++) { ch[i] = sent.charAt(i); } for(int j= 0;j<=len-1;j++){ for(int k=0;k<=len-1;k++){ if(ch[j]==ch[k]){ arr[j]= count++; } } } int max=arr[0]; for(int z=1;z<=len-1;z++){ if(count>max) max=count; } System.out.println(max); System.out.println("The character that

Hungarian Algorithm: How to cover 0 elements with minimum lines?

巧了我就是萌 提交于 2019-11-29 17:43:41
问题 I am trying to implement the Hungarian algorithm in Java. I have an NxN cost matrix. I am following this guide step by step. So I have the costMatrix[N][N] and 2 arrays to track covered rows and covered cols - rowCover[N], rowColumn[N] (1 means covered, 0 means uncovered) How can I cover the 0s with the minimum number of lines? Can anyone point me in the right direction? Any help/suggestion would be appreciated. 回答1: Check the 3rd step of the algorithm in the Wikipedia article (section Matrix

NASM Assembly mathematical logic

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 17:34:32
I have a program in assembly for the Linux terminal that's supposed to work through a series of mathematical manipulations, compare the final value to 20, and then using if logic, report <, > or = relationship. Code is: segment .data out_less db "Z is less than 20.", 10, 0 out_greater db "Z is greater than 20.", 10, 0 out_equal db "Z is equal to 20.", 10, 0 segment .bss segment .text global main extern printf main: mov eax, 10 mov ebx, 12 mov ecx, eax add ecx, ebx ;set c (ecx reserved) mov eax, 3 mov ebx, ecx sub ebx, eax ;set f (ebx reserved) mov eax, 12 mul ecx add ecx, 10 ;(a+b*c) (ecx

1 = false and 0 = true?

ぃ、小莉子 提交于 2019-11-29 16:49:30
问题 I came across an is_equals() function in a c API at work that returned 1 for non-equal sql tables (false) and 0 for equal ones (true). I only realized it after running test cases on my code, one for the positive example and one for the negative and they both failed which at first made little sense. The code in the API does not have a bug as the output was recorded correctly in its documentation. My questions - are there upside down worlds / parallel universes / coding languages where this

Understanding Modified Baugh-Wooley multiplication algorithm

雨燕双飞 提交于 2019-11-29 16:20:51
For Modified Baugh-Wooley multiplication algorithm , why is it !(A0*B5) instead of just (A0*B5) ? Same questions for !(A1*B5), !(A2*B5), !(A3*B5), !(A4*B5), !(A5*B4), !(A5*3), !(A5*B2), !(A5*B1) and !(A5*B0) Besides, why there are two extra '1' ? In signed 6-bit 2s complement notation, the place values of the bits are: -32 16 8 4 2 1 Notice that the top bit has a negative value. When addition, subtraction, and multiplication are performed mod 64, however, that minus sign makes absolutely no difference to how those operations work, because 32 = -32 mod 64. Your multiplication is not being

How to open blobs on browser without downloading through java service?

烂漫一生 提交于 2019-11-29 15:59:56
I am creating an application where I need to view blobs in browser rather than downloading them. Currently, links of blobs having token downloads the corresponding blob. I got some reference here to view the blobs in browser : https://github.com/Azure-Samples/storage-blob-java-getting-started/blob/master/src/BlobBasics.java (See from line number 141) Here is my code to create token : @Test public String testBlobSaS(CloudBlob blob, CloudBlobContainer container) throws InvalidKeyException, IllegalArgumentException, StorageException, URISyntaxException, InterruptedException {

Python Deleting Certain File Extensions

狂风中的少年 提交于 2019-11-29 15:34:47
问题 I'm fairly new to Python, but I have gotten this code to work, and in fact, do what it's intended to do. However, I'm wondering if there is a more efficient way to code this, perhaps to enhance the processing speed. import os, glob def scandirs(path): for currentFile in glob.glob( os.path.join(path, '*') ): if os.path.isdir(currentFile): print 'got a directory: ' + currentFile scandirs(currentFile) print "processing file: " + currentFile png = "png"; jpg = "jpg"; if currentFile.endswith(png)

What is meant by “logical purity” in Prolog?

送分小仙女□ 提交于 2019-11-29 13:12:21
What is meant by "logical purity" (in the context of Prolog programming)? The logical-purity tag info says "programs using only Horn clauses" , but then, how would predicates like if_/3 qualify, using as much as it does the cut, and the various meta-logical (what's the proper terminology? var/1 and such) predicates, i.e. the low-level stuff. I get it that it achieves some "pure" effect, but what does this mean, precisely? For a more concrete illustration, please explain how does if_/3 qualify as logically pure, seen in use e.g. in this answer ? Let us first get used to a declarative reading of