qid int64 1 74.7M | question stringlengths 15 58.3k | date stringlengths 10 10 | metadata list | response_j stringlengths 4 30.2k | response_k stringlengths 11 36.5k |
|---|---|---|---|---|---|
3,318,704 | I have an existing database that holds information about upcoming meetings in my organization. I would like to be able to display this information in datatable type of format upon which I can then filter and sort the information (possibly jquery sort).
Can anyone point me to some kind of tutorial that would give me an ... | 2010/07/23 | [
"https://Stackoverflow.com/questions/3318704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/306894/"
] | You might consider youing the table wizard project to incorporate this data into drupal.
<http://www.lullabot.com/articles/drupal-data-imports-migrate-and-table-wizard>
It allows you to view the data and import it into your drupal project very easily. | If you have your own table. Cck and views won't be much help to you. However you can still do db\_query to get the data and theme\_table will help you display. From the docs it looks like theme table will do some sorting for you but I haven't tried this. |
3,318,704 | I have an existing database that holds information about upcoming meetings in my organization. I would like to be able to display this information in datatable type of format upon which I can then filter and sort the information (possibly jquery sort).
Can anyone point me to some kind of tutorial that would give me an ... | 2010/07/23 | [
"https://Stackoverflow.com/questions/3318704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/306894/"
] | [Views](http://drupal.org/project/views "Views") will handle any data manipulation (like filtering and sorting) you might want to do; and Views 3 can utilize any backend datasource (previously, you needed to use Drupal's database). If you want this to be robust and not a one-time import, Views is likely the way to go.
... | If you have your own table. Cck and views won't be much help to you. However you can still do db\_query to get the data and theme\_table will help you display. From the docs it looks like theme table will do some sorting for you but I haven't tried this. |
3,318,704 | I have an existing database that holds information about upcoming meetings in my organization. I would like to be able to display this information in datatable type of format upon which I can then filter and sort the information (possibly jquery sort).
Can anyone point me to some kind of tutorial that would give me an ... | 2010/07/23 | [
"https://Stackoverflow.com/questions/3318704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/306894/"
] | [Views](http://drupal.org/project/views "Views") will handle any data manipulation (like filtering and sorting) you might want to do; and Views 3 can utilize any backend datasource (previously, you needed to use Drupal's database). If you want this to be robust and not a one-time import, Views is likely the way to go.
... | You might consider youing the table wizard project to incorporate this data into drupal.
<http://www.lullabot.com/articles/drupal-data-imports-migrate-and-table-wizard>
It allows you to view the data and import it into your drupal project very easily. |
42,763,111 | I have a large set of JavaScript snippets each containing a line like:
```
function('some string without numbers', '123,71')
```
and I'm hoping to get a regex together to pull the numbers from the second argument. The second argument can contain an arbitrary number of comma separated numbers (inlcuding zero numbers)... | 2017/03/13 | [
"https://Stackoverflow.com/questions/42763111",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1314314/"
] | In your case, you may match and *capture* the digits inside the single quotes and then split them with a comma:
```js
var s = "function('some string without numbers', '123,71')";
var res = s.match(/'([\d,]+)'/) || ["", ""];
console.log(res[1].split(','));
```
The `/'([\d,]+)'/` regex will match a `'`, then 1+ digit... | If you have a numbers in a variable `x` like this:
```
var x = '55,1,6000';
```
then use this to have the list of numbers:
```
var array = x.split(',');
```
If you can have some whitespace before/after the comma then use:
```
var array = x.split('\s*,\s*');
```
or something like that.
Sometimes it is easier t... |
3,999,628 | I was reading an example of the application of the Argument Principle and I encountered the following reasoning, which I do not understand.
At a certain point in the example, we consider $f(iy)=(y^4 − 4y^2 + 3)+i(-y^3+2y)$ and the following asseveration is made: since $\lim\_{y\to \infty}\frac{-y^3+2y}{y^4 − 4y^2 + 3}... | 2021/01/25 | [
"https://math.stackexchange.com/questions/3999628",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/716468/"
] | $$(y^4 − 4y^2 + 3)+i(-y^3+2y)=y^3[(y-4/y+3/y^2)-i(1-2/y^2)] $$
$$\arg f(iy)= \tan^{-1} \frac{2/y^2-1}{y-4/y+3/y^2} \approx -\tan^{-1} \frac{1}{y}\to 0.$$ | **Not an answer**
$(p=\text{Re }z=t^4-4 t^2+3,q=\text{Im }z=2 t-t^3)$
eliminating the parameter $t$ I got the cartesian equation of the curve
$$-p^3+p^2-4 p q^2+5 p+q^4-4 q^2+3=0$$
that I used to get the plot in the image below.
If you manage to plot the curve for huge values of $q$ you will see that $\arg z\to 0$ a... |
19,323,947 | Given the following C code, what is the difference between `a = f;` and `a = (int *) f;`?
```
float *f;
int *a;
...
a = f;
a = (int *) f;
``` | 2013/10/11 | [
"https://Stackoverflow.com/questions/19323947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/571828/"
] | ```
float *f;
int *a;
a = f;
```
This assignment is erroneous (there is a C constraint violation), there is no implicit conversion between pointer types (except with `void *`). A compiler can refuse to compile a program with this assignment. | `a = (int*) f;` makes explicit that you want to cast a `float*` pointer to an `int*` pointer. Without it, you'll receive an incompatible pointer types error. |
19,323,947 | Given the following C code, what is the difference between `a = f;` and `a = (int *) f;`?
```
float *f;
int *a;
...
a = f;
a = (int *) f;
``` | 2013/10/11 | [
"https://Stackoverflow.com/questions/19323947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/571828/"
] | `a = (int*) f;` makes explicit that you want to cast a `float*` pointer to an `int*` pointer. Without it, you'll receive an incompatible pointer types error. | ```
a = f; //assignment
// is a constraint violation
a = (int *) f; //cast + assignment
```
Explicitly casting float pointer to int pointer.simply hides compiler warnings or errors.
but very well might crash when running as the sizes of what the program expects when dereferencing the pointer differs from reality. |
19,323,947 | Given the following C code, what is the difference between `a = f;` and `a = (int *) f;`?
```
float *f;
int *a;
...
a = f;
a = (int *) f;
``` | 2013/10/11 | [
"https://Stackoverflow.com/questions/19323947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/571828/"
] | ```
float *f;
int *a;
a = f;
```
This assignment is erroneous (there is a C constraint violation), there is no implicit conversion between pointer types (except with `void *`). A compiler can refuse to compile a program with this assignment. | 6.5.16.1 Simple assignment
--------------------------
>
> the left operand has atomic, qualified, or unqualified pointer type, and (considering
> the type the left operand would have after lvalue conversion) both operands are
> pointers to qualified or unqualified versions of **compatible types**, and the type pointe... |
19,323,947 | Given the following C code, what is the difference between `a = f;` and `a = (int *) f;`?
```
float *f;
int *a;
...
a = f;
a = (int *) f;
``` | 2013/10/11 | [
"https://Stackoverflow.com/questions/19323947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/571828/"
] | 6.5.16.1 Simple assignment
--------------------------
>
> the left operand has atomic, qualified, or unqualified pointer type, and (considering
> the type the left operand would have after lvalue conversion) both operands are
> pointers to qualified or unqualified versions of **compatible types**, and the type pointe... | ```
a = f; //assignment
// is a constraint violation
a = (int *) f; //cast + assignment
```
Explicitly casting float pointer to int pointer.simply hides compiler warnings or errors.
but very well might crash when running as the sizes of what the program expects when dereferencing the pointer differs from reality. |
19,323,947 | Given the following C code, what is the difference between `a = f;` and `a = (int *) f;`?
```
float *f;
int *a;
...
a = f;
a = (int *) f;
``` | 2013/10/11 | [
"https://Stackoverflow.com/questions/19323947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/571828/"
] | ```
float *f;
int *a;
a = f;
```
This assignment is erroneous (there is a C constraint violation), there is no implicit conversion between pointer types (except with `void *`). A compiler can refuse to compile a program with this assignment. | ```
a = f; //assignment
// is a constraint violation
a = (int *) f; //cast + assignment
```
Explicitly casting float pointer to int pointer.simply hides compiler warnings or errors.
but very well might crash when running as the sizes of what the program expects when dereferencing the pointer differs from reality. |
19,323,947 | Given the following C code, what is the difference between `a = f;` and `a = (int *) f;`?
```
float *f;
int *a;
...
a = f;
a = (int *) f;
``` | 2013/10/11 | [
"https://Stackoverflow.com/questions/19323947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/571828/"
] | ```
float *f;
int *a;
a = f;
```
This assignment is erroneous (there is a C constraint violation), there is no implicit conversion between pointer types (except with `void *`). A compiler can refuse to compile a program with this assignment. | Your code will compile (at least in my linux and gcc). But you will get a warning.
If you use `a = f;` and then use `a` somewhere in your code, you will get erroneous data, because a float is stored in a different format in memory. Even if you do the casting first you probably will get erroneous results, but the compil... |
19,323,947 | Given the following C code, what is the difference between `a = f;` and `a = (int *) f;`?
```
float *f;
int *a;
...
a = f;
a = (int *) f;
``` | 2013/10/11 | [
"https://Stackoverflow.com/questions/19323947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/571828/"
] | ```
float *f;
int *a;
a = f;
```
This assignment is erroneous (there is a C constraint violation), there is no implicit conversion between pointer types (except with `void *`). A compiler can refuse to compile a program with this assignment. | Given:
```
float *f;
int *a;
```
This:
```
a = f;
```
is a *constraint violation*. It requires a *diagnostic* from any conforming compiler. After issuing the required diagnostic, it may or may not reject the program. (IMHO it should do so.) A conforming compiler may choose to accept it with a mere warning (which ... |
19,323,947 | Given the following C code, what is the difference between `a = f;` and `a = (int *) f;`?
```
float *f;
int *a;
...
a = f;
a = (int *) f;
``` | 2013/10/11 | [
"https://Stackoverflow.com/questions/19323947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/571828/"
] | Your code will compile (at least in my linux and gcc). But you will get a warning.
If you use `a = f;` and then use `a` somewhere in your code, you will get erroneous data, because a float is stored in a different format in memory. Even if you do the casting first you probably will get erroneous results, but the compil... | ```
a = f; //assignment
// is a constraint violation
a = (int *) f; //cast + assignment
```
Explicitly casting float pointer to int pointer.simply hides compiler warnings or errors.
but very well might crash when running as the sizes of what the program expects when dereferencing the pointer differs from reality. |
19,323,947 | Given the following C code, what is the difference between `a = f;` and `a = (int *) f;`?
```
float *f;
int *a;
...
a = f;
a = (int *) f;
``` | 2013/10/11 | [
"https://Stackoverflow.com/questions/19323947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/571828/"
] | Given:
```
float *f;
int *a;
```
This:
```
a = f;
```
is a *constraint violation*. It requires a *diagnostic* from any conforming compiler. After issuing the required diagnostic, it may or may not reject the program. (IMHO it should do so.) A conforming compiler may choose to accept it with a mere warning (which ... | ```
a = f; //assignment
// is a constraint violation
a = (int *) f; //cast + assignment
```
Explicitly casting float pointer to int pointer.simply hides compiler warnings or errors.
but very well might crash when running as the sizes of what the program expects when dereferencing the pointer differs from reality. |
57,642,115 | I'm writing a website, and part of it requires some text to appear as if it's being typed. However, one of my functions to do this (`typewriter2`) isn't working, even though it's called.
I've tried moving around the code, and testing it separately. The code runs fine, however the `typewriter2` function just won't star... | 2019/08/24 | [
"https://Stackoverflow.com/questions/57642115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11972820/"
] | Using global variables will hurt you. It makes the code unpredictable, especially if you use the same variable in more than one function.
Another thing: Don't query the DOM for the element every time you need the element: Querying the DOM is expensive and should be avoided if possible (in your code it dosen't matter, ... | The issue was that `i` was not set to the correct value, and had to be renamed. |
15,187,699 | I am trying to create a Login with AJAX and PHP to display error messages more smoother.
My HTML
```
<form>
<input type="email" placeholder="Email Address" id="loginMail" name="loginMail" class="text">
<input type="password" placeholder="Password" id="pass" name="pass" class="text"><br><br>
<input type=... | 2013/03/03 | [
"https://Stackoverflow.com/questions/15187699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1815940/"
] | If you want to use `send_mail`, you'll have to create your own [email backend](https://docs.djangoproject.com/en/dev/topics/email/#defining-a-custom-email-backend) which uses your custom settings and then pass it to `send_mail` in the `connection` attribute. | Sending mail with **a custom configured SMTP setting in the admin page which is independent of the Django setting:**
```
from django.core import mail
from django.core.mail.backends.smtp import EmailBackend
from <'Your SMTP setting in admin'> import <'Your model'>
def send_mail(subject, contact_list, body):
try:
... |
15,187,699 | I am trying to create a Login with AJAX and PHP to display error messages more smoother.
My HTML
```
<form>
<input type="email" placeholder="Email Address" id="loginMail" name="loginMail" class="text">
<input type="password" placeholder="Password" id="pass" name="pass" class="text"><br><br>
<input type=... | 2013/03/03 | [
"https://Stackoverflow.com/questions/15187699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1815940/"
] | If you want to use `send_mail`, you'll have to create your own [email backend](https://docs.djangoproject.com/en/dev/topics/email/#defining-a-custom-email-backend) which uses your custom settings and then pass it to `send_mail` in the `connection` attribute. | This works for me
```py
from django.core.mail import EmailMessage
from django.core.mail.backends.smtp import EmailBackend
config = Configuration.objects.get(**lookup_kwargs)
try:
backend = EmailBackend(
host=config.host,
port=config.port,
password=config.password,
username=config... |
15,187,699 | I am trying to create a Login with AJAX and PHP to display error messages more smoother.
My HTML
```
<form>
<input type="email" placeholder="Email Address" id="loginMail" name="loginMail" class="text">
<input type="password" placeholder="Password" id="pass" name="pass" class="text"><br><br>
<input type=... | 2013/03/03 | [
"https://Stackoverflow.com/questions/15187699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1815940/"
] | This works for me
```py
from django.core.mail import EmailMessage
from django.core.mail.backends.smtp import EmailBackend
config = Configuration.objects.get(**lookup_kwargs)
try:
backend = EmailBackend(
host=config.host,
port=config.port,
password=config.password,
username=config... | Sending mail with **a custom configured SMTP setting in the admin page which is independent of the Django setting:**
```
from django.core import mail
from django.core.mail.backends.smtp import EmailBackend
from <'Your SMTP setting in admin'> import <'Your model'>
def send_mail(subject, contact_list, body):
try:
... |
1,674,062 | Have a question about the design/usage of asp.net mvc here.
In the html helper class, you can get to the current controller by Html.ViewContext.Controller. Moreover, you can get to the request, route collection and much more from the html helper class.
Doesn't this go against the rule of MVC? Doesn't this opens up a ... | 2009/11/04 | [
"https://Stackoverflow.com/questions/1674062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31206/"
] | Use a strong typed ViewModel, so your view is only dependant of it and not of the controller who generates it | >
> Doesn't this go against the rule of MVC?
>
>
>
Yes, it goes.
>
> Doesn't this opens up a ways for developer to do heavy controller dependent code in views?
>
>
>
Yes, it opens that door. It needs to be avoided.
>
> what's the best practice use case for current viewcontext and controller from the html h... |
1,674,062 | Have a question about the design/usage of asp.net mvc here.
In the html helper class, you can get to the current controller by Html.ViewContext.Controller. Moreover, you can get to the request, route collection and much more from the html helper class.
Doesn't this go against the rule of MVC? Doesn't this opens up a ... | 2009/11/04 | [
"https://Stackoverflow.com/questions/1674062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31206/"
] | >
> Doesn't this go against the rule of MVC?
>
>
>
Yes, it goes.
>
> Doesn't this opens up a ways for developer to do heavy controller dependent code in views?
>
>
>
Yes, it opens that door. It needs to be avoided.
>
> what's the best practice use case for current viewcontext and controller from the html h... | Simple answer is no, generally a view should not be dependant on a controller.
To elaborate a bit on what was already said; there are plenty of ways to shoot yourself in the foot using ASP.Net MVC if you're not careful. The basic concept helps, but there is no way to make it foolproof and still remain flexible enough ... |
1,674,062 | Have a question about the design/usage of asp.net mvc here.
In the html helper class, you can get to the current controller by Html.ViewContext.Controller. Moreover, you can get to the request, route collection and much more from the html helper class.
Doesn't this go against the rule of MVC? Doesn't this opens up a ... | 2009/11/04 | [
"https://Stackoverflow.com/questions/1674062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31206/"
] | Use a strong typed ViewModel, so your view is only dependant of it and not of the controller who generates it | Simple answer is no, generally a view should not be dependant on a controller.
To elaborate a bit on what was already said; there are plenty of ways to shoot yourself in the foot using ASP.Net MVC if you're not careful. The basic concept helps, but there is no way to make it foolproof and still remain flexible enough ... |
60,062,520 | I have spent many hours researching this problem and trying various solutions but I never quite find a suitable solution for my specific problem. I am new to SQL and some of the examples are confusing as well.
So here is my dilemma. I have a equipment table that tracks oil changes for specific units in a database. The... | 2020/02/04 | [
"https://Stackoverflow.com/questions/60062520",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8097937/"
] | First create a unique partial index for the column `UnitID`:
```
CREATE UNIQUE INDEX idx_unit ON tablename(UnitID)
WHERE Date_Completed IS NULL;
```
so that only 1 row with `Date_Completed=null` is allowed for each `UnitID`.
So a statement like this:
```
INSERT INTO tablename(id, UnitID, Posted_On, Date_Comple... | Firstly I would use a view rather than a table to store any calculated data - it reduces storage overheads and will update the calculation every time the view is opened.
If you're using SQLite you should be able to get the overdue by subtracting the Posted\_On from its function to return today's date something like `da... |
60,062,520 | I have spent many hours researching this problem and trying various solutions but I never quite find a suitable solution for my specific problem. I am new to SQL and some of the examples are confusing as well.
So here is my dilemma. I have a equipment table that tracks oil changes for specific units in a database. The... | 2020/02/04 | [
"https://Stackoverflow.com/questions/60062520",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8097937/"
] | First create a unique partial index for the column `UnitID`:
```
CREATE UNIQUE INDEX idx_unit ON tablename(UnitID)
WHERE Date_Completed IS NULL;
```
so that only 1 row with `Date_Completed=null` is allowed for each `UnitID`.
So a statement like this:
```
INSERT INTO tablename(id, UnitID, Posted_On, Date_Comple... | I think you need something like this:
```
MERGE INTO EQUIPMENT A
USING (SELECT * FROM EQUIPMENT B WHERE DATE_COMPLETED IS NULL) C
ON (A.UNITID=C.UNITID)
WHEN MATCHED THEN UPDATE SET A.OVERDUEBY="new value"
WHEN NOT MATCHED THEN INSERT (A.id,A.UnitID,A.Posted_On,A.Date_Completed,A.Note,A.OverDueBy)
VALUES (C.id,C.Un... |
51,979,608 | I have a javafx application. Initially it loads a login page using WebView. Login page takes user name and redirects to another page. In this html page I have a function inside javascript. I want to call a java method while executing the script. but I end up getting an error saying
```
ReferenceError: Can't find vari... | 2018/08/23 | [
"https://Stackoverflow.com/questions/51979608",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4081897/"
] | I have found the answer.
Since after login it redirects to an URL. I had to add a listener with documentProperty(). Inside I add the code for calling java method from javascript. So while loading the page I don't get `ReferenceError: Can't find variable: OpenDoc[at 17]` message since I added the reference already. her... | First you have to enable JavaScript on the `WebEngine`
```
webEngine.setJavaScriptEnabled(true);
```
and this line will do the trick
```
webengine.executeScript("initOpenDoc(\"ID\")");
``` |
31,705 | I mean CACHE from InterSystems (<http://www.intersystems.com/cache/>)
Does this database stable enough ?
Does the vendor provide prompt support for issues and bugs ?
Will the database files grow faster (comparing with the same amount of data in traditional RDBMS) ?
I would like to read an opinion of a DBA who have ev... | 2009/06/25 | [
"https://serverfault.com/questions/31705",
"https://serverfault.com",
"https://serverfault.com/users/9838/"
] | The MP is artificially expensive as it supports being used in configurations with more than two sockets. In practice, you can view the DP as simply a crippled version of the MP fiddled so it won't work in multi-socket configurations.
The MP is almost identical to the DP and almost certainly no more physically difficul... | While I'm sure there are feature differences, I highly doubt that there is a major "technical" answer. Production line tool-up, poor yields on a new chip, and overall fab capacity probably account for the lion's share of the costs to Intel. Having said that, I can't imagine it really costs Intel that much more to make ... |
31,705 | I mean CACHE from InterSystems (<http://www.intersystems.com/cache/>)
Does this database stable enough ?
Does the vendor provide prompt support for issues and bugs ?
Will the database files grow faster (comparing with the same amount of data in traditional RDBMS) ?
I would like to read an opinion of a DBA who have ev... | 2009/06/25 | [
"https://serverfault.com/questions/31705",
"https://serverfault.com",
"https://serverfault.com/users/9838/"
] | While I'm sure there are feature differences, I highly doubt that there is a major "technical" answer. Production line tool-up, poor yields on a new chip, and overall fab capacity probably account for the lion's share of the costs to Intel. Having said that, I can't imagine it really costs Intel that much more to make ... | The cost of CPU's has very little to do with what it actually does and everything to do with how many of them can be crammed into a single silicon die, and how many of them are likely to be sold. Even if they are almost identical physically if Intel sell 500k 5400's vs 50k 7000's then the cost of the 7000's will have t... |
31,705 | I mean CACHE from InterSystems (<http://www.intersystems.com/cache/>)
Does this database stable enough ?
Does the vendor provide prompt support for issues and bugs ?
Will the database files grow faster (comparing with the same amount of data in traditional RDBMS) ?
I would like to read an opinion of a DBA who have ev... | 2009/06/25 | [
"https://serverfault.com/questions/31705",
"https://serverfault.com",
"https://serverfault.com/users/9838/"
] | The MP is artificially expensive as it supports being used in configurations with more than two sockets. In practice, you can view the DP as simply a crippled version of the MP fiddled so it won't work in multi-socket configurations.
The MP is almost identical to the DP and almost certainly no more physically difficul... | The cost of CPU's has very little to do with what it actually does and everything to do with how many of them can be crammed into a single silicon die, and how many of them are likely to be sold. Even if they are almost identical physically if Intel sell 500k 5400's vs 50k 7000's then the cost of the 7000's will have t... |
13,460,571 | Sorry for the confusing question but here's what i'm trying to do. I have a page with multiple (ul) items. I'm using jquery to manipulate the classes of the (ul)'s and (li)'s. What i'm trying to do is treat each (ul) as an individual as oppose to a whole. For example my:
```
<ul class="bNav">
<li><a href="#">Home</a... | 2012/11/19 | [
"https://Stackoverflow.com/questions/13460571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/584765/"
] | From the docs:
***.is()***
Check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments.
Try:
```
$('.bNav.opp').addClass('nav').wrap('<nav class="navbar navbar-inverse"><div class="navbar-inner">');
$('.bNa... | Use an `.each` loop (and try `.hasClass()` instead):
```
$('.bNav').each(function(i,el) {
if ($(this).hasClass('opp')) {
```
<http://api.jquery.com/each>
<http://api.jquery.com/hasClass> |
13,460,571 | Sorry for the confusing question but here's what i'm trying to do. I have a page with multiple (ul) items. I'm using jquery to manipulate the classes of the (ul)'s and (li)'s. What i'm trying to do is treat each (ul) as an individual as oppose to a whole. For example my:
```
<ul class="bNav">
<li><a href="#">Home</a... | 2012/11/19 | [
"https://Stackoverflow.com/questions/13460571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/584765/"
] | From the docs:
***.is()***
Check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments.
Try:
```
$('.bNav.opp').addClass('nav').wrap('<nav class="navbar navbar-inverse"><div class="navbar-inner">');
$('.bNa... | Try this:
```
$('.bNav')
.addClass('nav')
.filter('.opp')
.wrap('<nav class="navbar navbar-inverse"><div class="navbar-inner">')
.end().not('.opp')
.wrap('<nav class="navbar"><div class="navbar-inner">')
;
``` |
13,460,571 | Sorry for the confusing question but here's what i'm trying to do. I have a page with multiple (ul) items. I'm using jquery to manipulate the classes of the (ul)'s and (li)'s. What i'm trying to do is treat each (ul) as an individual as oppose to a whole. For example my:
```
<ul class="bNav">
<li><a href="#">Home</a... | 2012/11/19 | [
"https://Stackoverflow.com/questions/13460571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/584765/"
] | Use an `.each` loop (and try `.hasClass()` instead):
```
$('.bNav').each(function(i,el) {
if ($(this).hasClass('opp')) {
```
<http://api.jquery.com/each>
<http://api.jquery.com/hasClass> | Try this:
```
$('.bNav')
.addClass('nav')
.filter('.opp')
.wrap('<nav class="navbar navbar-inverse"><div class="navbar-inner">')
.end().not('.opp')
.wrap('<nav class="navbar"><div class="navbar-inner">')
;
``` |
9,256,242 | I am fetching some data from database and want to show these values in a combo in javascript but combo box is not populating any value, perhaps i am doing something wrong in json or javascript, can anybody tell me where i am wrong? From db 5 values are coming in while loop
```
JSONObject jsonObj= new JSONObject();
... | 2012/02/13 | [
"https://Stackoverflow.com/questions/9256242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1179771/"
] | 1. There was a syntax error
2. `parseJSON` is not needed when data is retrieved using `getJSON`
Assuming the response json is of struture:
{name={prop1:value1 , prop2: valu2, prop3:value3 ..... }}
```
$(document).ready(function () {
$("#combo").change(function () {
$.getJSON('combo.jsp', {
... | I don't know which browser you are using. But afaik, insert html directly by using `innerHTML` is not working on some browser.
You should try this way:
```
$("#combo1")[0].options.add(new Option(label, value));
```
label indicates the string inner "option"
value indicates the attribute "value" of the "option"
In yo... |
9,256,242 | I am fetching some data from database and want to show these values in a combo in javascript but combo box is not populating any value, perhaps i am doing something wrong in json or javascript, can anybody tell me where i am wrong? From db 5 values are coming in while loop
```
JSONObject jsonObj= new JSONObject();
... | 2012/02/13 | [
"https://Stackoverflow.com/questions/9256242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1179771/"
] | 1. There was a syntax error
2. `parseJSON` is not needed when data is retrieved using `getJSON`
Assuming the response json is of struture:
{name={prop1:value1 , prop2: valu2, prop3:value3 ..... }}
```
$(document).ready(function () {
$("#combo").change(function () {
$.getJSON('combo.jsp', {
... | I doubt u are getting values from your getJSON CALL .. Use Firebug to see if you are getting response for your ajax call. And use console.log(responseData); inside $.getJSON('combo.jsp', {count : this.value}, function(responseData) {
console.log(responseData);
});
Hi try this:
```
var options = '';
$.getJSON('combo.... |
2,284,326 | I'm selecting records from a database using the equivalent of this query:
```
SELECT * FROM reports WHERE user_id IN (3, 6, 22);
```
The function calling fetchAll() has an argument that's an array of the user IDs, and this call works just fine:
```
$resultSet = $this->getDbTable()->fetchAll('user_id IN (' . implode... | 2010/02/17 | [
"https://Stackoverflow.com/questions/2284326",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/275588/"
] | ```
$data = array(1, 2, 3);
$select->where('user_id IN (?)', $data);
``` | In Zend 2
```
$data = array(1, 2, 3);
$select->where('user_id', $data);
``` |
2,284,326 | I'm selecting records from a database using the equivalent of this query:
```
SELECT * FROM reports WHERE user_id IN (3, 6, 22);
```
The function calling fetchAll() has an argument that's an array of the user IDs, and this call works just fine:
```
$resultSet = $this->getDbTable()->fetchAll('user_id IN (' . implode... | 2010/02/17 | [
"https://Stackoverflow.com/questions/2284326",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/275588/"
] | ```
$data = array(1, 2, 3);
$select->where('user_id IN (?)', $data);
``` | ```
$select = $this->getSql()->select();
$select->where("reports.user_id in ('3','6','22')");
$resultSet = $this->selectWith($select);
//echo $select->getSqlString();die;
return $resultSet;
``` |
2,284,326 | I'm selecting records from a database using the equivalent of this query:
```
SELECT * FROM reports WHERE user_id IN (3, 6, 22);
```
The function calling fetchAll() has an argument that's an array of the user IDs, and this call works just fine:
```
$resultSet = $this->getDbTable()->fetchAll('user_id IN (' . implode... | 2010/02/17 | [
"https://Stackoverflow.com/questions/2284326",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/275588/"
] | In Zend 2
```
$data = array(1, 2, 3);
$select->where('user_id', $data);
``` | ```
$select = $this->getSql()->select();
$select->where("reports.user_id in ('3','6','22')");
$resultSet = $this->selectWith($select);
//echo $select->getSqlString();die;
return $resultSet;
``` |
43,621,369 | I've been looking at already answered solutions to this questions but none of them seem to work with my code. I've only just started coding in C# and I'm confused how my code isn't working.
```cs
using System;
namespace dt
{
class Averager
{
static void Main()
{
var total = 0.0;
int runningN... | 2017/04/25 | [
"https://Stackoverflow.com/questions/43621369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7318129/"
] | You're calling `ReadLine` twice! The first time is after the prompt. The second is in the `else` clause of your if statement. The second one is likely null and causes the error when trying to convert to double. You need to store the value of your input to a variable:
```
using System;
namespace dt
{
class Averager ... | The error tells you the exact problem you're having.
>
> Input string was not in a correct format.
>
>
>
You need to make sure the input into the parse method is valid. In most cases, you will find a TryParse variant of the Parse methods. In this case, [double.TryParse](https://msdn.microsoft.com/en-us/library/9... |
43,621,369 | I've been looking at already answered solutions to this questions but none of them seem to work with my code. I've only just started coding in C# and I'm confused how my code isn't working.
```cs
using System;
namespace dt
{
class Averager
{
static void Main()
{
var total = 0.0;
int runningN... | 2017/04/25 | [
"https://Stackoverflow.com/questions/43621369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7318129/"
] | You're calling `ReadLine` twice! The first time is after the prompt. The second is in the `else` clause of your if statement. The second one is likely null and causes the error when trying to convert to double. You need to store the value of your input to a variable:
```
using System;
namespace dt
{
class Averager ... | I would just stuff it into a double right off the bat -- using "Convert.toDouble(yourValue). It appread that you are already doing your checking to see if you will be getting a numeric value or a string so why not skip the var and make it a double straight away?
using System;
```
namespace dt{
class Averager
... |
43,621,369 | I've been looking at already answered solutions to this questions but none of them seem to work with my code. I've only just started coding in C# and I'm confused how my code isn't working.
```cs
using System;
namespace dt
{
class Averager
{
static void Main()
{
var total = 0.0;
int runningN... | 2017/04/25 | [
"https://Stackoverflow.com/questions/43621369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7318129/"
] | The error tells you the exact problem you're having.
>
> Input string was not in a correct format.
>
>
>
You need to make sure the input into the parse method is valid. In most cases, you will find a TryParse variant of the Parse methods. In this case, [double.TryParse](https://msdn.microsoft.com/en-us/library/9... | I would just stuff it into a double right off the bat -- using "Convert.toDouble(yourValue). It appread that you are already doing your checking to see if you will be getting a numeric value or a string so why not skip the var and make it a double straight away?
using System;
```
namespace dt{
class Averager
... |
15,646,170 | Is there any way to do this, without using the error control operator on `@preg_match` ? :)
Because PHP requires that patterns are wrapped between a character, I was thinking to do it this way:
1. Get the first character.
2. Find the last occurence of this character in the string with:
```
$rpos = strrpos($string, $... | 2013/03/26 | [
"https://Stackoverflow.com/questions/15646170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1325399/"
] | I'm always using [this function](https://github.com/symfony/Finder/blob/master/Expression/Regex.php#L64-74) in the Symfony2 Finder component:
```php
if (preg_match('/^(.{3,}?)([imsxuADU]*)$/', $expr, $m)) {
$start = substr($m[1], 0, 1);
$end = substr($m[1], -1);
if (($start === $end && !preg_match('/[*?... | In the commets it is already described in the short way.
But you can check if the regex is okay by using the [`filter_var`](http://php.net/filter-var) method
```
$string = "String to match";
if (filter_var($string, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/abc/")))) {
echo "Regex is OK";
} ... |
289,719 | Here are my settings:
```
$ xterm
xterm Xt error: Can't open display:
xterm: DISPLAY is not set
$ echo $DISPLAY
$ cat /etc/ssh/sshd_config | grep X
X11Forwarding yes
X11DisplayOffset 10
``` | 2013/05/02 | [
"https://askubuntu.com/questions/289719",
"https://askubuntu.com",
"https://askubuntu.com/users/117117/"
] | You need to use the -X flag
```
ssh -X user@server
``` | Try with this command:
```
DISPLAY=:0 xterm
``` |
289,719 | Here are my settings:
```
$ xterm
xterm Xt error: Can't open display:
xterm: DISPLAY is not set
$ echo $DISPLAY
$ cat /etc/ssh/sshd_config | grep X
X11Forwarding yes
X11DisplayOffset 10
``` | 2013/05/02 | [
"https://askubuntu.com/questions/289719",
"https://askubuntu.com",
"https://askubuntu.com/users/117117/"
] | In my case I was missing the xauth program on the target machine
How to debug these situations:
1. On the target host, run another sshd daemon to debug on another port:
```
/usr/sbin/sshd -d -p 222
```
2. On the source host:
```
ssh -v -Y phil@192.168.0.14 -p 222
```
In my situation I could see:
```
debug1: Rem... | Try with this command:
```
DISPLAY=:0 xterm
``` |
289,719 | Here are my settings:
```
$ xterm
xterm Xt error: Can't open display:
xterm: DISPLAY is not set
$ echo $DISPLAY
$ cat /etc/ssh/sshd_config | grep X
X11Forwarding yes
X11DisplayOffset 10
``` | 2013/05/02 | [
"https://askubuntu.com/questions/289719",
"https://askubuntu.com",
"https://askubuntu.com/users/117117/"
] | Try with this command:
```
DISPLAY=:0 xterm
``` | Did you run `vncpasswd` in the account you used to write the configuration file?
I had this problem because I configured the `root` account but the `vnc` user is another, run the `vncpasswd` again in the right account and everything will be ok. |
289,719 | Here are my settings:
```
$ xterm
xterm Xt error: Can't open display:
xterm: DISPLAY is not set
$ echo $DISPLAY
$ cat /etc/ssh/sshd_config | grep X
X11Forwarding yes
X11DisplayOffset 10
``` | 2013/05/02 | [
"https://askubuntu.com/questions/289719",
"https://askubuntu.com",
"https://askubuntu.com/users/117117/"
] | You need to use the -X flag
```
ssh -X user@server
``` | In my case I was missing the xauth program on the target machine
How to debug these situations:
1. On the target host, run another sshd daemon to debug on another port:
```
/usr/sbin/sshd -d -p 222
```
2. On the source host:
```
ssh -v -Y phil@192.168.0.14 -p 222
```
In my situation I could see:
```
debug1: Rem... |
289,719 | Here are my settings:
```
$ xterm
xterm Xt error: Can't open display:
xterm: DISPLAY is not set
$ echo $DISPLAY
$ cat /etc/ssh/sshd_config | grep X
X11Forwarding yes
X11DisplayOffset 10
``` | 2013/05/02 | [
"https://askubuntu.com/questions/289719",
"https://askubuntu.com",
"https://askubuntu.com/users/117117/"
] | You need to use the -X flag
```
ssh -X user@server
``` | Did you run `vncpasswd` in the account you used to write the configuration file?
I had this problem because I configured the `root` account but the `vnc` user is another, run the `vncpasswd` again in the right account and everything will be ok. |
289,719 | Here are my settings:
```
$ xterm
xterm Xt error: Can't open display:
xterm: DISPLAY is not set
$ echo $DISPLAY
$ cat /etc/ssh/sshd_config | grep X
X11Forwarding yes
X11DisplayOffset 10
``` | 2013/05/02 | [
"https://askubuntu.com/questions/289719",
"https://askubuntu.com",
"https://askubuntu.com/users/117117/"
] | In my case I was missing the xauth program on the target machine
How to debug these situations:
1. On the target host, run another sshd daemon to debug on another port:
```
/usr/sbin/sshd -d -p 222
```
2. On the source host:
```
ssh -v -Y phil@192.168.0.14 -p 222
```
In my situation I could see:
```
debug1: Rem... | Did you run `vncpasswd` in the account you used to write the configuration file?
I had this problem because I configured the `root` account but the `vnc` user is another, run the `vncpasswd` again in the right account and everything will be ok. |
33,240,856 | After when a radiobutton is checked, I do an ajax request to the server. when it returns, I have the full html page with the new data. I need only a part of the code. How can I replace the old data (form before the ajax request) with the new data after the request? Here is my code:
```
$(".do-ajax").change(function ()... | 2015/10/20 | [
"https://Stackoverflow.com/questions/33240856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4551041/"
] | Use the `find` method to find elements within the jQuery object:
```
$(".do-ajax").change(function () {
$.ajax({
url: "",
data: { id: this.id },
type: "POST",
success: function (data) {
$(".ajax-form").replaceWith($(data).find(".ajax-form"));
},
error: function (data) {
console.lo... | Try this in your ajax success call back function: `$('.ajax-form').html($(data).find('.ajax-form').html())` |
16,827,123 | Is there a quicker or more efficient way to add Strings to a List than the below example?:
```
List<String> apptList = new List<String>();
foreach (Appointment appointment in appointments){
String subject = appointment.Subject;
//...(continues for another 10 lines)
//...And then manually adding each Str... | 2013/05/30 | [
"https://Stackoverflow.com/questions/16827123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2380071/"
] | ```
var apptList = appointments.Select(a => a.Subject).ToList();
``` | I'm not sure if I'm getting your code right, but since your Appointment class is already implementing IEnumerable, you should be able to call ToList() to convert it to a list in one shot.
<http://msdn.microsoft.com/en-us/library/bb342261.aspx> |
16,827,123 | Is there a quicker or more efficient way to add Strings to a List than the below example?:
```
List<String> apptList = new List<String>();
foreach (Appointment appointment in appointments){
String subject = appointment.Subject;
//...(continues for another 10 lines)
//...And then manually adding each Str... | 2013/05/30 | [
"https://Stackoverflow.com/questions/16827123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2380071/"
] | ```
var apptList = appointments.Select(a => a.Subject).ToList();
``` | How about this:
```
List<string> apptList = appointments.Select(x => x.Subject).ToList();
``` |
16,827,123 | Is there a quicker or more efficient way to add Strings to a List than the below example?:
```
List<String> apptList = new List<String>();
foreach (Appointment appointment in appointments){
String subject = appointment.Subject;
//...(continues for another 10 lines)
//...And then manually adding each Str... | 2013/05/30 | [
"https://Stackoverflow.com/questions/16827123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2380071/"
] | I'm not sure if I'm getting your code right, but since your Appointment class is already implementing IEnumerable, you should be able to call ToList() to convert it to a list in one shot.
<http://msdn.microsoft.com/en-us/library/bb342261.aspx> | How about this:
```
List<string> apptList = appointments.Select(x => x.Subject).ToList();
``` |
66,784,374 | I have the below code:
```
d=0
n=5750
squared_list = []
for i in range(0, n):
squared_list.append(i ** 2)
string_digits = [str(int) for int in squared_list]
str_of_ints = ''.join(string_digits)
counter = 0
for j in str_of_ints:
if j ==str(d):
counter +=1
print(counter)
```
The output is supposed t... | 2021/03/24 | [
"https://Stackoverflow.com/questions/66784374",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | `range` STOPS at its second arg.
If you change `n=5750` to `n=5751`, you will get the expected result. You could also use `range(0, n+1)` as Fred said.
...and like Mark said, don't use `int` as a variable name | your initial range needs to be:
`for i in range(0, n + 1):`
as range does not include the last number it reaches so you're only going for numbers 0 to 5749 in your code. |
66,784,374 | I have the below code:
```
d=0
n=5750
squared_list = []
for i in range(0, n):
squared_list.append(i ** 2)
string_digits = [str(int) for int in squared_list]
str_of_ints = ''.join(string_digits)
counter = 0
for j in str_of_ints:
if j ==str(d):
counter +=1
print(counter)
```
The output is supposed t... | 2021/03/24 | [
"https://Stackoverflow.com/questions/66784374",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | `range` STOPS at its second arg.
If you change `n=5750` to `n=5751`, you will get the expected result. You could also use `range(0, n+1)` as Fred said.
...and like Mark said, don't use `int` as a variable name | Your loop in running up to 5749, use below code:
```
for i in range(0, n+1):
squared_list.append(i ** 2)
``` |
66,784,374 | I have the below code:
```
d=0
n=5750
squared_list = []
for i in range(0, n):
squared_list.append(i ** 2)
string_digits = [str(int) for int in squared_list]
str_of_ints = ''.join(string_digits)
counter = 0
for j in str_of_ints:
if j ==str(d):
counter +=1
print(counter)
```
The output is supposed t... | 2021/03/24 | [
"https://Stackoverflow.com/questions/66784374",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | `range` STOPS at its second arg.
If you change `n=5750` to `n=5751`, you will get the expected result. You could also use `range(0, n+1)` as Fred said.
...and like Mark said, don't use `int` as a variable name | as it's been said you should not use "int" as a variable name, change it to "i" or something.
Also, in your question you should explain what you're trying to achieve, here we can only infer from the bugged code and the expected value, formulating your problem in a clear way will also help you debugging some times...
A... |
66,784,374 | I have the below code:
```
d=0
n=5750
squared_list = []
for i in range(0, n):
squared_list.append(i ** 2)
string_digits = [str(int) for int in squared_list]
str_of_ints = ''.join(string_digits)
counter = 0
for j in str_of_ints:
if j ==str(d):
counter +=1
print(counter)
```
The output is supposed t... | 2021/03/24 | [
"https://Stackoverflow.com/questions/66784374",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | your initial range needs to be:
`for i in range(0, n + 1):`
as range does not include the last number it reaches so you're only going for numbers 0 to 5749 in your code. | Your loop in running up to 5749, use below code:
```
for i in range(0, n+1):
squared_list.append(i ** 2)
``` |
66,784,374 | I have the below code:
```
d=0
n=5750
squared_list = []
for i in range(0, n):
squared_list.append(i ** 2)
string_digits = [str(int) for int in squared_list]
str_of_ints = ''.join(string_digits)
counter = 0
for j in str_of_ints:
if j ==str(d):
counter +=1
print(counter)
```
The output is supposed t... | 2021/03/24 | [
"https://Stackoverflow.com/questions/66784374",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | your initial range needs to be:
`for i in range(0, n + 1):`
as range does not include the last number it reaches so you're only going for numbers 0 to 5749 in your code. | as it's been said you should not use "int" as a variable name, change it to "i" or something.
Also, in your question you should explain what you're trying to achieve, here we can only infer from the bugged code and the expected value, formulating your problem in a clear way will also help you debugging some times...
A... |
45,629,565 | >
> C:\Program Files\MongoDB\Server\3.4\bin>mongo
>
>
>
```
MongoDB shell version v3.4.7
connecting to: mongodb://127.0.0.1:27017
2017-08-11T15:37:19.430+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017 after 5000ms milliseconds, giving up.
2017-08-11T15:37:19.433+0800 E QUERY [thread1] Error: cou... | 2017/08/11 | [
"https://Stackoverflow.com/questions/45629565",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/667903/"
] | You need to create data/db directory and give the below command.
mongod --dbpath d:\test\mongodb\data
It will start running at 27017 port. If pou want to change the port then add --port portnumber
Assuming you have already set the environment variable | Could you try connecting using `mongo --host <host>`? |
5,353,511 | I am trying to code the equivalent to the EXCEL PMT function.
in JavaScript, the formula looks like this:
```
function PMT (ir, np, pv, fv ) {
/*
ir - interest rate per month
np - number of periods (months)
pv - present value
fv - future value (residual value)
*/
pmt = ( ir * ( pv * Math.pow ( (ir+1), np ) + f... | 2011/03/18 | [
"https://Stackoverflow.com/questions/5353511",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/503973/"
] | @dps123: When I recently had to work with some financial equations to convert functions from an Excel workbook, I came across the [EGM Mathematical Finance class](http://www.phpclasses.org/browse/file/3028.html), which tries to mimic Excel functions. It might be worth having a look at, if only to see how the functions ... | I am not a math wiz, but a simple google search turned this thread up:
<http://www.excelforum.com/excel-general/370948-pmt-function-does-anyone-know-the-formula.html>
Here he has the following formula for type=0:
```
pmt = ((pv - fv) * ir / (1 - (1 + ir) ^ -(np)));
```
Maybe this will work for you :) |
5,353,511 | I am trying to code the equivalent to the EXCEL PMT function.
in JavaScript, the formula looks like this:
```
function PMT (ir, np, pv, fv ) {
/*
ir - interest rate per month
np - number of periods (months)
pv - present value
fv - future value (residual value)
*/
pmt = ( ir * ( pv * Math.pow ( (ir+1), np ) + f... | 2011/03/18 | [
"https://Stackoverflow.com/questions/5353511",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/503973/"
] | @dps
You would need to amend the denominator where the interest factor is changed to `(ir * type + 1)`
When it is an annuity due meaning start of period payments the value of `1` for `Type` will insure the interest factor `(ir + 1)` and when it is an ordinary annuity meaning end of period payments the value of `0` fo... | I am not a math wiz, but a simple google search turned this thread up:
<http://www.excelforum.com/excel-general/370948-pmt-function-does-anyone-know-the-formula.html>
Here he has the following formula for type=0:
```
pmt = ((pv - fv) * ir / (1 - (1 + ir) ^ -(np)));
```
Maybe this will work for you :) |
5,353,511 | I am trying to code the equivalent to the EXCEL PMT function.
in JavaScript, the formula looks like this:
```
function PMT (ir, np, pv, fv ) {
/*
ir - interest rate per month
np - number of periods (months)
pv - present value
fv - future value (residual value)
*/
pmt = ( ir * ( pv * Math.pow ( (ir+1), np ) + f... | 2011/03/18 | [
"https://Stackoverflow.com/questions/5353511",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/503973/"
] | Below is the code in java:
```
double pmt = ((pv - fv) * ir / (1 - Math.pow((1 + ir), -np)));
``` | I am not a math wiz, but a simple google search turned this thread up:
<http://www.excelforum.com/excel-general/370948-pmt-function-does-anyone-know-the-formula.html>
Here he has the following formula for type=0:
```
pmt = ((pv - fv) * ir / (1 - (1 + ir) ^ -(np)));
```
Maybe this will work for you :) |
5,353,511 | I am trying to code the equivalent to the EXCEL PMT function.
in JavaScript, the formula looks like this:
```
function PMT (ir, np, pv, fv ) {
/*
ir - interest rate per month
np - number of periods (months)
pv - present value
fv - future value (residual value)
*/
pmt = ( ir * ( pv * Math.pow ( (ir+1), np ) + f... | 2011/03/18 | [
"https://Stackoverflow.com/questions/5353511",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/503973/"
] | @dps123: When I recently had to work with some financial equations to convert functions from an Excel workbook, I came across the [EGM Mathematical Finance class](http://www.phpclasses.org/browse/file/3028.html), which tries to mimic Excel functions. It might be worth having a look at, if only to see how the functions ... | @dps
You would need to amend the denominator where the interest factor is changed to `(ir * type + 1)`
When it is an annuity due meaning start of period payments the value of `1` for `Type` will insure the interest factor `(ir + 1)` and when it is an ordinary annuity meaning end of period payments the value of `0` fo... |
5,353,511 | I am trying to code the equivalent to the EXCEL PMT function.
in JavaScript, the formula looks like this:
```
function PMT (ir, np, pv, fv ) {
/*
ir - interest rate per month
np - number of periods (months)
pv - present value
fv - future value (residual value)
*/
pmt = ( ir * ( pv * Math.pow ( (ir+1), np ) + f... | 2011/03/18 | [
"https://Stackoverflow.com/questions/5353511",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/503973/"
] | @dps123: When I recently had to work with some financial equations to convert functions from an Excel workbook, I came across the [EGM Mathematical Finance class](http://www.phpclasses.org/browse/file/3028.html), which tries to mimic Excel functions. It might be worth having a look at, if only to see how the functions ... | Below is the code in java:
```
double pmt = ((pv - fv) * ir / (1 - Math.pow((1 + ir), -np)));
``` |
31,777,169 | I have seen variations of this question, but not in this exact context. What I have is a file called 100-Test.zip which contains 100 .jpg images. I want to open this file in memory and process each file doing PIL operations. The rest of the code is already written, I just want to concentrate on getting from the zip fil... | 2015/08/02 | [
"https://Stackoverflow.com/questions/31777169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3785114/"
] | Turns out the problem was there was an extra empty element in namelist() due to the images being zipped inside a direcotory insde the zip file. Here is the full code that will check for that and iterate through the 100 images.
```
import zipfile
from StringIO import StringIO
from PIL import Image
import imghdr
imgzip... | I have the same issue, thanks for @alfredox, I modified the answer, use io.BytesIO not StringIo in python3.
```
z = zipfile.ZipFile(zip_file)
for i in range(len(z.namelist())):
file_in_zip = z.namelist()[i]
if (".jpg" in file_in_zip or ".JPG" in file_in_zip):
data = z.read(file_in_zip)
dataEn... |
31,777,169 | I have seen variations of this question, but not in this exact context. What I have is a file called 100-Test.zip which contains 100 .jpg images. I want to open this file in memory and process each file doing PIL operations. The rest of the code is already written, I just want to concentrate on getting from the zip fil... | 2015/08/02 | [
"https://Stackoverflow.com/questions/31777169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3785114/"
] | Turns out the problem was there was an extra empty element in namelist() due to the images being zipped inside a direcotory insde the zip file. Here is the full code that will check for that and iterate through the 100 images.
```
import zipfile
from StringIO import StringIO
from PIL import Image
import imghdr
imgzip... | There is no need to use StringIO. `zipfile` can read image file in memory. The following loops through all images in your .zip file:
```
import zipfile
from PIL import Image
imgzip = zipfile.ZipFile("100-Test.zip")
inflist = imgzip.infolist()
for f in inflist:
ifile = imgzip.open(f)
img = Image.open(ifile)
... |
31,777,169 | I have seen variations of this question, but not in this exact context. What I have is a file called 100-Test.zip which contains 100 .jpg images. I want to open this file in memory and process each file doing PIL operations. The rest of the code is already written, I just want to concentrate on getting from the zip fil... | 2015/08/02 | [
"https://Stackoverflow.com/questions/31777169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3785114/"
] | Turns out the problem was there was an extra empty element in namelist() due to the images being zipped inside a direcotory insde the zip file. Here is the full code that will check for that and iterate through the 100 images.
```
import zipfile
from StringIO import StringIO
from PIL import Image
import imghdr
imgzip... | If you need to work on pixel data then you can load an image stream data from zip file as numpy array keeping the original data shape (i.e. 32x32 RGB) following the steps:
1. use zipfile to get the ZipExtFile format
2. use PIL.Image to convert ZipExtFile into image like data structure
3. convert PIL.image into numpy a... |
31,777,169 | I have seen variations of this question, but not in this exact context. What I have is a file called 100-Test.zip which contains 100 .jpg images. I want to open this file in memory and process each file doing PIL operations. The rest of the code is already written, I just want to concentrate on getting from the zip fil... | 2015/08/02 | [
"https://Stackoverflow.com/questions/31777169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3785114/"
] | Turns out the problem was there was an extra empty element in namelist() due to the images being zipped inside a direcotory insde the zip file. Here is the full code that will check for that and iterate through the 100 images.
```
import zipfile
from StringIO import StringIO
from PIL import Image
import imghdr
imgzip... | cv2.imdecode() version:
```
with zipfile.ZipFile(zip_data_path, "r") as z:
for img_name in z.namelist():
buf = z.read(name)
np_buf = np.frombuffer(buf, np.uint8)
img = cv2.imdecode(np_buf, cv2.IMREAD_UNCHANGED)
# Saving image as an example.
cv2.imwrite(name, img)
``` |
31,777,169 | I have seen variations of this question, but not in this exact context. What I have is a file called 100-Test.zip which contains 100 .jpg images. I want to open this file in memory and process each file doing PIL operations. The rest of the code is already written, I just want to concentrate on getting from the zip fil... | 2015/08/02 | [
"https://Stackoverflow.com/questions/31777169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3785114/"
] | There is no need to use StringIO. `zipfile` can read image file in memory. The following loops through all images in your .zip file:
```
import zipfile
from PIL import Image
imgzip = zipfile.ZipFile("100-Test.zip")
inflist = imgzip.infolist()
for f in inflist:
ifile = imgzip.open(f)
img = Image.open(ifile)
... | I have the same issue, thanks for @alfredox, I modified the answer, use io.BytesIO not StringIo in python3.
```
z = zipfile.ZipFile(zip_file)
for i in range(len(z.namelist())):
file_in_zip = z.namelist()[i]
if (".jpg" in file_in_zip or ".JPG" in file_in_zip):
data = z.read(file_in_zip)
dataEn... |
31,777,169 | I have seen variations of this question, but not in this exact context. What I have is a file called 100-Test.zip which contains 100 .jpg images. I want to open this file in memory and process each file doing PIL operations. The rest of the code is already written, I just want to concentrate on getting from the zip fil... | 2015/08/02 | [
"https://Stackoverflow.com/questions/31777169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3785114/"
] | I have the same issue, thanks for @alfredox, I modified the answer, use io.BytesIO not StringIo in python3.
```
z = zipfile.ZipFile(zip_file)
for i in range(len(z.namelist())):
file_in_zip = z.namelist()[i]
if (".jpg" in file_in_zip or ".JPG" in file_in_zip):
data = z.read(file_in_zip)
dataEn... | If you need to work on pixel data then you can load an image stream data from zip file as numpy array keeping the original data shape (i.e. 32x32 RGB) following the steps:
1. use zipfile to get the ZipExtFile format
2. use PIL.Image to convert ZipExtFile into image like data structure
3. convert PIL.image into numpy a... |
31,777,169 | I have seen variations of this question, but not in this exact context. What I have is a file called 100-Test.zip which contains 100 .jpg images. I want to open this file in memory and process each file doing PIL operations. The rest of the code is already written, I just want to concentrate on getting from the zip fil... | 2015/08/02 | [
"https://Stackoverflow.com/questions/31777169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3785114/"
] | I have the same issue, thanks for @alfredox, I modified the answer, use io.BytesIO not StringIo in python3.
```
z = zipfile.ZipFile(zip_file)
for i in range(len(z.namelist())):
file_in_zip = z.namelist()[i]
if (".jpg" in file_in_zip or ".JPG" in file_in_zip):
data = z.read(file_in_zip)
dataEn... | cv2.imdecode() version:
```
with zipfile.ZipFile(zip_data_path, "r") as z:
for img_name in z.namelist():
buf = z.read(name)
np_buf = np.frombuffer(buf, np.uint8)
img = cv2.imdecode(np_buf, cv2.IMREAD_UNCHANGED)
# Saving image as an example.
cv2.imwrite(name, img)
``` |
31,777,169 | I have seen variations of this question, but not in this exact context. What I have is a file called 100-Test.zip which contains 100 .jpg images. I want to open this file in memory and process each file doing PIL operations. The rest of the code is already written, I just want to concentrate on getting from the zip fil... | 2015/08/02 | [
"https://Stackoverflow.com/questions/31777169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3785114/"
] | There is no need to use StringIO. `zipfile` can read image file in memory. The following loops through all images in your .zip file:
```
import zipfile
from PIL import Image
imgzip = zipfile.ZipFile("100-Test.zip")
inflist = imgzip.infolist()
for f in inflist:
ifile = imgzip.open(f)
img = Image.open(ifile)
... | If you need to work on pixel data then you can load an image stream data from zip file as numpy array keeping the original data shape (i.e. 32x32 RGB) following the steps:
1. use zipfile to get the ZipExtFile format
2. use PIL.Image to convert ZipExtFile into image like data structure
3. convert PIL.image into numpy a... |
31,777,169 | I have seen variations of this question, but not in this exact context. What I have is a file called 100-Test.zip which contains 100 .jpg images. I want to open this file in memory and process each file doing PIL operations. The rest of the code is already written, I just want to concentrate on getting from the zip fil... | 2015/08/02 | [
"https://Stackoverflow.com/questions/31777169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3785114/"
] | There is no need to use StringIO. `zipfile` can read image file in memory. The following loops through all images in your .zip file:
```
import zipfile
from PIL import Image
imgzip = zipfile.ZipFile("100-Test.zip")
inflist = imgzip.infolist()
for f in inflist:
ifile = imgzip.open(f)
img = Image.open(ifile)
... | cv2.imdecode() version:
```
with zipfile.ZipFile(zip_data_path, "r") as z:
for img_name in z.namelist():
buf = z.read(name)
np_buf = np.frombuffer(buf, np.uint8)
img = cv2.imdecode(np_buf, cv2.IMREAD_UNCHANGED)
# Saving image as an example.
cv2.imwrite(name, img)
``` |
31,777,169 | I have seen variations of this question, but not in this exact context. What I have is a file called 100-Test.zip which contains 100 .jpg images. I want to open this file in memory and process each file doing PIL operations. The rest of the code is already written, I just want to concentrate on getting from the zip fil... | 2015/08/02 | [
"https://Stackoverflow.com/questions/31777169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3785114/"
] | If you need to work on pixel data then you can load an image stream data from zip file as numpy array keeping the original data shape (i.e. 32x32 RGB) following the steps:
1. use zipfile to get the ZipExtFile format
2. use PIL.Image to convert ZipExtFile into image like data structure
3. convert PIL.image into numpy a... | cv2.imdecode() version:
```
with zipfile.ZipFile(zip_data_path, "r") as z:
for img_name in z.namelist():
buf = z.read(name)
np_buf = np.frombuffer(buf, np.uint8)
img = cv2.imdecode(np_buf, cv2.IMREAD_UNCHANGED)
# Saving image as an example.
cv2.imwrite(name, img)
``` |
212,463 | here I am taking 3 inputs. 1st input will take test cases and the other two input will take starting and ending range. the program is running fine as expected but the limit of this question for compilation is 1 sec, and my code is taking 5.01 sec.
How can I make it more efficient so that I can submit the code?
>
> T... | 2019/01/29 | [
"https://codereview.stackexchange.com/questions/212463",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/191567/"
] | Welcome to CR, nice challenge
A few comments about the code
* Many unnecessary conversion
Python is a duck typed language, if it talks like a duck, walks like a duck... it must be a duck!
This means that
>
>
> ```
> p ^= int(x)
>
> ```
>
>
Here `x` is already an `int`, same goes for the `str` conversion late... | The logic is straightforward and easy to follow (albeit with an unnecessary conversion of an `int` to an `int`):
```
p = 0
for x in range(a,b+1):
p ^= x
return p % 2
```
However, you could achieve the same more efficiently by noting that we're just counting how many odd numbers are in the range, and reporting wh... |
212,463 | here I am taking 3 inputs. 1st input will take test cases and the other two input will take starting and ending range. the program is running fine as expected but the limit of this question for compilation is 1 sec, and my code is taking 5.01 sec.
How can I make it more efficient so that I can submit the code?
>
> T... | 2019/01/29 | [
"https://codereview.stackexchange.com/questions/212463",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/191567/"
] | If one has a range 1,2,3,4 then only every first bit is interesting for the result; in concreto: whether odd or even. If the number of odd numbers is odd, the result is odd.
```
def even (lwb, upb):
n = upb - lwb + 1;
ones = (n / 2) + (0 if n % 2 == 0 else (upb & 1))
return ones % 2 == 0
```
Here `lwb` (... | The logic is straightforward and easy to follow (albeit with an unnecessary conversion of an `int` to an `int`):
```
p = 0
for x in range(a,b+1):
p ^= x
return p % 2
```
However, you could achieve the same more efficiently by noting that we're just counting how many odd numbers are in the range, and reporting wh... |
212,463 | here I am taking 3 inputs. 1st input will take test cases and the other two input will take starting and ending range. the program is running fine as expected but the limit of this question for compilation is 1 sec, and my code is taking 5.01 sec.
How can I make it more efficient so that I can submit the code?
>
> T... | 2019/01/29 | [
"https://codereview.stackexchange.com/questions/212463",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/191567/"
] | If you want to make this efficient you should avoid iterating over the range at all.
If you notice that the Xor of four consecutive integers is always even, you can "ignore" them in the final Xor and in the end you only care about the bounds modulo 4, and thus only have to read 4 bits of the input.
A one liner giving... | The logic is straightforward and easy to follow (albeit with an unnecessary conversion of an `int` to an `int`):
```
p = 0
for x in range(a,b+1):
p ^= x
return p % 2
```
However, you could achieve the same more efficiently by noting that we're just counting how many odd numbers are in the range, and reporting wh... |
70,958 | A player in my upcoming game wants to play a burrowing race. I couldn't find rules about what sort of actions a burrow creature can take.
Do rules exist for burrowing creatures:
* Attacking from underground?
* Getting cover underground?
* Casting spells underground?
Note: I see this question has been answered for 4E... | 2015/11/10 | [
"https://rpg.stackexchange.com/questions/70958",
"https://rpg.stackexchange.com",
"https://rpg.stackexchange.com/users/25783/"
] | ### Rules as Written, Burrow is *undefined* in Pathfinder.
The helpful folks at pathfindersrd have the rules for Burrow appended with the following note:
>
> Burrow details were not included in the Pathfinder Roleplaying Game so
> the details shown here were copied from d20srd.org.
>
>
>
RAW cannot help you here... | Making a few additions to Tim C's excellent answer:
>
> Incorporeal creatures have an innate sense of direction and can move at full speed even when they cannot see.
>
>
>
This line, which burrowing creatures lack, implies that creatures in objects are **Blinded** while fully submerged (i.e., not attacking). Sinc... |
61,246,688 | i'm currently getting this warning in the console
Warning: Failed prop type: Invalid prop `dataSet.headings` of type `array` supplied to `myComp`, expected `object`.
i have a variable `data`
```
let data = {
headings: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
}
```
and have this in the react rende... | 2020/04/16 | [
"https://Stackoverflow.com/questions/61246688",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1772701/"
] | Your data set is actually much simpler than your `propTypes` definition is.
You don't need the `PropTypes.objectof` there.
Instead, do this:
```
MyComp.propTypes = {
dataSet: PropTypes.shape({
headings: PropTypes.arrayOf(PropTypes.string)
})
};
``` | `objectOf` is to indicate an object with property values of a specified type, i.e. all strings or numbers.
Your data, however, is just an object with one property, `headings`, with a value that is an array of strings.
```
MyComp.propTypes = {
dataSet: PropTypes.shape({
headings: PropTypes.arrayOf(
PropTyp... |
61,246,688 | i'm currently getting this warning in the console
Warning: Failed prop type: Invalid prop `dataSet.headings` of type `array` supplied to `myComp`, expected `object`.
i have a variable `data`
```
let data = {
headings: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
}
```
and have this in the react rende... | 2020/04/16 | [
"https://Stackoverflow.com/questions/61246688",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1772701/"
] | Your data set is actually much simpler than your `propTypes` definition is.
You don't need the `PropTypes.objectof` there.
Instead, do this:
```
MyComp.propTypes = {
dataSet: PropTypes.shape({
headings: PropTypes.arrayOf(PropTypes.string)
})
};
``` | In tabs element pass props as shown below code (renderTabBar)
```js
const Health_record = (props) => {
return (
<Tabs renderTabBar={renderTabBar} >
<Tab heading="tab1">
</Tab>
<Tab heading="tab1">
</Tab>
<Tabs>
)
}
const rende... |
67,668,104 | I'm deploying Pytorch model saved as `.pth` to AWS Sagemaker. I specify custom `inference.py` file and my catalog looks like this:
```
| my_model
| |--model.pth
|
| code
| |--inference.py
| |--requirements.txt
|
```
That's completely in line with [SDK doc](https://sa... | 2021/05/24 | [
"https://Stackoverflow.com/questions/67668104",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15982582/"
] | If you aren't working in a git repository there can be issues with `source_dir` that is why I just define the `source_dir` as an absolute path instead
e.g for your example assuming your notebook is inside `code` directory
```
base_dir = os.path.dirname(os.path.realpath(__file__))
source_dir = os.path.join(base_dir, '.... | You will need to specify the `source_dir`.
Here is the sample notebook which shows "bring your own Pytorch model" deployment setup. Since the `sagemaker.pytorch.model.PyTorchModel` is based on `sagemaker.model.FrameworkModel`, you may use the `source_dir` when initializing the PyTorchModel.
Reference
* [Deploying pr... |
60,604,276 | I wanted to do a date range search in java suppose I wanted to search from 10-22-2019 to the present date.
But the question is to do the date range search in the chunk size of two weeks(consider this can vary but in form weeks) for eg here start date will 10-22-2019 but the end date will start date + 2 weeks added to i... | 2020/03/09 | [
"https://Stackoverflow.com/questions/60604276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11216426/"
] | Simple iterative solution :
```
LocalDate start = LocalDate.parse("2019-10-22");
LocalDate end = LocalDate.now();
LocalDate chunckStart = start;
while (chunckStart.plusDays(15).isBefore(end)) {
doTheThing(chunckStart, chunckStart.plusDays(15));
chunckStart = chunckStart.plusDays(16);
}
doTheThing(chunckStar... | try:
```java
public static Iterator<Pair<LocalDate, LocalDate>> splitDataRange(LocalDate start, LocalDate end, int dayChunkSize) {
return new Iterator<Pair<LocalDate, LocalDate>>() {
private LocalDate chunkStart = start;
private LocalDate chunkEnd = start.plusDays(dayChunkSize);
... |
60,604,276 | I wanted to do a date range search in java suppose I wanted to search from 10-22-2019 to the present date.
But the question is to do the date range search in the chunk size of two weeks(consider this can vary but in form weeks) for eg here start date will 10-22-2019 but the end date will start date + 2 weeks added to i... | 2020/03/09 | [
"https://Stackoverflow.com/questions/60604276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11216426/"
] | Simple iterative solution :
```
LocalDate start = LocalDate.parse("2019-10-22");
LocalDate end = LocalDate.now();
LocalDate chunckStart = start;
while (chunckStart.plusDays(15).isBefore(end)) {
doTheThing(chunckStart, chunckStart.plusDays(15));
chunckStart = chunckStart.plusDays(16);
}
doTheThing(chunckStar... | Here's a solution using Streams and `LocalDate`:
```
LocalDate start = LocalDate.of(2020, 2, 28);
LocalDate end = LocalDate.now();
int step = 7;
start
.datesUntil(end, Period.ofDays(step))
.map(date -> {
LocalDate proposedEnd = date.plusDays(step);
LocalDate chunkEnd = proposedEnd.compareTo(en... |
19,379,283 | I need to create string variable `string time` and it should look like `14:58`.
I created function
```
string SetTime() {
long double h = (long double)(rand()%25);
long double m = (long double)(rand()%60);
string hour = to_string(h);
string minutes = (m <= 9 ? "0" : "" ) + to_string(m);
string time = hour + ":" ... | 2013/10/15 | [
"https://Stackoverflow.com/questions/19379283",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2287081/"
] | Your function is called `SetTime` while you're calling `SetNumber`. The linker cannot find the definition of `SetNumber`. It is interesting that you are getting a linker error rather than a compiler error. It means that you've declared `SetNumber`. | you should call SetTime, not SetNumber |
1,345,018 | I have some doubts about the following implementation of the state pattern:
I have an Order object. For simplicity, let's suppose it has a quantity, productId, price and supplier. Also, there are a set of known states in which the order can transition:
* state a: order is new, quantity must be > 0 and must have produ... | 2009/08/28 | [
"https://Stackoverflow.com/questions/1345018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146124/"
] | Changing the current state object can be done directly from a state object, from the Order and even OK from an external source (processor), though unusual.
According to the State pattern the Order object delegates all requests to the current OrderState object. If setQuantity() is a state-specific operation (it is in y... | Do you have several different classes, one per state.
```
BaseOrder {
// common getters
// persistence capabilities
}
NewOrder extends BaseOrder {
// setters
CheckingOrder placeOrder();
}
CheckingOrder extends BaseOrder {
CancelledOrder cancel();
PricingOrder assignSupplier();
}
```
and... |
1,345,018 | I have some doubts about the following implementation of the state pattern:
I have an Order object. For simplicity, let's suppose it has a quantity, productId, price and supplier. Also, there are a set of known states in which the order can transition:
* state a: order is new, quantity must be > 0 and must have produ... | 2009/08/28 | [
"https://Stackoverflow.com/questions/1345018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146124/"
] | In order for the state pattern to work, the context object has to expose an interface that the state classes can use. At a bare minimum this will have to include a `changeState(State)` method. This I'm afraid is just one of the limitations of the pattern and is a possible reason why it is not always useful. The secret ... | Do you have several different classes, one per state.
```
BaseOrder {
// common getters
// persistence capabilities
}
NewOrder extends BaseOrder {
// setters
CheckingOrder placeOrder();
}
CheckingOrder extends BaseOrder {
CancelledOrder cancel();
PricingOrder assignSupplier();
}
```
and... |
1,345,018 | I have some doubts about the following implementation of the state pattern:
I have an Order object. For simplicity, let's suppose it has a quantity, productId, price and supplier. Also, there are a set of known states in which the order can transition:
* state a: order is new, quantity must be > 0 and must have produ... | 2009/08/28 | [
"https://Stackoverflow.com/questions/1345018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146124/"
] | I would store information in the Order class, and pass a pointer to the Order instance to the state. Something like this:
```
class Order {
setQuantity(q) {
_state.setQuantity(q);
}
}
StateA {
setQuantity(q) {
_order.q = q;
}
}
StateB {
setQuantity(q) {
throw exception;
}
}
``` | Do you have several different classes, one per state.
```
BaseOrder {
// common getters
// persistence capabilities
}
NewOrder extends BaseOrder {
// setters
CheckingOrder placeOrder();
}
CheckingOrder extends BaseOrder {
CancelledOrder cancel();
PricingOrder assignSupplier();
}
```
and... |
1,345,018 | I have some doubts about the following implementation of the state pattern:
I have an Order object. For simplicity, let's suppose it has a quantity, productId, price and supplier. Also, there are a set of known states in which the order can transition:
* state a: order is new, quantity must be > 0 and must have produ... | 2009/08/28 | [
"https://Stackoverflow.com/questions/1345018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146124/"
] | This is an ideal scenario for the state pattern.
In the State pattern, your state classes should be responsible for transitioning state, not just checking the validity of the transition. In addition, pushing state transitions outside of the order class is not a good idea and goes against the pattern, but you can still... | Do you have several different classes, one per state.
```
BaseOrder {
// common getters
// persistence capabilities
}
NewOrder extends BaseOrder {
// setters
CheckingOrder placeOrder();
}
CheckingOrder extends BaseOrder {
CancelledOrder cancel();
PricingOrder assignSupplier();
}
```
and... |
1,345,018 | I have some doubts about the following implementation of the state pattern:
I have an Order object. For simplicity, let's suppose it has a quantity, productId, price and supplier. Also, there are a set of known states in which the order can transition:
* state a: order is new, quantity must be > 0 and must have produ... | 2009/08/28 | [
"https://Stackoverflow.com/questions/1345018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146124/"
] | This is an ideal scenario for the state pattern.
In the State pattern, your state classes should be responsible for transitioning state, not just checking the validity of the transition. In addition, pushing state transitions outside of the order class is not a good idea and goes against the pattern, but you can still... | Changing the current state object can be done directly from a state object, from the Order and even OK from an external source (processor), though unusual.
According to the State pattern the Order object delegates all requests to the current OrderState object. If setQuantity() is a state-specific operation (it is in y... |
1,345,018 | I have some doubts about the following implementation of the state pattern:
I have an Order object. For simplicity, let's suppose it has a quantity, productId, price and supplier. Also, there are a set of known states in which the order can transition:
* state a: order is new, quantity must be > 0 and must have produ... | 2009/08/28 | [
"https://Stackoverflow.com/questions/1345018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146124/"
] | This is an ideal scenario for the state pattern.
In the State pattern, your state classes should be responsible for transitioning state, not just checking the validity of the transition. In addition, pushing state transitions outside of the order class is not a good idea and goes against the pattern, but you can still... | In order for the state pattern to work, the context object has to expose an interface that the state classes can use. At a bare minimum this will have to include a `changeState(State)` method. This I'm afraid is just one of the limitations of the pattern and is a possible reason why it is not always useful. The secret ... |
1,345,018 | I have some doubts about the following implementation of the state pattern:
I have an Order object. For simplicity, let's suppose it has a quantity, productId, price and supplier. Also, there are a set of known states in which the order can transition:
* state a: order is new, quantity must be > 0 and must have produ... | 2009/08/28 | [
"https://Stackoverflow.com/questions/1345018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146124/"
] | This is an ideal scenario for the state pattern.
In the State pattern, your state classes should be responsible for transitioning state, not just checking the validity of the transition. In addition, pushing state transitions outside of the order class is not a good idea and goes against the pattern, but you can still... | I would store information in the Order class, and pass a pointer to the Order instance to the state. Something like this:
```
class Order {
setQuantity(q) {
_state.setQuantity(q);
}
}
StateA {
setQuantity(q) {
_order.q = q;
}
}
StateB {
setQuantity(q) {
throw exception;
}
}
``` |
26,895 | Hi I am not specialist in probability so I will not be surprised if the answer for this question is just a simple consequence of well known results from the random walk theory.
In this case, I will be happy if you can tell me the "magic words" to find the material related to this problem.
Let $\sum\_{i=1}^n X\_i$ a r... | 2011/10/06 | [
"https://physics.stackexchange.com/questions/26895",
"https://physics.stackexchange.com",
"https://physics.stackexchange.com/users/-1/"
] | If $p=1$ and $d$ is non-empty, then clearly the random walk is not transient, because since you use the $\ell^1$ norm, there is a closed surface which always reflects the walker back into the enclosed finite region. If, however, $p = 0$ then the walk is transient, since simple random walks in 3 dimensions are transient... | Your walk is always transient when you use the symmetric condition of reflection in both directions, and the argument is essentially given in the previous answer. But when the condition of reflection is *asymmetric*, so that you have reflection only when you are going out, an infinite number of reflectors will give rec... |
34,294,333 | In my session start script, I choose the session\_name and then do a session\_start.
```
$session_name = rand(0,1) ? 'first' : 'second';
session_name($session_name);
session_start();
```
The above code runs on every page load. After a few page loads, there will probably be sessions for both session\_name 'f... | 2015/12/15 | [
"https://Stackoverflow.com/questions/34294333",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/964634/"
] | **TRY IT**
```
<?php
session_name("first");
session_start();
echo session_status();
session_destroy();
echo session_status();
session_name("second");
session_start();
echo session_status();
session_destroy();
echo session_status();
?>
```
I've tested it on xampp and it return... | Please try below code
```
<?php unset($_SESSION['name']); // will delete just the name data
session_destroy(); // will delete ALL data associated with that user.
?>
``` |
303,570 | My 5th grader has a science project. He chose a water bottle trick.
We know that when you poke a pinhole into a sealed bottle of water the water will not flow because of the lack of air pressure but when you unscrew the cap the water will flow out of the hole.
He is hypothesizing that if you leave the cap on the bo... | 2017/01/07 | [
"https://physics.stackexchange.com/questions/303570",
"https://physics.stackexchange.com",
"https://physics.stackexchange.com/users/141377/"
] | When the air pressure pushing on the top surface of the water is equal to the air pressure pushing back on the water trying to come out of the pinhole at the bottom, those two pressures cancel out. Then the rate of the water coming out of the pinhole at the bottom depends only on the pressure due to the weight of the... | When you have a bottle or jar that is sealed on tight , no matter how hard you twist it or stick it in a door jamb, you can't open it. Yet if you jab a tiny little hole in the jar lid, the top opens easily. It's basically the same reason, once you equalise the pressure, that's all you need do |
24,208,096 | Say I have the following time series, which starts on 2014-06-01 which is a Sunday.
In [7]:
```
# 2014-06-01 is Sunday
df = pd.Series( index=pd.date_range( '2014-06-01', periods=30 ), data=nr.randn( 30 ) ) #
df
```
I can resample weekly, starting on Sundays and closing on Saturdays:
```
In [9]:
df.resample( 'W-SA... | 2014/06/13 | [
"https://Stackoverflow.com/questions/24208096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2564569/"
] | After trying the various options of `resample`, I might have an explanation. The way `resample` chooses the first entry of the new resampled index seems to depend on the `closed` option:
* when `closed=left`, `resample` looks for the latest possible start
* when `closed=right`, `resample` looks for the earliest possib... | The first saturday of the month of june 2014 is the 7th, so it starts on the seventh.
If you try with sunday, it starts on the first of june as expected.
```
df.resample( '2W-SUN' )
Out[11]:
2014-06-01 0.739895
2014-06-15 0.497950
2014-06-29 0.445480
2014-07-13 0.767430
Freq: 2W-SUN, dtype: float64
``` |
60,736 | In *The Originals*, Klaus has got a miracle baby daughter who:
* is a daughter of an original hybrid and a werewolf.
* can heal vampires from lethal werewolf bite (power of original hybrid).
* can create hybrids. A werewolf in transition must drink the blood of the baby (power of human doppelganger blood).
What exact... | 2014/07/06 | [
"https://scifi.stackexchange.com/questions/60736",
"https://scifi.stackexchange.com",
"https://scifi.stackexchange.com/users/931/"
] | I think that she is a heretic but different from the ones in The Vampire Diaries because she is more powerful. She is a combination of an original hybrid and a witch from a very powerful bloodline.
Personally I think her werewolf gene may never be triggered because she may end up losing her other abilities and magic -... | A witch can be a vampire as well as shown in vampire diaries when Kai was turned he was a heretic as shown when Tyler bit him and Kai healed himself. so which makes hope a heritic though I'm not sure how her werewolf gene would be connected but with all them ability's she is so much more dangerous that Klaus |
60,736 | In *The Originals*, Klaus has got a miracle baby daughter who:
* is a daughter of an original hybrid and a werewolf.
* can heal vampires from lethal werewolf bite (power of original hybrid).
* can create hybrids. A werewolf in transition must drink the blood of the baby (power of human doppelganger blood).
What exact... | 2014/07/06 | [
"https://scifi.stackexchange.com/questions/60736",
"https://scifi.stackexchange.com",
"https://scifi.stackexchange.com/users/931/"
] | I think that she is a heretic but different from the ones in The Vampire Diaries because she is more powerful. She is a combination of an original hybrid and a witch from a very powerful bloodline.
Personally I think her werewolf gene may never be triggered because she may end up losing her other abilities and magic -... | simple:
Hope is a vamire-werewolf-doppelganger-witch hybrid
a hybrid because of her father
a with because of her grandmother, and the first borns of every michelson are witches
a doppelganger due to her pure hybrid-witch nature |
60,736 | In *The Originals*, Klaus has got a miracle baby daughter who:
* is a daughter of an original hybrid and a werewolf.
* can heal vampires from lethal werewolf bite (power of original hybrid).
* can create hybrids. A werewolf in transition must drink the blood of the baby (power of human doppelganger blood).
What exact... | 2014/07/06 | [
"https://scifi.stackexchange.com/questions/60736",
"https://scifi.stackexchange.com",
"https://scifi.stackexchange.com/users/931/"
] | Hope is NOT a Doppelganger. We had already seen that the nature of hybrids created through Hope was slightly different than those created by Niklaus.
Klaus' s hybrids are (triggered) werewolves who die with his blood in their systems. During transation they are required to consume the blood of one of Amara's doppelgan... | simple:
Hope is a vamire-werewolf-doppelganger-witch hybrid
a hybrid because of her father
a with because of her grandmother, and the first borns of every michelson are witches
a doppelganger due to her pure hybrid-witch nature |
60,736 | In *The Originals*, Klaus has got a miracle baby daughter who:
* is a daughter of an original hybrid and a werewolf.
* can heal vampires from lethal werewolf bite (power of original hybrid).
* can create hybrids. A werewolf in transition must drink the blood of the baby (power of human doppelganger blood).
What exact... | 2014/07/06 | [
"https://scifi.stackexchange.com/questions/60736",
"https://scifi.stackexchange.com",
"https://scifi.stackexchange.com/users/931/"
] | I thought she was a Hybrid like her father. In "[From a Cradle to a Grave](http://vampirediaries.wikia.com/wiki/From_a_Cradle_to_a_Grave)", wasn't it sort of explained? Also, didn't Hayley need her blood to turn into a complete hybrid? That was how Hayley became a hybrid after she was killed she still had her babies bl... | Hope is a tribrid, but what has not been adequately answered is what that looks like.
The writers are kept on their toes, because they are making this stuff as it goes along. In the Vampire Diaries, at first you couldn't be a vampire and a witch, but then...there were The Heretics. This doesn't explain exactly how tha... |
60,736 | In *The Originals*, Klaus has got a miracle baby daughter who:
* is a daughter of an original hybrid and a werewolf.
* can heal vampires from lethal werewolf bite (power of original hybrid).
* can create hybrids. A werewolf in transition must drink the blood of the baby (power of human doppelganger blood).
What exact... | 2014/07/06 | [
"https://scifi.stackexchange.com/questions/60736",
"https://scifi.stackexchange.com",
"https://scifi.stackexchange.com/users/931/"
] | I thought she was a Hybrid like her father. In "[From a Cradle to a Grave](http://vampirediaries.wikia.com/wiki/From_a_Cradle_to_a_Grave)", wasn't it sort of explained? Also, didn't Hayley need her blood to turn into a complete hybrid? That was how Hayley became a hybrid after she was killed she still had her babies bl... | I think that she is a heretic but different from the ones in The Vampire Diaries because she is more powerful. She is a combination of an original hybrid and a witch from a very powerful bloodline.
Personally I think her werewolf gene may never be triggered because she may end up losing her other abilities and magic -... |
60,736 | In *The Originals*, Klaus has got a miracle baby daughter who:
* is a daughter of an original hybrid and a werewolf.
* can heal vampires from lethal werewolf bite (power of original hybrid).
* can create hybrids. A werewolf in transition must drink the blood of the baby (power of human doppelganger blood).
What exact... | 2014/07/06 | [
"https://scifi.stackexchange.com/questions/60736",
"https://scifi.stackexchange.com",
"https://scifi.stackexchange.com/users/931/"
] | I thought she was a Hybrid like her father. In "[From a Cradle to a Grave](http://vampirediaries.wikia.com/wiki/From_a_Cradle_to_a_Grave)", wasn't it sort of explained? Also, didn't Hayley need her blood to turn into a complete hybrid? That was how Hayley became a hybrid after she was killed she still had her babies bl... | Hope is part witch, vampire, and werewolf but she is a witch until she triggers her werewolf gene. Her blood can also create hybrids as shown in Season 1 Episode 22, when Haley died with her baby's blood in her and was in transition and had to complete her transition by drinking Hope's blood. |
60,736 | In *The Originals*, Klaus has got a miracle baby daughter who:
* is a daughter of an original hybrid and a werewolf.
* can heal vampires from lethal werewolf bite (power of original hybrid).
* can create hybrids. A werewolf in transition must drink the blood of the baby (power of human doppelganger blood).
What exact... | 2014/07/06 | [
"https://scifi.stackexchange.com/questions/60736",
"https://scifi.stackexchange.com",
"https://scifi.stackexchange.com/users/931/"
] | Hope is a pure blood hybrid meaning she was born with doppelganger blood unlike Klaus. After Klaus drained it from Elena, he was able to sire hybrids. Hope started siring hybrids from in the womb, meaning she's on a whole different level than Klaus. Normally, you can either be a vampire **or** a witch, never both, beca... | None of her genes have to be activated.
Whenever a new supernatural creature is born, the rules completely change. The underworld salene daughter is a prime example.
Hope does not have to activate any "gene" they will simple be active from birth
- She is a hybrid, so she can turn into a werewolf at any time
- She wa... |
60,736 | In *The Originals*, Klaus has got a miracle baby daughter who:
* is a daughter of an original hybrid and a werewolf.
* can heal vampires from lethal werewolf bite (power of original hybrid).
* can create hybrids. A werewolf in transition must drink the blood of the baby (power of human doppelganger blood).
What exact... | 2014/07/06 | [
"https://scifi.stackexchange.com/questions/60736",
"https://scifi.stackexchange.com",
"https://scifi.stackexchange.com/users/931/"
] | Hope **is** a witch, werewolf and vampire. She stopped the car before getting to the house that Elijah was in that exploded. She's obviously the strongest one - just no one knows it yet. Plus, you would think that she would technically be the number one **original** because she wasn't created by a witch, she was born t... | A witch can be a vampire as well as shown in vampire diaries when Kai was turned he was a heretic as shown when Tyler bit him and Kai healed himself. so which makes hope a heritic though I'm not sure how her werewolf gene would be connected but with all them ability's she is so much more dangerous that Klaus |
60,736 | In *The Originals*, Klaus has got a miracle baby daughter who:
* is a daughter of an original hybrid and a werewolf.
* can heal vampires from lethal werewolf bite (power of original hybrid).
* can create hybrids. A werewolf in transition must drink the blood of the baby (power of human doppelganger blood).
What exact... | 2014/07/06 | [
"https://scifi.stackexchange.com/questions/60736",
"https://scifi.stackexchange.com",
"https://scifi.stackexchange.com/users/931/"
] | Hope is a tribrid, but what has not been adequately answered is what that looks like.
The writers are kept on their toes, because they are making this stuff as it goes along. In the Vampire Diaries, at first you couldn't be a vampire and a witch, but then...there were The Heretics. This doesn't explain exactly how tha... | A witch can be a vampire as well as shown in vampire diaries when Kai was turned he was a heretic as shown when Tyler bit him and Kai healed himself. so which makes hope a heritic though I'm not sure how her werewolf gene would be connected but with all them ability's she is so much more dangerous that Klaus |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.