## Design a data model to store N datasets along with the values of N parameters sets and the results of runs using the parameter values on the datasets

Let’s say we have N different input static datasets D_n, for example (don’t focus on the example but more on the concept here) using N=3;
a dataset D_1 composed of images,
a dataset D_2 of features
and a dataset D_3 of objects.

On each dataset, I can apply some parameters P_n to do some (simple or sometime quite complex) computations on it.

Let’s call a ‘run’, the results of the combination of the application of
some defined set of values for the image parameters P_1 applied to the images dataset D_1 (which would lead to some processed data D_1′ corresponding to the dataset D_1) +
some defined set values of the features parameters P_2 applied to the features dataset D_2 (which would lead to some processed data D_2′ corresponding to the dataset D_2) +
some defined set of values of the object parameters P_3 applied to the object dataset D_3 (which would lead to some processed data D_3′ corresponding to the dataset D_3) .

How would you designed a relational database (I’m using PostgreSQL but I guess it’s not important at this stage) so that we can store both 1) the results of each and every run using different sets of defined values for the parameters P_n on the datasets D_n and 2) the values or the parameters used for getting these results.

For the moment, each time I want to run the computations using different parameter values, I change these values in a config file, overwriting the previous ones, and I output results to files on the disk, which also got overwritten for each new run. But I’d like to keep them all now.
Another problem that I have is that I’m writing images and some geographical data on the disk, mainly raster files, which are quite huge, therefore it would probably not be a good idea to store them in the database but only keeping a link (to the file) in the DB.
Last but not least, if I store values for parameters in a `parameter` table in my database, I cannot run the computation in parallel on the same database as I would need different values setup in the same table for two different runs.

That’s why I’m searching to better design and organize my datasets and parameters when playing with different sets of values.

## webserver – How strict should I be in rejecting unexpected HTTP request parameters redux?

I read this: How strict should I be in rejecting unexpected query parameters?

Answer: No, do not error out on unexpected query string parameters.

But I just got a requirement from our security guy that I must do so. Not only for unexpected query string, but also unexpected cookies, headers, and unexpected everything. Reasoning:

It is possible that some component in the tech stack has a vulnerability like buffer overflow, sql injection, or other vulnerabilities of this sort. Unexpected data in requests may be a malicious attempt to find and exploit such a vulnerability. Therefore it is needed to return a 4xx response in such a situation. The blackbox should be configured to detect a spike of 4xx responses and react appropriately: ban the ip that produces such responses, notify the admin that the server is under attack, and the likes. The 4xx response is not meant for the attacker but for our security systems.

I don’t know… it seems to make sense, but it contradicts advice found in stack exchange sites.

Where is the error of such reasoning?

## mysql – mysqli_query() expects at least 2 parameters, 1 given in Inicio de sesión

soy nuevo en esto de MySQL y PHP.

Tengo un codigo que es de inicio de sesión algo viejo que usa mysql_query(), sin embargo si lo pongo como mysqli_query() me da el siguiente error:

Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/path/index.php on line 26

Las lineas que dan el error son estas:

``````\$query =mysqli_query("SELECT * FROM usertbl WHERE username='".\$username."' AND password='".\$password."'");

\$numrows=mysqli_num_rows(\$query);
if(\$numrows!=0)

{
while(\$row=mysqli_fetch_assoc(\$query))
``````

Que podré hacer para corregirlo?

I’m having problems after configuring recaptcha, it generates the following warning "Recaptcha required parameters are missing!". Has anyone had this problem?

## physics – How to make a variable height jump controlled by parameters?

I’m trying to make a variable height jump controlled by parameters. I want to be able to specify the max height of my jump, and a time to max height. I also want to be able to specify a min jump height.
My understanding is we construct a jump by using max_height and time_to_max to calculate gravity.

``````func gravity(height, peak_time):
return -2 * height / pow(peak_time * 2, 2)
``````

Because min_jump_height uses the same gravity as max jump height, it’s time to peak is not determined directly, but through the other variables. I calculate my initial velocity based on my min_jump_height and gravity:

``````func initial_velocity(gravity, min_height):
return sqrt(2 * -gravity * min_height)
``````

As usual, I apply gravity each frame:

``````velocity += gravity * delta
``````

How do I make it so that each frame the jump button is held a little more is added to velocity such that the original peak height is hit at peak time? This is, in effect, compensating through interpolation for if my initial velocity had been targeted to my max_height instead of my min_height. I imagine there might be more than one valid form of interpolation to solve this problem and I’d be interested in any of them, but the simplest will do.

## How to match only part of URL and redirect URL with parameters in .htaccess?

If the query string is irrelevant then it can simply be ignored. (You can’t match the query string anyway with the `RewriteRule` directive.)

Try the following in your root .htaccess file to redirect the request:

``````RewriteEngine On
RewriteRule ^index.php/path/some-path/some-subpath\$ /category/? (L,R=301)
``````

In per-directory .htaccess files, the URL-path matched by the `RewriteRule` pattern has the directory-prefix removed. In other words, it does not start with a slash, `^index.php....` instead of `^/index.php....`.

The `?` on the end of the `RewriteRule` substitution is required in order to remove the query string (if any) from the request. Otherwise `parameter=1` will be passed through and appended to the target URL.

This will match any query string, including an empty one.

## 8 – How to set required POST parameters for routes

With GET method we can do something like this

``````example.user
path: 'example/{user}'
defaults:
_controller: 'DrupalexampleControllerExampleController::content'
requirements:
_permission: 'access content'
user: ^(a-zA-Z0-9_)+
``````

so it sets `user` param as required and also limits its format.

But I’d like to do something similar with POST method. Tried this, but not working:

``````example.user
path: 'example'
methods:  (POST)
defaults:
_controller: 'DrupalexampleControllerExampleController::content'
requirements:
_permission: 'access content'
user: ^(a-zA-Z0-9_)+
``````

EDIT:

Sure I can set some logic inside controller like this, but it doesn’t feel right:

``````public function store(Request \$request) {
\$params = json_decode(\$request->getContent(), TRUE);
//I'm trying to avoid using these conditions inside controller methods
if(empty(\$params('user'))){
//return error response
}else{
if (!preg_match('/^(a-zA-Z0-9_)+/', \$params('user'))) {
//return error response
}
}
//return success response
}
``````

So what’s drupal way to do it?

## c# – Refactoring constructor that has too many parameters

You are right, 8 parameters -all strings- makes the constructor a good candidate for a code review.

Consider some of the next points.

### Essential attributes first

Look the message model and figure out which attributes are necessary to initialize an instance in a consistent state. Reduce the number of arguments to the essential. Add setters or functions for the rest.

If all 8 attributes are required and read-only, there’s not too much to do.

### Encapsulation

Consider encapsulating correlated parameters. For example, A, B and C might be placed together into a new class. Find out which parameters change together, at the same time, due to the same reasons.

It reduces the number of arguments at the cost of one more class (complexity).

### Use creational patterns

Instead of initializing messages directly from any place in the code source, do It from factories or builders.

### Arrays

If none of the above works, try an array of parameters. Given the lack of meaningful param’s names, it’s probably the simplest solution.

Regarding arrays, I posted a question where I ask about its suitability. I was reluctant to trust in such a solution. However, the answers helped me out to be less reticent, so check it out if you also dislike this solution. It might change your mind about this.

### Inheritance

Eventually, you will realise that messages are good candidates for inheritance. Segmenting messages by attribute generates a little overhead because sooner than later you ends up asking for the type `if(message.getType() == ...)` all over the code.

## Solving coupled ODE symbolically for the parameters

I’m trying to solve the following system:

$$dot{x_1} = -i w_1 x_1+ i s_1 x_2$$
$$dot{x_2} = -i w_2 x_2- i s_2 x_1$$

For $$X(t)_{1,2}$$,
where $$x_{1,2} = X(t)_{1,2}cdot e^{ip(t)_{1,2}}$$

I know the solution is:

$$dot{X_1}=s_1X_2sin(p_1 – p_2)$$
$$dot{X_2}=s_2X_1sin(p_1 – p_2)$$

I tried the following:

``````x1 = X1(t)*E^(I*p1(t));
x2 = X2(t)*E^(I*p2(t));

x1dot = -I*w1*x1 + I*s1*x2;
x2dot = -I*w2*x2 + I*s2*x1;

x1d = D(x1, t);
x2d  = D(x2, t);

{{X1s(t), X2s(t)}} =
{X1(t), X2(t)} /.
Simplify(
Solve(
{x1d == x1dot, x2d == x2dot},
{X1(t), X2(t)}))
``````

But The result I get is:

$$-frac{i left(text{x1d} text{p2}'(t)+text{s1} e^{i text{p2}(t)} text{X2}'(t)+text{w2} text{x1d}right)}{e^{i text{p1}(t)} left(-text{w1} text{p2}'(t)+text{s1} text{s2}-text{w1} text{w2}right)},-frac{i left(text{w1} text{X2}'(t)+frac{text{s2} text{x1d}}{e^{i text{p2}(t)}}right)}{-text{w1} text{p2}'(t)+text{s1} text{s2}-text{w1} text{w2}}$$

I’m not sure if Mathematica can use Euler’s formula to simplify the complex exponents and get to the known solution. I guess it’s possible but I’m not sure how to do it