How can a ‘Request’ store a ‘Result’ code and its associated ‘Error’ code and still enforce the relationship between Result and Error?

I’m an application developer creating the database structure to represent a flat file message format. I’d like to ask the collective knowledge the best/correct way to represent the following scenario:

Request table (PK: RequestID) contains requests; a request has a Result property which is indeterminate (null) until the request has completed.

Result table (PK ResultID) is a lookup table containing (currently) two possible results:

  • Success (Result ID = 0)
  • Failure (Result ID = 1)

ErrorCode table (PK ErrorCodeID) is a lookup table containing error details and their parent ResultID:

  • No Error (ErrorCodeID = 0, ResultID = 0)
  • Generic Error (ErrorCodeID = 1, ResultID = 1)
  • Queue Full (ErrorCodeID = 2, ResultID = 1)
  • Unsupported Interface (ErrorCodeID = 3, ResultID = 1)
  • etc…

I’ve created a one to many relationship between Result (one) and ErrorCode (many). A ‘Success’ Result can only have a ‘No Error’ Error Code, while a ‘Failure’ Result can have a single error code of ‘Generic Error’, ‘Queue Full’, ‘Unsupported Interface’, etc.

When the Request has completed, I need to store the result and its associated error code.

I’ve thought of combining the two tables but that strikes me as repeating columns.

I’ve also thought of having the Request table store the ResultID and the ErrorCodeID but this doesn’t enforce the Result to ErrorCode relationship.

I’m a big believer in database that ‘defends itself’ from bad data so I want the relationship to reject a Result/ErrorCode combination that is invalid; a.k.a. a Result of ‘Success’ and an ErrorCode of ‘Generic Error’ or a Result of ‘Failure’ and an ErrorCode of ‘No Error’.

I’m also a big believer in solid initial design so when changes come down the pike at a later date (as they always do) the structure will not need rework.

Thank you in advance for your time.

Regards, John E.

Unable to get numerical result by using Integrate/NIntegrate

Nfunc[x_?NumericQ] :=   E^(-x^2/2)/    Sqrt[2*Pi]*(1/       2 Erf[(x - 0.256048)/Sqrt[2*1.6^2 + 0.231313^2]/Sqrt[2]] -      1/2 Erf[-Infinity/Sqrt[2]]) nume = N[NIntegrate[x*Nfunc[x], {x, -Infinity, Infinity},     Method -> {Automatic, "SymbolicProcessing" -> 0},     PrecisionGoal -> 3, AccuracyGoal -> 3], 4] den = N[Normal[    Integrate[Nfunc[x], {x, -Infinity, Infinity},      GenerateConditions -> False]], 4] nume/den 

I couldn’t get numerator nor denominator. It keeps "executing" for hours. Is there a mistake or isn’t mathematica able to perform this calculation?

I used functions with NumericQ for speeding up calculation, but no luck.

Returning random integer from interval based on last result and a seed

Suppose we have an interval of integers [a, b]. I would like to have a function that returns random members from within the interval, without repetitions. Once that all members within the interval are explored, the function would start to return the same first random sequence again, in the same order.

Example: a=1, b=5

3, 1, 4, 5, 2, 3, 1, 4, 5, 2, 3, 1, 4, 5, 2, ... 

This would be easy to achieve by shuffling an array of all elements between a and b, and repeating it once the array is finished. However, this would take too much memory space, and this is not suitable for my case (I might have millions of elements).

Instead, the function I’d like to have would be more or less like this:

f(a, b, n, seed) -> n+1 

Where:

a - start of interval b - end of interval n - last element returned from list seed - self-explanatory n+1 - next random element from list, calculated by using the seed and the last element returned (n) 

The trick is knowing some way to get a non-repeated number from the interval based only on the element returned before and the seed. In the end, it would behave like a circular list randomized at its initialization, but without using memory space.

What is the theoretical result of flattening a list containing only itself?

Consider the following python code

X = [None] X[0] = X 

This has many fun properties such as

X[0] == X 

and

X[0][0][0][0][0][0][0][0] == X 

I understand how this works from a practical standpoint, as it’s all just the same pointer.

Now, when flattening a list, we tend to convert things from

[[1, 2, 3], [[4, 5], [6, 7]], 8, 9] 

to

[1, 2, 3, 4, 5, 6, 7, 8, 9] 

In this case, I am considering flattening to be reducing a multi-dimensional list down to a single list of only non-list elements.

In practice, flattening this list would be impossible, as it would create an infinite loop.

This may be more mathematical in nature, but I’m unsure how to put it in mathematical terms. Suppose we could flatten this list, would the result simply be the empty list?

For context, I initially got this idea by considering the list

X = [[], []] X[0] = X 

It is clear to see that at each pass of flattening, the empty list that is the second element simply disappears. This lead me to think that the overall result, may be the empty list.

Could it be possible that flattening this list would theoretically produce an infinitely long list of the list itself, as in

X == [X, X, X, X, X, X, ..., X] 

This is purely a fun thought exercise. Any insight and discussion on this would be appreciated.

P.S. Although I’m looking for an answer in plain terms, if anyone is more mathematically inclined, I would be interested to see how this problem could be formulated in some sort of set notation. Please feel free to point me to a relevant math exchange thread as well.

P.P.S. I would also be interested in a solid proof (not formal) to go along with the answer.

Sort the result of the main Query in shop page by a custom taxonomy

In a WooCommerce site, we have products that have a custom taxonomy that are assign to a region.

When the user visits the site, we activate the browser geolocation, and we assign the user a region in a cookie.

Now we would like to show, in the shop page and in the product_cat taxonmies, in first the products that are assign to the same region of the user and then all other regions.

How could we implement this ?

So far, I taught of using pre_get_posts, and using something like :

add_action('pre_get_posts', 'order_by_region', 999999); function order_by_region($  q){  if(!is_admin() && $  q->is_main_query() && (is_shop() || is_tax('product_cat'))){   $  q->set('orderby', 'meta_value');   $  q->set('order', 'DESC');   $  q->set('value', $  _COOKIE['nameofusercookie']);   $  q->set('meta_key', 'regions');   }   return $  q; } 

But this didn’t work. I just found that in there it will filter the posts instead of ordering by regions.

I found the ‘the_posts’ hook. That contains all the products after quering but not yet looped. I think it might be better place to sort all the products with the cookie. But how do i compare the cookie and the regions taxonomy in each products ?

add_filter('the_posts', 'sort_query_by_region', 10, 2); function sort_query_by_region($  posts, $  q){  $  cookie = $  _COOKIE['selected_region'];   if(isset($  cookie) && !empty($  cookie)){   if(!is_admin() && $  q->is_main_query() && (is_shop() || is_tax('product_cat'))){    $  posts = sortByRegion($  posts);   }  }  return $  posts; }  function sortByRegion($  posts){  usort($  posts, "regionOrder");  return $  posts; }  function regionOrder($  a, $  b) {    // get the cookie    $  cookie = $  _COOKIE['slected_region'];    // Get the term region of each compared product   $  regionA = get_the_terms($  a->ID, 'regions')[0]->slug;   $  regionB = get_the_terms($  b->ID, 'regions')[0]->slug;    if($  regionA != $  cookie || $  regionB != $  cookie){    return ($  a, $  b);   } else {    return $  a < $  b;   } } 

I must that either doesn’t work.

Anyone everdone such a re-ordering and knows I to help me?

Using Ubuntu 18.04: On VestaCP installation, how to get result (https://subdomain.domain.tld:8083) instead of (https://123.312.321.23:8083) [closed]

I’m trying to install VestaCP on Ubuntu 18.04 but keep getting the following result after successful installation:

https://123.231.312.23:8083 instead of:

https://subdomain.domain.tld:8083

What do I have to do get this result: https://subdomain.domain.tld:8083?

I set hostname to server1: $ sudo hostnamectl set-hostname server1

then edit host file: $ sudo nano /etc/hosts

IP_address subdomain.domain.tld subdomain 

After all is done,I get hostname and FQDN as shown below, which is as it should be:

$   hostname server1 $   hostname -f server1.domain.tld 

But then, the result after successful installation: https://123.231.312.23:8083

What am I doing wrong?

Do any serious balance issues result from this houserule: Floating Ability Score at Character Creation?

I’ve recently been considering the phenomenon that "unusual" race-class combinations are often 1 modifier behind on their primary ability score – i.e. that they would start, using point buy or standard array, with a 15(+2) in their primary score, rather than 16 or 17 (+3). To my mind, this is a very significant mechanical effect that undesirably discourages such unusual combinations, while each race’s other qualities act as much more of a nudge than a hard barrier.

I recently came across a house-rule that would address this issue, allowing any race to achieve a 16 (assuming point buy or standard array) in their classes primary ability score at character creation, and have slightly modified it to the below.

Floating Ability Score at Character Creation

During character creation, you may remove 1 point from any racial ability score bonus you gain from your base race (but not your subrace), and add it to any other ability score which does not already gain a bonus from your race or subrace.

The original rule allowed this movement from any racial ability score, including from subraces. I have changed that because:

  1. It avoids breaking the balance of the Mountain Dwarf subrace, whose traits are designed to work against each other, and they do so much less if you can swap a point of STR for another stat
  2. Subraces are already thematically sparser than base races; the ASI is often 1 of only 2 defining traits – and you already get to pick between several subrace options anyway

I think even with that change this rule still achieves the desired goal of letting less traditional race/class combos not fall behind in their primary stat.

Are there any serious foreseeable balance issues that would arise from using this house-rule?

Double integration with a piecewise function gives wrong result

I am attempting to solve a double integral $ $ I(t) = \int_0^t dt’ \int_0^{t’} dt” f(t”)$ $ of a piecewise function of the type $ $ f(t) = \begin{cases}1 & \text{for } 0 \leq t < a \ -1 & \text{for } t>a\end{cases}$ $ with Mathematica. One can easily verify that for $ t>a$ this should evaluate to $ $ I(t) = \frac12 t (4 a – t) – a^2 $ $ However, if I try to solve in Mathematica using

Simplify[Integrate[Integrate[Piecewise[{{1, 0 <= ttt < a}, {-1, a <= ttt}}], {ttt, 0, tt}], {tt,0, t}], {t > a > 0}] 

The result I get is

-(1/2) t (-4 a + t) 

I.e. it is obviously missing the $ -a^2$ .

I am puzzled why this is happening. Am I simply too stupid to use Mathematica’s Piecewise/Integrate function correctly? If instead of the variable $ a$ I plug in a number, say 1, everything seems to evaluate correctly.

AES encryption (in Java) of different JSON strings always produce same encrypted string as result. Why?

I have a program written in Java which takes JSON string as argument, encrypts it using AES then encodes it using Base64. JSON string is like:

{"a": "b"} or {"a": "n"} or {"a": "k"}  

I.e related object would have one property a. Value part is randomly generated.

Program outputs for above JSON inputs looks like

UBNvKoRoGqk0PTQQL5K4Sw== bKwlToSND3HkceDExEDXSw== u/yKJq1FdoifBM+AnadC3A== 

i.e. they are unique.

Same goes for {"a":"gn"} — random string with length 2. Same for 3 and so on.

But starting from 7 program produces the same encoded string for different inputs. I mean following JSON strings taken as input:

{"a": "pzfovvs"} {"a": "bqwuvck"} 

produces same string as output:

Dwg0Xjkot8UBfn+vbcCfOS4KluXB6RCFQ932Y9ABtIg= 

Same goes for length 8 and 9. Starting from 10 results became unique again.

What is the explanation of this strange phenomenon?

(I can post code if needed.)

Ok, here is the code:

import java.security.Key; import java.security.NoSuchAlgorithmException; import java.util.Base64; import javax.crypto.Cipher; import javax.crypto.KeyGenerator;  public class JWTEncryptor {  private static String algorithm = "AES"; private static Key key; private static KeyGenerator keyGenerator; private static Cipher cipher;  public static String encrypt(String jwt) throws Exception {     if (key == null || cipher == null) {         setUp();     }     cipher.init(Cipher.ENCRYPT_MODE, key);     return Base64.getEncoder().encodeToString(cipher.doFinal(jwt.getBytes("UTF-8"))); }  private static void setUp() {     try {         cipher = Cipher.getInstance(algorithm);     } catch (Exception e1) {         e1.printStackTrace();     }     if (keyGenerator != null) {         key = keyGenerator.generateKey();         return;     }     try {         keyGenerator = KeyGenerator.getInstance(algorithm);         key = keyGenerator.generateKey();     } catch (NoSuchAlgorithmException e) {         e.printStackTrace();     } }  public static String decrypt(String encryptedJWT) throws Exception {     cipher.init(Cipher.DECRYPT_MODE, key);     return new     String(cipher.doFinal(Base64.getDecoder().decode(encryptedJWT))); }   }