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 |
|---|---|---|---|---|---|
32,178,130 | I'm trying to get users count belongs to specific company.
Here is my model;
```
var Company = Bookshelf.Model.extend({
tableName: 'companies',
users: function () {
return this.hasMany(User.Model, "company_id");
},
users_count : function(){
return new User.Model().query(function(qb){
... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32178130",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1011016/"
] | **Collection#count()**
If you upgrade to 0.8.2 you can use the new [`Collection#count` method](http://bookshelfjs.org/#Collection-count).
```
Company.forge({id: req.params.id}).users().count().then(userCount =>
res.send('company has ' + userCount + ' users!');
);
```
**Problem with your example**
The problem wit... | ```
User.collection().query(function (qb) {
qb.join('courses', 'users.id', 'courses.user_id');
qb.groupBy('users.id');
qb.select("users.*");
qb.count('* as course_count');
qb.orderBy("course_count", "desc");
})
``` |
32,178,130 | I'm trying to get users count belongs to specific company.
Here is my model;
```
var Company = Bookshelf.Model.extend({
tableName: 'companies',
users: function () {
return this.hasMany(User.Model, "company_id");
},
users_count : function(){
return new User.Model().query(function(qb){
... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32178130",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1011016/"
] | **Collection#count()**
If you upgrade to 0.8.2 you can use the new [`Collection#count` method](http://bookshelfjs.org/#Collection-count).
```
Company.forge({id: req.params.id}).users().count().then(userCount =>
res.send('company has ' + userCount + ' users!');
);
```
**Problem with your example**
The problem wit... | Check out the [bookshelf-eloquent](https://www.npmjs.com/package/bookshelf-eloquent) extension. The withCount() function is probably what you are looking for. Your code would look something like this:
```
let company = await Company.where('id', req.params.id)
.withCount('users').first();
``` |
32,178,130 | I'm trying to get users count belongs to specific company.
Here is my model;
```
var Company = Bookshelf.Model.extend({
tableName: 'companies',
users: function () {
return this.hasMany(User.Model, "company_id");
},
users_count : function(){
return new User.Model().query(function(qb){
... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32178130",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1011016/"
] | Check out the [bookshelf-eloquent](https://www.npmjs.com/package/bookshelf-eloquent) extension. The withCount() function is probably what you are looking for. Your code would look something like this:
```
let company = await Company.where('id', req.params.id)
.withCount('users').first();
``` | ```
User.collection().query(function (qb) {
qb.join('courses', 'users.id', 'courses.user_id');
qb.groupBy('users.id');
qb.select("users.*");
qb.count('* as course_count');
qb.orderBy("course_count", "desc");
})
``` |
10,077,837 | I'm having trouble putting this problem into searchable terms. I'm working on an Android application, and specifically the splash screen for my app. The app needs to fetch data from an external web service (a blocking function call), while it does this the user gets a nice title, image and progress bar. When the data a... | 2012/04/09 | [
"https://Stackoverflow.com/questions/10077837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/982955/"
] | Have a look at this project in GitHub.
<https://github.com/virajs/MongoDB-Mapping-Attributes.git>
This project mainly provide you with two mapping attributes. OneToMany and ManyToOne.
Checkout the code and play around with the test project. | You could declare your Comments property as List<MongoDBRef> and handle the relationship yourself but there is no automatic support for that. |
21,632,979 | I have an abstract class:
```
public abstract class Room {
}
```
and inherited classes that are not known at compile time like:
```
public class MagicRoom extends Room {
public MagicRoom(){
System.out.println("Creating a MagicRoom.");
}
public String magic = "";
}
```
or:
```
public class ... | 2014/02/07 | [
"https://Stackoverflow.com/questions/21632979",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3284680/"
] | Make that method generic:
```
public static <T extends Room> T makeRoom(Class<T> roomClass)
throws IllegalArgumentException, InstantiationException,
IllegalAccessException, InvocationTargetException,
SecurityException, NoSuchMethodException{
// This is enough, if you have 0-arg constructor ... | You'll have to cast the Room object to MagicRoom.
```
MagicRoom magicRoom = (MagicRoom) MazeGame.makeRoom(MagicRoom.class);
```
Also, I know it's only an example but you should make those attributes private and use accessor/mutator methods.
e.g.
```
public class MagicRoom extends Room {
public MagicRoom(){
... |
5,534,196 | I have Windows 7 installed on my PC. I am learning C and assembly language together. I use codeblock IDE for writing C codes and emu8086 for assembly codes. I am able to DEBUG the assembly codes from DOS prompt, but not the C codes. Why so?
I select console application option while writing C codes. they run well on th... | 2011/04/04 | [
"https://Stackoverflow.com/questions/5534196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/597858/"
] | The thing you're trying to do is doable, but you need to create a new implementation of IAsyncResult (something like "CompositeResult" that watches the first IAsyncResult, then kicks off the 2nd call).
However, this task is actually far easier using the Reactive Extensions - in that case you'd use Observable.FromAsyn... | I don't really understand what are you trying to achieve, but I think you should be rethinking the code.
An IAsyncResult instance is the object that allows to to handle asynchronous method calls, and they are created when you perform an async call through *BeginXXX*.
In your example, you basically want to return an in... |
5,534,196 | I have Windows 7 installed on my PC. I am learning C and assembly language together. I use codeblock IDE for writing C codes and emu8086 for assembly codes. I am able to DEBUG the assembly codes from DOS prompt, but not the C codes. Why so?
I select console application option while writing C codes. they run well on th... | 2011/04/04 | [
"https://Stackoverflow.com/questions/5534196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/597858/"
] | I think the easiest way to solve this is to use `Task` wrappers. In particular, you can finish a [`TaskCompletionSource`](http://msdn.microsoft.com/en-us/library/dd449174.aspx) when `BeginGetResponse` completes. Then just return the [`Task` for that `TaskCompletionSource`](http://msdn.microsoft.com/en-us/library/dd4491... | I don't really understand what are you trying to achieve, but I think you should be rethinking the code.
An IAsyncResult instance is the object that allows to to handle asynchronous method calls, and they are created when you perform an async call through *BeginXXX*.
In your example, you basically want to return an in... |
5,534,196 | I have Windows 7 installed on my PC. I am learning C and assembly language together. I use codeblock IDE for writing C codes and emu8086 for assembly codes. I am able to DEBUG the assembly codes from DOS prompt, but not the C codes. Why so?
I select console application option while writing C codes. they run well on th... | 2011/04/04 | [
"https://Stackoverflow.com/questions/5534196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/597858/"
] | I don't really understand what are you trying to achieve, but I think you should be rethinking the code.
An IAsyncResult instance is the object that allows to to handle asynchronous method calls, and they are created when you perform an async call through *BeginXXX*.
In your example, you basically want to return an in... | First, get the `AsyncResultNoResult` and `AsyncResult<TResult>` implementation code from Jeffrey Richter's MSDN magazine article "[Implementing the CLR Asynchronous Programming Model](http://msdn.microsoft.com/en-us/magazine/cc163467.aspx) (March 2007 issue)."
Once you have those base classes, you can relatively easil... |
5,534,196 | I have Windows 7 installed on my PC. I am learning C and assembly language together. I use codeblock IDE for writing C codes and emu8086 for assembly codes. I am able to DEBUG the assembly codes from DOS prompt, but not the C codes. Why so?
I select console application option while writing C codes. they run well on th... | 2011/04/04 | [
"https://Stackoverflow.com/questions/5534196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/597858/"
] | I realize that this question is almost one year old, but if the constraints of the asker still hold, there is an option available on .NET 3.5 to easily compose asynchronous operations. Look at Jeff Richter's [PowerThreading library](http://www.wintellect.com/PowerThreading.aspx). In the `Wintellect.PowerThreading.Async... | I don't really understand what are you trying to achieve, but I think you should be rethinking the code.
An IAsyncResult instance is the object that allows to to handle asynchronous method calls, and they are created when you perform an async call through *BeginXXX*.
In your example, you basically want to return an in... |
5,534,196 | I have Windows 7 installed on my PC. I am learning C and assembly language together. I use codeblock IDE for writing C codes and emu8086 for assembly codes. I am able to DEBUG the assembly codes from DOS prompt, but not the C codes. Why so?
I select console application option while writing C codes. they run well on th... | 2011/04/04 | [
"https://Stackoverflow.com/questions/5534196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/597858/"
] | The thing you're trying to do is doable, but you need to create a new implementation of IAsyncResult (something like "CompositeResult" that watches the first IAsyncResult, then kicks off the 2nd call).
However, this task is actually far easier using the Reactive Extensions - in that case you'd use Observable.FromAsyn... | First, get the `AsyncResultNoResult` and `AsyncResult<TResult>` implementation code from Jeffrey Richter's MSDN magazine article "[Implementing the CLR Asynchronous Programming Model](http://msdn.microsoft.com/en-us/magazine/cc163467.aspx) (March 2007 issue)."
Once you have those base classes, you can relatively easil... |
5,534,196 | I have Windows 7 installed on my PC. I am learning C and assembly language together. I use codeblock IDE for writing C codes and emu8086 for assembly codes. I am able to DEBUG the assembly codes from DOS prompt, but not the C codes. Why so?
I select console application option while writing C codes. they run well on th... | 2011/04/04 | [
"https://Stackoverflow.com/questions/5534196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/597858/"
] | I think the easiest way to solve this is to use `Task` wrappers. In particular, you can finish a [`TaskCompletionSource`](http://msdn.microsoft.com/en-us/library/dd449174.aspx) when `BeginGetResponse` completes. Then just return the [`Task` for that `TaskCompletionSource`](http://msdn.microsoft.com/en-us/library/dd4491... | First, get the `AsyncResultNoResult` and `AsyncResult<TResult>` implementation code from Jeffrey Richter's MSDN magazine article "[Implementing the CLR Asynchronous Programming Model](http://msdn.microsoft.com/en-us/magazine/cc163467.aspx) (March 2007 issue)."
Once you have those base classes, you can relatively easil... |
5,534,196 | I have Windows 7 installed on my PC. I am learning C and assembly language together. I use codeblock IDE for writing C codes and emu8086 for assembly codes. I am able to DEBUG the assembly codes from DOS prompt, but not the C codes. Why so?
I select console application option while writing C codes. they run well on th... | 2011/04/04 | [
"https://Stackoverflow.com/questions/5534196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/597858/"
] | I realize that this question is almost one year old, but if the constraints of the asker still hold, there is an option available on .NET 3.5 to easily compose asynchronous operations. Look at Jeff Richter's [PowerThreading library](http://www.wintellect.com/PowerThreading.aspx). In the `Wintellect.PowerThreading.Async... | First, get the `AsyncResultNoResult` and `AsyncResult<TResult>` implementation code from Jeffrey Richter's MSDN magazine article "[Implementing the CLR Asynchronous Programming Model](http://msdn.microsoft.com/en-us/magazine/cc163467.aspx) (March 2007 issue)."
Once you have those base classes, you can relatively easil... |
259,123 | Here's the problem, in a nutshell:
>
> *Glancy T. Pony is a mod on our mayonnaise site, and wakes up in the
> afternoon to find that her site has been littered by Miracle Whip
> astroturfers. As Glancy [cleans up the mess](https://meta.stackexchange.com/questions/259050/as-a-moderator-should-i-re-flag-spam-thats-al... | 2015/06/22 | [
"https://meta.stackexchange.com/questions/259123",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/50049/"
] | If I as a mod on Stack Overflow destroy an account for spam, you could immediately put a brake onto any linked accounts to require either more "I am human" validation or just hobble to one post per week and then flag up that account to the site moderators as one that's posted spam elsewhere. You could also feed the spa... | Create a "Destroy as spam account" function for moderators.
As part of the procedure do the following:
* Automatically generate a flag on any site that account is registered on for that user ("Network Spammer Detected")
* Automatically generate a flag for any other accounts with the same IP ("Possible Network Spamme... |
259,123 | Here's the problem, in a nutshell:
>
> *Glancy T. Pony is a mod on our mayonnaise site, and wakes up in the
> afternoon to find that her site has been littered by Miracle Whip
> astroturfers. As Glancy [cleans up the mess](https://meta.stackexchange.com/questions/259050/as-a-moderator-should-i-re-flag-spam-thats-al... | 2015/06/22 | [
"https://meta.stackexchange.com/questions/259123",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/50049/"
] | If I as a mod on Stack Overflow destroy an account for spam, you could immediately put a brake onto any linked accounts to require either more "I am human" validation or just hobble to one post per week and then flag up that account to the site moderators as one that's posted spam elsewhere. You could also feed the spa... | One of the important things I think per-site mods should have possibility to **vote on nuking a network profile of spammer**.
How can it work
* One mod on one site can vote to nuke a network spammer's profile, and only one per site
* There would be three votes from three moderators of three different sites required t... |
259,123 | Here's the problem, in a nutshell:
>
> *Glancy T. Pony is a mod on our mayonnaise site, and wakes up in the
> afternoon to find that her site has been littered by Miracle Whip
> astroturfers. As Glancy [cleans up the mess](https://meta.stackexchange.com/questions/259050/as-a-moderator-should-i-re-flag-spam-thats-al... | 2015/06/22 | [
"https://meta.stackexchange.com/questions/259123",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/50049/"
] | When we get spam, it is almost invariably by users with 1 rep point whose network profiles are also at or around 1 rep. I am reasonably certain that all spammers I've deleted should have been deleted network-wide.
This would suggest that it may well be a good idea to propagate deletions across multiple sites. At least... | One of the important things I think per-site mods should have possibility to **vote on nuking a network profile of spammer**.
How can it work
* One mod on one site can vote to nuke a network spammer's profile, and only one per site
* There would be three votes from three moderators of three different sites required t... |
259,123 | Here's the problem, in a nutshell:
>
> *Glancy T. Pony is a mod on our mayonnaise site, and wakes up in the
> afternoon to find that her site has been littered by Miracle Whip
> astroturfers. As Glancy [cleans up the mess](https://meta.stackexchange.com/questions/259050/as-a-moderator-should-i-re-flag-spam-thats-al... | 2015/06/22 | [
"https://meta.stackexchange.com/questions/259123",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/50049/"
] | Create a "Destroy as spam account" function for moderators.
As part of the procedure do the following:
* Automatically generate a flag on any site that account is registered on for that user ("Network Spammer Detected")
* Automatically generate a flag for any other accounts with the same IP ("Possible Network Spamme... | Blatant spam is the one universal issue that I would expect every moderator from every site to recognize. It does not need any domain knowledge or familiarity with the site to act on it.
One thing I think would be nice in general, and would avoid honest mistakes would be to actually mention the consequences of the des... |
259,123 | Here's the problem, in a nutshell:
>
> *Glancy T. Pony is a mod on our mayonnaise site, and wakes up in the
> afternoon to find that her site has been littered by Miracle Whip
> astroturfers. As Glancy [cleans up the mess](https://meta.stackexchange.com/questions/259050/as-a-moderator-should-i-re-flag-spam-thats-al... | 2015/06/22 | [
"https://meta.stackexchange.com/questions/259123",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/50049/"
] | I suggest a *networked moderator review queue*, only accessible by moderators.
(Bear with me..it has good potential)
**TL;DR;**
Have a new review queue accessible by moderators only, which would be shown to all moderators across all sites.
When a user is marked as spammy, the system would raise a flag, add a ... | One of the important things I think per-site mods should have possibility to **vote on nuking a network profile of spammer**.
How can it work
* One mod on one site can vote to nuke a network spammer's profile, and only one per site
* There would be three votes from three moderators of three different sites required t... |
259,123 | Here's the problem, in a nutshell:
>
> *Glancy T. Pony is a mod on our mayonnaise site, and wakes up in the
> afternoon to find that her site has been littered by Miracle Whip
> astroturfers. As Glancy [cleans up the mess](https://meta.stackexchange.com/questions/259050/as-a-moderator-should-i-re-flag-spam-thats-al... | 2015/06/22 | [
"https://meta.stackexchange.com/questions/259123",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/50049/"
] | Blatant spam is the one universal issue that I would expect every moderator from every site to recognize. It does not need any domain knowledge or familiarity with the site to act on it.
One thing I think would be nice in general, and would avoid honest mistakes would be to actually mention the consequences of the des... | I suggest a *networked moderator review queue*, only accessible by moderators.
(Bear with me..it has good potential)
**TL;DR;**
Have a new review queue accessible by moderators only, which would be shown to all moderators across all sites.
When a user is marked as spammy, the system would raise a flag, add a ... |
259,123 | Here's the problem, in a nutshell:
>
> *Glancy T. Pony is a mod on our mayonnaise site, and wakes up in the
> afternoon to find that her site has been littered by Miracle Whip
> astroturfers. As Glancy [cleans up the mess](https://meta.stackexchange.com/questions/259050/as-a-moderator-should-i-re-flag-spam-thats-al... | 2015/06/22 | [
"https://meta.stackexchange.com/questions/259123",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/50049/"
] | Blatant spam is the one universal issue that I would expect every moderator from every site to recognize. It does not need any domain knowledge or familiarity with the site to act on it.
One thing I think would be nice in general, and would avoid honest mistakes would be to actually mention the consequences of the des... | Suspend the network user for a short time (a day or so) so there is a chance to do a 'review' of the account. (Was it a single time mistake, or is there more)
Then the SE Community Managers, or other moderators (on the same site or other sites) can review the account.
If a user gets 3 or more 'delete votes' against h... |
259,123 | Here's the problem, in a nutshell:
>
> *Glancy T. Pony is a mod on our mayonnaise site, and wakes up in the
> afternoon to find that her site has been littered by Miracle Whip
> astroturfers. As Glancy [cleans up the mess](https://meta.stackexchange.com/questions/259050/as-a-moderator-should-i-re-flag-spam-thats-al... | 2015/06/22 | [
"https://meta.stackexchange.com/questions/259123",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/50049/"
] | When we get spam, it is almost invariably by users with 1 rep point whose network profiles are also at or around 1 rep. I am reasonably certain that all spammers I've deleted should have been deleted network-wide.
This would suggest that it may well be a good idea to propagate deletions across multiple sites. At least... | I suggest a *networked moderator review queue*, only accessible by moderators.
(Bear with me..it has good potential)
**TL;DR;**
Have a new review queue accessible by moderators only, which would be shown to all moderators across all sites.
When a user is marked as spammy, the system would raise a flag, add a ... |
259,123 | Here's the problem, in a nutshell:
>
> *Glancy T. Pony is a mod on our mayonnaise site, and wakes up in the
> afternoon to find that her site has been littered by Miracle Whip
> astroturfers. As Glancy [cleans up the mess](https://meta.stackexchange.com/questions/259050/as-a-moderator-should-i-re-flag-spam-thats-al... | 2015/06/22 | [
"https://meta.stackexchange.com/questions/259123",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/50049/"
] | If I as a mod on Stack Overflow destroy an account for spam, you could immediately put a brake onto any linked accounts to require either more "I am human" validation or just hobble to one post per week and then flag up that account to the site moderators as one that's posted spam elsewhere. You could also feed the spa... | Suspend the network user for a short time (a day or so) so there is a chance to do a 'review' of the account. (Was it a single time mistake, or is there more)
Then the SE Community Managers, or other moderators (on the same site or other sites) can review the account.
If a user gets 3 or more 'delete votes' against h... |
259,123 | Here's the problem, in a nutshell:
>
> *Glancy T. Pony is a mod on our mayonnaise site, and wakes up in the
> afternoon to find that her site has been littered by Miracle Whip
> astroturfers. As Glancy [cleans up the mess](https://meta.stackexchange.com/questions/259050/as-a-moderator-should-i-re-flag-spam-thats-al... | 2015/06/22 | [
"https://meta.stackexchange.com/questions/259123",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/50049/"
] | When we get spam, it is almost invariably by users with 1 rep point whose network profiles are also at or around 1 rep. I am reasonably certain that all spammers I've deleted should have been deleted network-wide.
This would suggest that it may well be a good idea to propagate deletions across multiple sites. At least... | Suspend the network user for a short time (a day or so) so there is a chance to do a 'review' of the account. (Was it a single time mistake, or is there more)
Then the SE Community Managers, or other moderators (on the same site or other sites) can review the account.
If a user gets 3 or more 'delete votes' against h... |
25,050,894 | I have file of type unicode, I need to get the check the file if `^` is being used as a delimiter or not using batch script
Here is example of the file content:
```
Case Id^Subcase Id^Cr Date Cust^Case Title^Contact First Name^Contact Last Name^Customer Phone Number^Contact E Mail
```
The approach i tried using is ... | 2014/07/31 | [
"https://Stackoverflow.com/questions/25050894",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3493117/"
] | You can try
```
@echo off
setlocal enableextensions disabledelayedexpansion
set "carets="
for /f %%a in (
'findstr /n /r /c:"^" data.txt ^| findstr /b /c:"1:" ^| find /c "^"'
) do set "carets=%%a"
echo %carets%
if "%carets%"=="7" ( echo FOUND ) else ( echo NOT FOUND )
```
How does it... | A for loop can process contents of a file and do lots of manipulations to it ... I'm not sure if this algorithm would work but it should atleast get you somewhere...
```
@echo off
For /f "tokens=*" %%a in (filename.extension) do (
Echo "%%a" ¦ find "^^"
)
Pause
``` |
25,050,894 | I have file of type unicode, I need to get the check the file if `^` is being used as a delimiter or not using batch script
Here is example of the file content:
```
Case Id^Subcase Id^Cr Date Cust^Case Title^Contact First Name^Contact Last Name^Customer Phone Number^Contact E Mail
```
The approach i tried using is ... | 2014/07/31 | [
"https://Stackoverflow.com/questions/25050894",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3493117/"
] | You can try
```
@echo off
setlocal enableextensions disabledelayedexpansion
set "carets="
for /f %%a in (
'findstr /n /r /c:"^" data.txt ^| findstr /b /c:"1:" ^| find /c "^"'
) do set "carets=%%a"
echo %carets%
if "%carets%"=="7" ( echo FOUND ) else ( echo NOT FOUND )
```
How does it... | Try this ..
```
@echo off
Set string=<%~1
Echo %string% ¦ find "^^"
Pause
```
Drag the file onto the batch file so it becomes the first argument and set will declare an instance variable of it .... Long shot .. hope it helps |
25,050,894 | I have file of type unicode, I need to get the check the file if `^` is being used as a delimiter or not using batch script
Here is example of the file content:
```
Case Id^Subcase Id^Cr Date Cust^Case Title^Contact First Name^Contact Last Name^Customer Phone Number^Contact E Mail
```
The approach i tried using is ... | 2014/07/31 | [
"https://Stackoverflow.com/questions/25050894",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3493117/"
] | You can try
```
@echo off
setlocal enableextensions disabledelayedexpansion
set "carets="
for /f %%a in (
'findstr /n /r /c:"^" data.txt ^| findstr /b /c:"1:" ^| find /c "^"'
) do set "carets=%%a"
echo %carets%
if "%carets%"=="7" ( echo FOUND ) else ( echo NOT FOUND )
```
How does it... | Use `awk` with the field separator set to `^` which you will need to escape.
```
awk -F \^ '{ print NF; n+=1 }; END { print n }' temp.txt
```
Will print the number of fields on each line followed by the number of lines - I am sure that you could find a better usage but it gives you a starting point. |
27,574,596 | I am writing a document reading application using Node-Webkit. A document can be hundreds of pages long and the interface allows opening the document to a specific chapter. Once the initial chapter is displayed, I want to load the rest of the book asynchronously. Since I don't know what direction the reader will scroll... | 2014/12/19 | [
"https://Stackoverflow.com/questions/27574596",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17870/"
] | The simple solution in my mind would be to not have the elements in the DOM until they are loaded. The user won't be able to scroll because there won't be content to scroll to. Then, it's just a matter of preserving the viewport when the elements are added.
Take the initial position of your scroll container and the he... | If you're updating the DOM from the click handler of an anchor (`<a/>`) tag, make sure you return false from the callback function. |
87,239 | Suppose we have a singly connected but not necessarily convex polygon. Something like `shape = CountryData["Chad", "Coordinates"]`.
Is there a simple way to implement an approximate [dilation](https://en.wikipedia.org/wiki/Dilation_(morphology)) for this shape, and obtain the result as vector data (lists of coordinate... | 2015/06/30 | [
"https://mathematica.stackexchange.com/questions/87239",
"https://mathematica.stackexchange.com",
"https://mathematica.stackexchange.com/users/12/"
] | From 2016 and Version 11.0 we can use `ImageMesh`.
```
img = ImagePad[ColorNegate@Image@Graphics[Polygon[shape]], 30];
imgD = Dilation[img, DiskMatrix[30]];
mesh0 = ImageMesh@img; meshD = ImageMesh@imgD;
Graphics[{Green,
Arrow[Flatten[pts0 = MeshPrimitives[mesh0, 1][[All, 1]], 1]], Red,
Arrow@Flatten[ptsD = MeshPrim... | For *visualization* purposes only I propose a simple and robust approach using a thick boundary line:
```
shape = CountryData["Chad", "Coordinates"];
r = 2;
xmin = Min[shape[[1, ;; , 1]]] - r;
xmax = Max[shape[[1, ;; , 1]]] + r;
ymin = Min[shape[[1, ;; , 2]]] - r;
ymax = Max[shape[[1, ;; , 2]]] + r;
Graphics[{{FaceF... |
87,239 | Suppose we have a singly connected but not necessarily convex polygon. Something like `shape = CountryData["Chad", "Coordinates"]`.
Is there a simple way to implement an approximate [dilation](https://en.wikipedia.org/wiki/Dilation_(morphology)) for this shape, and obtain the result as vector data (lists of coordinate... | 2015/06/30 | [
"https://mathematica.stackexchange.com/questions/87239",
"https://mathematica.stackexchange.com",
"https://mathematica.stackexchange.com/users/12/"
] | ```
shape = First @ CountryData["Chad", "Coordinates"];
poly = Polygon @ shape;
srd = SignedRegionDistance @ poly;
ranges = Flatten /@ Transpose[{{x, y},
CoordinateBounds[ScalingTransform[1.4 {1, 1}, Mean @ shape] @ shape]}];
ContourPlot[srd[{x, y}], ranges[[1]], ranges[[2]],
Contours -> Thread[{{-1, -.5, -.2... | For *visualization* purposes only I propose a simple and robust approach using a thick boundary line:
```
shape = CountryData["Chad", "Coordinates"];
r = 2;
xmin = Min[shape[[1, ;; , 1]]] - r;
xmax = Max[shape[[1, ;; , 1]]] + r;
ymin = Min[shape[[1, ;; , 2]]] - r;
ymax = Max[shape[[1, ;; , 2]]] + r;
Graphics[{{FaceF... |
478,065 | I'm building a PHP application using CodeIgniter. It is similar to `Let Me Google That For You` where you write a sentence into a text input box, click submit, and you are taken to a URL that displays the result. I wanted the URL to be human-editable, and relatively simple. I've gotten around the CodeIgniter URL routin... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478065",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | If your’re using Apache 2.2 and later, you can use the [B flag](http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteflags) to force the backreference to be escaped:
```
RewriteCond %{QUERY_STRING} ^q=.*
RewriteRule ^ /index.php/app/create/%0? [L,B]
``` | I usually do human readable urls like this
```
$humanReadableUrl= implode("_",preg_split('/\W+/', trim($input), -1, PREG_SPLIT_NO_EMPTY));
```
It will remove any non-word characters and will add underscores beetween words |
56,382,117 | Here is my question - is there a way I can edit my code so that the RequestedDateTime1 time from query 1 remains aligned with the its corresponding EventDisplay1 from query 1?
Below is how I arrived with this question.
I have the following code:
```
SELECT [Financial Number], [Depart Date & Time],
(Cas... | 2019/05/30 | [
"https://Stackoverflow.com/questions/56382117",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10687615/"
] | In WebChat v4 you can add data to any outgoing activity's channel data through a custom store middleware; however, this approach does not work with the embedded iFrame. You have to either use a CDN or React.
For more details, take at the [Send Backchannel Welcome Event](https://github.com/microsoft/BotFramework-WebCh... | Unfortunately, you can't currently send any hidden information through the Web Chat channel.
What you can do is use the `DirectLine` channel along with the [WebChat web control](https://github.com/microsoft/BotFramework-WebChat). Then you can pass arbitrary data like your name and ticket id in the channel data object... |
8,959,116 | I had this solution working happily and i added this attribute:
```
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = true)]
public class metadata : Attribute
{
string mid;
string mdescription;
Dictionary<string, string> mdata;
public string id
{
... | 2012/01/22 | [
"https://Stackoverflow.com/questions/8959116",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/996992/"
] | The problem is that KeyValuePair is not supported as attribute parameter type.
According to the [C# Language specification](http://msdn.microsoft.com/en-us/library/aa664615%28v=vs.71%29.aspx):
The types of positional and named parameters for an attribute class are limited to the attribute parameter types, which are:
... | The way you declared the array is suspicious, I don't think you need the params keyword. I don't think you want 0 or more keyvaluepair arrays, I think you are looking for a single array with 0 or more entries. Remove the params keyword, and set the default value of thisdataarray to null. |
10,474 | How I can copy my `public` schema into the same database with full table structure, data, functions, fk, pk and etc.
My version of Postgres is 8.4
P.S. I need to copy **schema** NOT database | 2012/01/10 | [
"https://dba.stackexchange.com/questions/10474",
"https://dba.stackexchange.com",
"https://dba.stackexchange.com/users/5728/"
] | There's no simple way to do this in pg\_dump/pg\_restore itself. You could try the following if you are able to remove the database temporarily.
1. Take a dump of your public schema using [pg\_dump](http://www.postgresql.org/docs/8.4/static/app-pgdump.html)
2. run "ALTER SCHEMA public RENAME TO public\_copy"
3. Restor... | You could use
```
CREATE DATABASE new_db TEMPLATE = old_db;
```
Then drop all schemas you don't need:
```
DROP SCHEMA public CASCADE;
DROP SCHEMA other CASCADE;
```
The only drawback is all connections to old\_db must be determinated before you can create the copy (so the process that runs the `CREATE DATABASE` ... |
10,474 | How I can copy my `public` schema into the same database with full table structure, data, functions, fk, pk and etc.
My version of Postgres is 8.4
P.S. I need to copy **schema** NOT database | 2012/01/10 | [
"https://dba.stackexchange.com/questions/10474",
"https://dba.stackexchange.com",
"https://dba.stackexchange.com/users/5728/"
] | There's no simple way to do this in pg\_dump/pg\_restore itself. You could try the following if you are able to remove the database temporarily.
1. Take a dump of your public schema using [pg\_dump](http://www.postgresql.org/docs/8.4/static/app-pgdump.html)
2. run "ALTER SCHEMA public RENAME TO public\_copy"
3. Restor... | Using pgAdmin you can do the following. It's pretty manual, but might be all you need. A script based approach would be much more desirable. Not sure how well this will work if you don't have admin access and if your database is large, but should work just fine on a development database that you just have on your local... |
10,474 | How I can copy my `public` schema into the same database with full table structure, data, functions, fk, pk and etc.
My version of Postgres is 8.4
P.S. I need to copy **schema** NOT database | 2012/01/10 | [
"https://dba.stackexchange.com/questions/10474",
"https://dba.stackexchange.com",
"https://dba.stackexchange.com/users/5728/"
] | There's no simple way to do this in pg\_dump/pg\_restore itself. You could try the following if you are able to remove the database temporarily.
1. Take a dump of your public schema using [pg\_dump](http://www.postgresql.org/docs/8.4/static/app-pgdump.html)
2. run "ALTER SCHEMA public RENAME TO public\_copy"
3. Restor... | >
>
> ```
> pg_dump -n schema_name > dump.sql
> vi dump.sql # edit the schema name
> psql: psql -f dump.sql
>
> ```
>
>
If you're stuck with php then use either back tics
```
`/usr/bin/pg_dump-n myschema mydb -U username > /tmp/dump.sql`
```
or the exec() command. For the change you can use sed the same way.
... |
10,474 | How I can copy my `public` schema into the same database with full table structure, data, functions, fk, pk and etc.
My version of Postgres is 8.4
P.S. I need to copy **schema** NOT database | 2012/01/10 | [
"https://dba.stackexchange.com/questions/10474",
"https://dba.stackexchange.com",
"https://dba.stackexchange.com/users/5728/"
] | There's no simple way to do this in pg\_dump/pg\_restore itself. You could try the following if you are able to remove the database temporarily.
1. Take a dump of your public schema using [pg\_dump](http://www.postgresql.org/docs/8.4/static/app-pgdump.html)
2. run "ALTER SCHEMA public RENAME TO public\_copy"
3. Restor... | expanding on user1113185 [answer](https://dba.stackexchange.com/a/10475/78639), here's a full workflow using psql/pg\_dump.
The following exports all objects of `old_schema` and imports them into new `new_schema` schema, as `user`, in `dbname` database:
```
psql -U user -d dbname -c 'ALTER SCHEMA old_schema RENAME TO... |
51,563,702 | I have been banging my head at my desk for 3 days now and I am not sure what to do about this issue, so please if you have any idea of what is going on let me know.
**Issue:** When I am running a globally installed (outside of the virtual environment) jupyter notebook with a registered kernel (ipykernel installed in t... | 2018/07/27 | [
"https://Stackoverflow.com/questions/51563702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10078580/"
] | TLDR
====
For me it worked installing `jupyter` in the virtual enviroment created by `pipenv` with the following command:
```
pipenv run pip install jupyter
```
Too Short, Wanna Read!
======================
I had the same problem with python 3 versions so I started using `pipenv` as you show, with a simple `Pipfil... | To make `pipenv` use the `Pipfile` you want when running it from any path you want, you should add to your `~/.bashrc` and `~/.profile` the following env variable:
```
export PIPENV_PIPFILE="<path_to_the_Pipefile_you_want>"
```
Otherwise, `pipenv` will try to use a `Pipefile` from the path where it is being run. |
73,225,600 | I'm trying to plot a scatterplot, but instead of having points or triangles or other symbols, I want to plot numbers. For example, with these points:
```
centroidCoords = [Point(7.210123936676805, -0.0014481952154823),
Point(5.817327756517152, -1.0513260084561042),
Point(5.603133733... | 2022/08/03 | [
"https://Stackoverflow.com/questions/73225600",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18486979/"
] | `console.log` is a void return (*i.e. returns `undefined`*), it doesn't return any Promise object to chain from. Just issue the imperative navigation after the log statement.
```
const handleSubmit = e => {
e.preventDefault();
console.log(inputs);
sendRequest()
.then(data =>
console.log(data);
na... | i changed my code to
```
sendRequest().then((data) => console.log(data)).then(() => navigate('/myBlogs/'))
```
from this
```
sendRequest().then(data =>
console.log(data).then(() => navigate('/myBlogs/'))
);
```
and it works |
71,789,301 | ```
teams = ['Argentina', 'Australia', 'Belgium', 'Brazil', 'Colombia', 'Costa Rica', 'Croatia', 'Denmark', 'Egypt', 'England', 'France', 'Germany', 'Iceland', 'Iran', 'Japan', 'Mexico', 'Morocco', 'Nigeria', 'Panama', 'Peru', 'Poland', 'Portugal', 'Russia', 'Saudi Arabia', 'Senegal', 'Serbia', 'South Korea', 'Spain', ... | 2022/04/07 | [
"https://Stackoverflow.com/questions/71789301",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18249677/"
] | The `wins` dictionary is shared across *all* keys inside the `combined_data` dictionary.
To resolve this issue, use a dictionary comprehension instead:
```py
combined_data = {team: {"wins" : 0} for team in teams}
``` | Your code is not creating a new dictionary for each country, it's putting a reference to *the exact same dictionary* in each key's value. You can see this by running `id()` on two separate keys of the dataframe:
```py
id(combined_data['Argentina']) # 5077746752
id(combined_data['Sweden']) # 5077746752
```
To do ... |
9,678,098 | In `SQL Server Reporting Services`, I was able to make a report that accessed `SQL Server` via a stored procedure. In this stored procedure, I passed along a parameter and the stored procedure returned only data related to that parameter. This worked correctly.
Is it possible to, take that same parameter and pass it ... | 2012/03/13 | [
"https://Stackoverflow.com/questions/9678098",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/854739/"
] | Yes, you can do this by [creating an additional dataset](http://msdn.microsoft.com/en-us/library/ms160345%28v=sql.90%29.aspx), so that you have one dataset for each stored procedure call.
If your report then contains two tables, each table could then reference one of the datasets. | If the columns returns are the same for both the stored procedures then.
You can also create one more stored procedure that takes this parameter's value.
Exec both the stored procedure1 and stored procedure2 based on the parameter value.
Advantage Here You dont need to create the two tables in the report.
LINK: [UN... |
49,549,403 | * [Chrome output](https://i.stack.imgur.com/J6nNn.png)
* [Firefox output](https://i.stack.imgur.com/639OS.png)
```css
.continue-btn {
border: 2px solid #000;
border-radius: 0px!important;
width: 100%;
text-align: center;
padding: 0px;
line-height: 55px;
color: #000;
margin: 6% 0... | 2018/03/29 | [
"https://Stackoverflow.com/questions/49549403",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1140153/"
] | The reason you couldn't find information on any other languages using checked exceptions is they learned from Java's mistake.
EDIT: So to clarify a little more checked exceptions were entirely a Java thing that in theory sounded like a really great idea, but in practice actually create a tight coupling between the con... | Checked exceptions are not a common feature in mainstream languages due to bad experiences with them in Java. However, Java is not the only language that implements them, and just because Java's implementation was faulty does not mean that they are a bad feature in general.
[Nim](https://status-im.github.io/nim-style-... |
3,381,936 | I have shown by tedious case analysis that any formula in the first order logic that does not contain the negation or implication symbol cannot be a contradiction (false under every interpretation). I am wondering if a there is a formula without the not symbol that is a contradiction, and if there is a formula with onl... | 2019/10/05 | [
"https://math.stackexchange.com/questions/3381936",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/287662/"
] | There is no such sentence, and this remains true if we allow $\wedge,\vee,\leftrightarrow$ as well (thus subsuming the previous result you mention).
In fact, fixing a first-order language $\Sigma$, the unique (up to isomorphism) one-element $\Sigma$-structure $\mathcal{A}\_\Sigma$ where every $n$-ary relation holds o... | If such a formula existed, one with a minimal number of implications would contain at least one $\to$ (because you've already checked the case with none), and we could write some such contradiction as $a\to b$. (If $(a\to b)\lor c$ is a contradiction, so is $a\to b$; if $(a\to b)\land c$ is a contradiction, so is $(c\l... |
169,865 | In my kitchen, all our drawers appear to use a wooden rail "hanger" (at the top of the drawer) to slide in and out:
[](https://i.stack.imgur.com/zcij6.jpg)
The problem is our utensil drawer is probably one of the heaviest, and it finally gave out, so... | 2019/07/25 | [
"https://diy.stackexchange.com/questions/169865",
"https://diy.stackexchange.com",
"https://diy.stackexchange.com/users/1125/"
] | You're not answering what Ed Beal and Harper are asking. Is the breaker heating up? You can check that with an infrared thermometer which you can find for somewhere south of $30.00.
You also just revealed the the breaker is an AFCI (arc fault circuit interrupter). It trips when it senses something arcing. It is quite... | Window AC draws more power than a fridge and *they* get a dedicated circuit by code. (mostly because the loss of power to a fridge is a big inconvenience)
That said: Breakers are not peas in a pod. Some will trip below rated capacity (rare) Replacing the breaker with a 20A, given that you have 12 ga wire is a cheap an... |
169,865 | In my kitchen, all our drawers appear to use a wooden rail "hanger" (at the top of the drawer) to slide in and out:
[](https://i.stack.imgur.com/zcij6.jpg)
The problem is our utensil drawer is probably one of the heaviest, and it finally gave out, so... | 2019/07/25 | [
"https://diy.stackexchange.com/questions/169865",
"https://diy.stackexchange.com",
"https://diy.stackexchange.com/users/1125/"
] | You're not answering what Ed Beal and Harper are asking. Is the breaker heating up? You can check that with an infrared thermometer which you can find for somewhere south of $30.00.
You also just revealed the the breaker is an AFCI (arc fault circuit interrupter). It trips when it senses something arcing. It is quite... | You have a fault in the *wiring* in your wall, not the breaker
--------------------------------------------------------------
Most AFCIs, including your Homeline unit, also contain a ground fault trip in order to help them catch firestarting arc-to-ground type faults (note, that the "arcs" AFCIs catch don't have to be... |
169,865 | In my kitchen, all our drawers appear to use a wooden rail "hanger" (at the top of the drawer) to slide in and out:
[](https://i.stack.imgur.com/zcij6.jpg)
The problem is our utensil drawer is probably one of the heaviest, and it finally gave out, so... | 2019/07/25 | [
"https://diy.stackexchange.com/questions/169865",
"https://diy.stackexchange.com",
"https://diy.stackexchange.com/users/1125/"
] | You're not answering what Ed Beal and Harper are asking. Is the breaker heating up? You can check that with an infrared thermometer which you can find for somewhere south of $30.00.
You also just revealed the the breaker is an AFCI (arc fault circuit interrupter). It trips when it senses something arcing. It is quite... | You have an arc fault breaker. It has two jobs:
* Detect current which is excessive
* Detect **arc faults**.
Arc faults are when arcing occurs (when it's not supposed to; obviously throwing a switch is an expected arc). Arcing is the blue-white flash you may have seen when plugging in certain things to certain place... |
52,823,091 | I've been racking my brain for a couple of days to work out a series or closed-form equation to the following problem:
Specifically: given all strings of length *N* that draws from an alphabet of *L* letters (starting with 'A', for example {A, B}, {A, B, C}, ...), how many of those strings contain a substring that mat... | 2018/10/15 | [
"https://Stackoverflow.com/questions/52823091",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9189482/"
] | It is possible to use dynamic programming approach.
For fixed `L`, let `X(n)` be number of strings of length `n` that contain given pattern, and let `A(n)` be number of strings of length `n` that contain given pattern and starts with A.
First derive recursion formula for `A(n)`. Lets count all strings in `A(n)` by gr... | This can be described as a state machine. (For simplicity, `x` is any letter other than `A`.)
```
S0 := 'A' S1 | 'x' S0 // ""
S1 := 'A' S1 | 'x' S2 // A
S2 := 'A' S1 | 'x' S3 // Ax
S3 := 'A' S4 | 'x' S3 // Axx+
S4 := 'A' S4 | 'x' S4 | $ // AxxA
```
Counting the number of matching strings of length `n... |
56,579,837 | i have an issue with an AJAX call to give the response to the main function. Right now i use async false which i know is odd and i try to solve it but fail all the time.
This works (async false):
```
function printTable(){
var $table = $('#Table');
var view_data;
$.ajax({
type: "GET",
u... | 2019/06/13 | [
"https://Stackoverflow.com/questions/56579837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10320484/"
] | Yes, absolutely!
As ever, there is a trade-off, which you've already identified.
But this is a completely normal and sensible thing to do. If you don't need to compute these values every time, then don't.
In this particular case, I'd probably make these items static members of the encapsulating class, unless you hav... | It depends on your context. As you rightly point out you're trading memory usage for speed. So what's more important (if either even) in your context? Are you on the hot path of a low latency program? Are you on a low memory device? |
56,579,837 | i have an issue with an AJAX call to give the response to the main function. Right now i use async false which i know is odd and i try to solve it but fail all the time.
This works (async false):
```
function printTable(){
var $table = $('#Table');
var view_data;
$.ajax({
type: "GET",
u... | 2019/06/13 | [
"https://Stackoverflow.com/questions/56579837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10320484/"
] | That seems like a viable option. I have one suggested change for your sample, and that is to call `getApiUrl()` within the second static's initializer, making it the only initializer... thusly:
```
static const QString endpointUrl = QString("%1/%2").arg(getApiUrl(), "endpoint");
```
That's one less object to keep ar... | It depends on your context. As you rightly point out you're trading memory usage for speed. So what's more important (if either even) in your context? Are you on the hot path of a low latency program? Are you on a low memory device? |
56,579,837 | i have an issue with an AJAX call to give the response to the main function. Right now i use async false which i know is odd and i try to solve it but fail all the time.
This works (async false):
```
function printTable(){
var $table = $('#Table');
var view_data;
$.ajax({
type: "GET",
u... | 2019/06/13 | [
"https://Stackoverflow.com/questions/56579837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10320484/"
] | For your specific example
=========================
In your example caching will make basically no performance difference, so using `static` is probably the only method that's worth it's effort.
If your calculation was actually expensive, here are some thoughts on this way of caching in general:
In General
=========... | It depends on your context. As you rightly point out you're trading memory usage for speed. So what's more important (if either even) in your context? Are you on the hot path of a low latency program? Are you on a low memory device? |
56,579,837 | i have an issue with an AJAX call to give the response to the main function. Right now i use async false which i know is odd and i try to solve it but fail all the time.
This works (async false):
```
function printTable(){
var $table = $('#Table');
var view_data;
$.ajax({
type: "GET",
u... | 2019/06/13 | [
"https://Stackoverflow.com/questions/56579837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10320484/"
] | Yes, absolutely!
As ever, there is a trade-off, which you've already identified.
But this is a completely normal and sensible thing to do. If you don't need to compute these values every time, then don't.
In this particular case, I'd probably make these items static members of the encapsulating class, unless you hav... | That seems like a viable option. I have one suggested change for your sample, and that is to call `getApiUrl()` within the second static's initializer, making it the only initializer... thusly:
```
static const QString endpointUrl = QString("%1/%2").arg(getApiUrl(), "endpoint");
```
That's one less object to keep ar... |
56,579,837 | i have an issue with an AJAX call to give the response to the main function. Right now i use async false which i know is odd and i try to solve it but fail all the time.
This works (async false):
```
function printTable(){
var $table = $('#Table');
var view_data;
$.ajax({
type: "GET",
u... | 2019/06/13 | [
"https://Stackoverflow.com/questions/56579837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10320484/"
] | Yes, absolutely!
As ever, there is a trade-off, which you've already identified.
But this is a completely normal and sensible thing to do. If you don't need to compute these values every time, then don't.
In this particular case, I'd probably make these items static members of the encapsulating class, unless you hav... | For your specific example
=========================
In your example caching will make basically no performance difference, so using `static` is probably the only method that's worth it's effort.
If your calculation was actually expensive, here are some thoughts on this way of caching in general:
In General
=========... |
11,634,734 | ```
println("This program allows you to enter your exam results!");
int n0 = readInt("How many exam results do you have? ");
for (int n=1; n<=n0; n++) {
String r0 = "r"+n;
int result = readInt("Result "+n+": ");
println(r0);
}
```
I am new to java and I was wondering if it would be... | 2012/07/24 | [
"https://Stackoverflow.com/questions/11634734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1270911/"
] | I think what you really need to do is have a collection or *array* of results. Anytime you think you need something like:
```
int r0 = ...;
int r1 = ...;
int r2 = ...;
```
etc. then it's good indication that you're looking at some sort of collection.
So in the above example, you'd build an array of *size number of ... | Even if you could, I don't imagine that would be a very good idea! It would be a nightmare to get to them to refer back to them later on.
In your situation, I would just recommend using an array of `int`s for your results instead. |
11,634,734 | ```
println("This program allows you to enter your exam results!");
int n0 = readInt("How many exam results do you have? ");
for (int n=1; n<=n0; n++) {
String r0 = "r"+n;
int result = readInt("Result "+n+": ");
println(r0);
}
```
I am new to java and I was wondering if it would be... | 2012/07/24 | [
"https://Stackoverflow.com/questions/11634734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1270911/"
] | Even if you could, I don't imagine that would be a very good idea! It would be a nightmare to get to them to refer back to them later on.
In your situation, I would just recommend using an array of `int`s for your results instead. | Below I have A program that will work. I would copy the code and try and rewrite it yourself to make sure you fully understand what is going on.
```
import java.util.Scanner;
public class Arrays
{
public static void main(String[] args)
{
// Initialize Variables
int examCount = 0;
doubl... |
11,634,734 | ```
println("This program allows you to enter your exam results!");
int n0 = readInt("How many exam results do you have? ");
for (int n=1; n<=n0; n++) {
String r0 = "r"+n;
int result = readInt("Result "+n+": ");
println(r0);
}
```
I am new to java and I was wondering if it would be... | 2012/07/24 | [
"https://Stackoverflow.com/questions/11634734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1270911/"
] | I think what you really need to do is have a collection or *array* of results. Anytime you think you need something like:
```
int r0 = ...;
int r1 = ...;
int r2 = ...;
```
etc. then it's good indication that you're looking at some sort of collection.
So in the above example, you'd build an array of *size number of ... | **1.** First **do not declare** `r0 as String` as you **intend to use it as** `integer`, but declare it as `int`, ya offcourse you can convert
**string to integer** using `Integer.parseInt()`.
**eg:**
```
String r0 = "10";
int r = Integer.parseInt(r0);
```
**2.** I will advice you to use **Collection framework** f... |
11,634,734 | ```
println("This program allows you to enter your exam results!");
int n0 = readInt("How many exam results do you have? ");
for (int n=1; n<=n0; n++) {
String r0 = "r"+n;
int result = readInt("Result "+n+": ");
println(r0);
}
```
I am new to java and I was wondering if it would be... | 2012/07/24 | [
"https://Stackoverflow.com/questions/11634734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1270911/"
] | I think what you really need to do is have a collection or *array* of results. Anytime you think you need something like:
```
int r0 = ...;
int r1 = ...;
int r2 = ...;
```
etc. then it's good indication that you're looking at some sort of collection.
So in the above example, you'd build an array of *size number of ... | Below I have A program that will work. I would copy the code and try and rewrite it yourself to make sure you fully understand what is going on.
```
import java.util.Scanner;
public class Arrays
{
public static void main(String[] args)
{
// Initialize Variables
int examCount = 0;
doubl... |
11,634,734 | ```
println("This program allows you to enter your exam results!");
int n0 = readInt("How many exam results do you have? ");
for (int n=1; n<=n0; n++) {
String r0 = "r"+n;
int result = readInt("Result "+n+": ");
println(r0);
}
```
I am new to java and I was wondering if it would be... | 2012/07/24 | [
"https://Stackoverflow.com/questions/11634734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1270911/"
] | **1.** First **do not declare** `r0 as String` as you **intend to use it as** `integer`, but declare it as `int`, ya offcourse you can convert
**string to integer** using `Integer.parseInt()`.
**eg:**
```
String r0 = "10";
int r = Integer.parseInt(r0);
```
**2.** I will advice you to use **Collection framework** f... | Below I have A program that will work. I would copy the code and try and rewrite it yourself to make sure you fully understand what is going on.
```
import java.util.Scanner;
public class Arrays
{
public static void main(String[] args)
{
// Initialize Variables
int examCount = 0;
doubl... |
45,295,081 | Data set:

For the above data set I want to count the number of different entries in the fourth column. I have code in Python but not able to implement it in Java using Spark.
Python code:
```
user_data = sc.textFile(dataSet path)
//counting number of occupations
num_... | 2017/07/25 | [
"https://Stackoverflow.com/questions/45295081",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8361502/"
] | You can create a custom `IHttpActionResult` which decorates a real one but exposes a way to manipulate the response:
```
public class CustomResult : IHttpActionResult
{
private readonly IHttpActionResult _decorated;
private readonly Action<HttpResponseMessage> _response;
public CustomResult(IHttpActionRes... | You can add header by using this code:
```
HttpContext.Current.Response.AppendHeader("Some-Header", value);
```
or this
```
response.Headers.Add("Some-Header", value);
``` |
45,295,081 | Data set:

For the above data set I want to count the number of different entries in the fourth column. I have code in Python but not able to implement it in Java using Spark.
Python code:
```
user_data = sc.textFile(dataSet path)
//counting number of occupations
num_... | 2017/07/25 | [
"https://Stackoverflow.com/questions/45295081",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8361502/"
] | You can continue to use the `HttpResponseMessage` as you are accustom to and update the header. After which you can use the `IHttpActionResult ResponseMessage(HttpResponseMessage)` method to convert to `IHttpActionResult`
Simple example
```
public class MyApiController : ApiController {
public IHttpActionResult ... | You can add header by using this code:
```
HttpContext.Current.Response.AppendHeader("Some-Header", value);
```
or this
```
response.Headers.Add("Some-Header", value);
``` |
59,781,296 | Why would I need to create a blob snapshot and incur additional cost if Azure already provides GRS(Geo redundant storage) or ZRS (Zone redundant storage)? | 2020/01/17 | [
"https://Stackoverflow.com/questions/59781296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1545193/"
] | Redundancy (ZRS/GRS/RAGRS) provides means to achieve high availability of your resources (blobs in your scenario). By enabling redundancy you are ensuring that a copy of your blob is available in another region/zone in case primary region/zone is not available. It also ensures against data corruption of the primary blo... | I guess you need to understand the difference between **Backup** and **Redundancy**.
Backups make sure if something is lost, corrupted or stolen, that a copy of the data is available at your disposal.
Redundancy makes sure that if something fails—your computer fails, a drive gets fried, or a server freezes and you ar... |
59,781,296 | Why would I need to create a blob snapshot and incur additional cost if Azure already provides GRS(Geo redundant storage) or ZRS (Zone redundant storage)? | 2020/01/17 | [
"https://Stackoverflow.com/questions/59781296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1545193/"
] | I guess you need to understand the difference between **Backup** and **Redundancy**.
Backups make sure if something is lost, corrupted or stolen, that a copy of the data is available at your disposal.
Redundancy makes sure that if something fails—your computer fails, a drive gets fried, or a server freezes and you ar... | You could also turn soft delete on. That would keep a copy of every blob for every change made to it, even if someone deletes it. Then you set the retention period for those blobs so they would be automatically removed after some period of time.
<https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-soft... |
59,781,296 | Why would I need to create a blob snapshot and incur additional cost if Azure already provides GRS(Geo redundant storage) or ZRS (Zone redundant storage)? | 2020/01/17 | [
"https://Stackoverflow.com/questions/59781296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1545193/"
] | Redundancy (ZRS/GRS/RAGRS) provides means to achieve high availability of your resources (blobs in your scenario). By enabling redundancy you are ensuring that a copy of your blob is available in another region/zone in case primary region/zone is not available. It also ensures against data corruption of the primary blo... | You could also turn soft delete on. That would keep a copy of every blob for every change made to it, even if someone deletes it. Then you set the retention period for those blobs so they would be automatically removed after some period of time.
<https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-soft... |
51,215,821 | I'm trying to invert and flip a two-dimensional array, but something goes wrong! Flipping works ok, but inverting is not.
Can't find a mistake right here:
```
public int[][] flipAndInvert(int[][] A) {
int row = -1;
int col = -1;
int[][] arr = A;
for (int i = 0; i < arr.length; i++) {
row++;
... | 2018/07/06 | [
"https://Stackoverflow.com/questions/51215821",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10043854/"
] | What I think is that since you are using this line:
```
int[][] arr = A;
```
The reference of the array is being passed to arr, and hence the line:
```
arr[row][col] = A[i][j];
```
is equivalent to:
```
A[row][col] = A[i][j];
```
as arr has an reference to A and they both now refer to the same memory location ... | Using apache commons lang:
```
int[][] matrix = new int[3][3];
for (int i = 0; i < matrix.length; i++) {
matrix[i][0] = 3 * i;
matrix[i][1] = 3 * i + 1;
matrix[i][2] = 3 * i + 2;
}
System.out.println(Arrays.toString(matrix[0]));
System.out.println(Arrays.toString(matrix[1])... |
51,215,821 | I'm trying to invert and flip a two-dimensional array, but something goes wrong! Flipping works ok, but inverting is not.
Can't find a mistake right here:
```
public int[][] flipAndInvert(int[][] A) {
int row = -1;
int col = -1;
int[][] arr = A;
for (int i = 0; i < arr.length; i++) {
row++;
... | 2018/07/06 | [
"https://Stackoverflow.com/questions/51215821",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10043854/"
] | The problem of your code should be this line:
```
int[][] arr = A;
```
You are assigning the reference of array `A` to `arr` and from then when you modify one you modify both of the arrays or better they are modified together because they refer to the same address. | Using apache commons lang:
```
int[][] matrix = new int[3][3];
for (int i = 0; i < matrix.length; i++) {
matrix[i][0] = 3 * i;
matrix[i][1] = 3 * i + 1;
matrix[i][2] = 3 * i + 2;
}
System.out.println(Arrays.toString(matrix[0]));
System.out.println(Arrays.toString(matrix[1])... |
51,215,821 | I'm trying to invert and flip a two-dimensional array, but something goes wrong! Flipping works ok, but inverting is not.
Can't find a mistake right here:
```
public int[][] flipAndInvert(int[][] A) {
int row = -1;
int col = -1;
int[][] arr = A;
for (int i = 0; i < arr.length; i++) {
row++;
... | 2018/07/06 | [
"https://Stackoverflow.com/questions/51215821",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10043854/"
] | What I think is that since you are using this line:
```
int[][] arr = A;
```
The reference of the array is being passed to arr, and hence the line:
```
arr[row][col] = A[i][j];
```
is equivalent to:
```
A[row][col] = A[i][j];
```
as arr has an reference to A and they both now refer to the same memory location ... | The problem of your code should be this line:
```
int[][] arr = A;
```
You are assigning the reference of array `A` to `arr` and from then when you modify one you modify both of the arrays or better they are modified together because they refer to the same address. |
8,829,284 | I have no idea why this error is occurring after debugging the project even though the codes are default.
Controller
```
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
}
```
View
```
@{
Layout = null;
}
<!DOCTYPE html>... | 2012/01/12 | [
"https://Stackoverflow.com/questions/8829284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/502908/"
] | I think you just have your visual studio settings set so that the view is set to the start page. Right click on the project and go to properties, then to the web tab. Is the 'specific page' radio button selected with 'Views/Home/Index.cshtml' set as the value? Change it to use a start url. Personally I prefer not to ha... | Right click your web project -> Properties -> Web
check that you have the start action set to Specific Page with no value in the field.
My guess is that you have the start action set to current page. |
8,829,284 | I have no idea why this error is occurring after debugging the project even though the codes are default.
Controller
```
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
}
```
View
```
@{
Layout = null;
}
<!DOCTYPE html>... | 2012/01/12 | [
"https://Stackoverflow.com/questions/8829284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/502908/"
] | I think you just have your visual studio settings set so that the view is set to the start page. Right click on the project and go to properties, then to the web tab. Is the 'specific page' radio button selected with 'Views/Home/Index.cshtml' set as the value? Change it to use a start url. Personally I prefer not to ha... | This error might even cause if the hierarchy of the folder structure is incorrect in Views folder.
If you are adding views by right-click on Views folder.The new view added might be incorrectly placed in the folder hierarchy.
The way to troubleshoot the problem is:
Consider a view named index.ascx which is supposed to... |
8,829,284 | I have no idea why this error is occurring after debugging the project even though the codes are default.
Controller
```
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
}
```
View
```
@{
Layout = null;
}
<!DOCTYPE html>... | 2012/01/12 | [
"https://Stackoverflow.com/questions/8829284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/502908/"
] | Right click your web project -> Properties -> Web
check that you have the start action set to Specific Page with no value in the field.
My guess is that you have the start action set to current page. | This error might even cause if the hierarchy of the folder structure is incorrect in Views folder.
If you are adding views by right-click on Views folder.The new view added might be incorrectly placed in the folder hierarchy.
The way to troubleshoot the problem is:
Consider a view named index.ascx which is supposed to... |
47,056,387 | HTML5 audio does not seem to work on Firefox and Opera:
```
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
```
You can test it from [here](https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_au... | 2017/11/01 | [
"https://Stackoverflow.com/questions/47056387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/413225/"
] | * Add this hibernate property in your `application.properties` file:
```
spring.jpa.hibernate.ddl-auto=create-drop
```
Or
```
spring.jpa.hibernate.ddl-auto=create
```
From [documentation](http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl) :
>
> **crea... | The thing that worked for me was adding this line to **application.properties**:
```
spring.datasource.initialize=false
``` |
47,056,387 | HTML5 audio does not seem to work on Firefox and Opera:
```
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
```
You can test it from [here](https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_au... | 2017/11/01 | [
"https://Stackoverflow.com/questions/47056387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/413225/"
] | * Add this hibernate property in your `application.properties` file:
```
spring.jpa.hibernate.ddl-auto=create-drop
```
Or
```
spring.jpa.hibernate.ddl-auto=create
```
From [documentation](http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl) :
>
> **crea... | One of the reason could be, if your entity classes are in a completely different package than your main application package.
This could prevent your entities from being scanned. As there would be no scanned entities, no tables would be inserted to your database, meaning you wouldn't even see any obvious exceptions or ... |
47,056,387 | HTML5 audio does not seem to work on Firefox and Opera:
```
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
```
You can test it from [here](https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_au... | 2017/11/01 | [
"https://Stackoverflow.com/questions/47056387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/413225/"
] | * Add this hibernate property in your `application.properties` file:
```
spring.jpa.hibernate.ddl-auto=create-drop
```
Or
```
spring.jpa.hibernate.ddl-auto=create
```
From [documentation](http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl) :
>
> **crea... | The data.sql gets initialized first in spring boot. So, it tries to insert the data before creating the table by @Entity...
To solve this issue, add this code to your application.properties.
*spring.jpa.defer-datasource-initialization = true* |
47,056,387 | HTML5 audio does not seem to work on Firefox and Opera:
```
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
```
You can test it from [here](https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_au... | 2017/11/01 | [
"https://Stackoverflow.com/questions/47056387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/413225/"
] | The thing that worked for me was adding this line to **application.properties**:
```
spring.datasource.initialize=false
``` | The data.sql gets initialized first in spring boot. So, it tries to insert the data before creating the table by @Entity...
To solve this issue, add this code to your application.properties.
*spring.jpa.defer-datasource-initialization = true* |
47,056,387 | HTML5 audio does not seem to work on Firefox and Opera:
```
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
```
You can test it from [here](https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_au... | 2017/11/01 | [
"https://Stackoverflow.com/questions/47056387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/413225/"
] | One of the reason could be, if your entity classes are in a completely different package than your main application package.
This could prevent your entities from being scanned. As there would be no scanned entities, no tables would be inserted to your database, meaning you wouldn't even see any obvious exceptions or ... | The data.sql gets initialized first in spring boot. So, it tries to insert the data before creating the table by @Entity...
To solve this issue, add this code to your application.properties.
*spring.jpa.defer-datasource-initialization = true* |
622,888 | I am using in my document the `concmath` package, but there is no blackboard bold font linked to the command `\mathbb{}` with this font package. I already asked this question elsewhere and I got this solution :
```
\makeatletter
\def\afterfi#1#2\fi{\fi#1}
\def\map#1#2{\mapA{}#1#2\@nnil}
\def\mapA#1#2#3{\ifx\@nnil#3\em... | 2021/11/17 | [
"https://tex.stackexchange.com/questions/622888",
"https://tex.stackexchange.com",
"https://tex.stackexchange.com/users/248264/"
] | An alternative is to use the [`ccfonts`](http://mirrors.ctan.org/macros/latex/contrib/ccfonts/ccfonts.pdf) package, which is still being updated. The `concmath` package is from last century.
```
\usepackage[T1]{fontenc}
\usepackage{amssymb}
\usepackage{ccfonts}
```
loads either the AMS or Concrete version of all the... | From the documentation:
>
> The ‘amsfonts’ and ‘amssymb’ options: These options provide the functionality of the standard ‘amsfonts’ and ‘amssymb’ packages, but using the Concrete
> versions of the AMS symbol fonts and math alphabets.
>
>
>
```
\documentclass{article}
\usepackage[amssymb]{concmath}
\begin{documen... |
51,352,929 | today, suddendly, all my **Android Emulators** (on Win10 / IntelliJ IDEA),
started complaining about a missing library.
When i launch any emulator, during loading, i read on the console log:
**Emulator: Could not load library 'WinHvPlatform.dll'**
then, the emulator starts and seems to run OK.
But... does anyone ha... | 2018/07/15 | [
"https://Stackoverflow.com/questions/51352929",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8846877/"
] | Using a variable to check if header is added or not may be helpful. If header added it will not add second times
```
header_added = False
for team in team_list:
do_some stuff
with open('MLB_Active_Roster.csv', 'a', newline='') as fp:
f = csv.writer(fp)
if not header_added:
f.writer... | Another method would be to simply do it before the for loop so you do not have to check if already written.
```
import requests
import csv
from bs4 import BeautifulSoup
team_list={'yankees','redsox'}
with open('MLB_Active_Roster.csv', 'w', newline='') as fp:
f = csv.writer(fp)
f.writerow(['Name','ID','Number... |
51,352,929 | today, suddendly, all my **Android Emulators** (on Win10 / IntelliJ IDEA),
started complaining about a missing library.
When i launch any emulator, during loading, i read on the console log:
**Emulator: Could not load library 'WinHvPlatform.dll'**
then, the emulator starts and seems to run OK.
But... does anyone ha... | 2018/07/15 | [
"https://Stackoverflow.com/questions/51352929",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8846877/"
] | Using a variable to check if header is added or not may be helpful. If header added it will not add second times
```
header_added = False
for team in team_list:
do_some stuff
with open('MLB_Active_Roster.csv', 'a', newline='') as fp:
f = csv.writer(fp)
if not header_added:
f.writer... | Just write the header before the loop, and have the loop within the `with` context manager:
```
import requests
import csv
from bs4 import BeautifulSoup
team_list = {'yankees', 'redsox'}
headers = ['Name', 'ID', 'Number', 'Hand', 'Height', 'Weight', 'DOB', 'Team']
# 1. wrap everything in context manager
with open('... |
51,352,929 | today, suddendly, all my **Android Emulators** (on Win10 / IntelliJ IDEA),
started complaining about a missing library.
When i launch any emulator, during loading, i read on the console log:
**Emulator: Could not load library 'WinHvPlatform.dll'**
then, the emulator starts and seems to run OK.
But... does anyone ha... | 2018/07/15 | [
"https://Stackoverflow.com/questions/51352929",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8846877/"
] | Another method would be to simply do it before the for loop so you do not have to check if already written.
```
import requests
import csv
from bs4 import BeautifulSoup
team_list={'yankees','redsox'}
with open('MLB_Active_Roster.csv', 'w', newline='') as fp:
f = csv.writer(fp)
f.writerow(['Name','ID','Number... | Just write the header before the loop, and have the loop within the `with` context manager:
```
import requests
import csv
from bs4 import BeautifulSoup
team_list = {'yankees', 'redsox'}
headers = ['Name', 'ID', 'Number', 'Hand', 'Height', 'Weight', 'DOB', 'Team']
# 1. wrap everything in context manager
with open('... |
53,751,987 | I have a `.world` file in ROS for gazebo simulation which is an XML file.
How can I put on a dynamic home path instead of the static path in `<uri>` tag?
---
Here's my simplified `.world` file:
```
<?xml version="1.0" ?>
<sdf version='1.5'>
<world name='default'>
<visual name='base_link_visual_front_sonar'>
... | 2018/12/12 | [
"https://Stackoverflow.com/questions/53751987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3702377/"
] | Based on SCouto answer, I give you the complete solution that worked for me:
```
def myUDF: UserDefinedFunction = udf(
(s1: String, s2: String) => {
val splitted1 = s1.split(",")
val splitted2 = s2.split(",")
splitted1.intersect(splitted2).length
})
val spark = SparkSession.builder().master("local").getOrCr... | That error means that your udf is returning unit ( no return at all, as void un Java )
Try this. You are applying the intersect over the original s1 and S2 rather than over the splitted ones.
`def myUDF = udf((s1: String, s2: String) =>{`
```
val splitted1 = s1.split(",")
val splitted2= s2.split(",")
splitted... |
53,751,987 | I have a `.world` file in ROS for gazebo simulation which is an XML file.
How can I put on a dynamic home path instead of the static path in `<uri>` tag?
---
Here's my simplified `.world` file:
```
<?xml version="1.0" ?>
<sdf version='1.5'>
<world name='default'>
<visual name='base_link_visual_front_sonar'>
... | 2018/12/12 | [
"https://Stackoverflow.com/questions/53751987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3702377/"
] | Unless I misunderstood your problem, there are standard functions that can help you (so you don't have to write a UDF), i.e. `split` and `array_intersect`.
Given the following dataset:
```
val df = Seq(("Author1,Author2,Author3","Author2,Author3"))
.toDF("source","target")
scala> df.show(false)
+-------------------... | That error means that your udf is returning unit ( no return at all, as void un Java )
Try this. You are applying the intersect over the original s1 and S2 rather than over the splitted ones.
`def myUDF = udf((s1: String, s2: String) =>{`
```
val splitted1 = s1.split(",")
val splitted2= s2.split(",")
splitted... |
53,751,987 | I have a `.world` file in ROS for gazebo simulation which is an XML file.
How can I put on a dynamic home path instead of the static path in `<uri>` tag?
---
Here's my simplified `.world` file:
```
<?xml version="1.0" ?>
<sdf version='1.5'>
<world name='default'>
<visual name='base_link_visual_front_sonar'>
... | 2018/12/12 | [
"https://Stackoverflow.com/questions/53751987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3702377/"
] | Unless I misunderstood your problem, there are standard functions that can help you (so you don't have to write a UDF), i.e. `split` and `array_intersect`.
Given the following dataset:
```
val df = Seq(("Author1,Author2,Author3","Author2,Author3"))
.toDF("source","target")
scala> df.show(false)
+-------------------... | Based on SCouto answer, I give you the complete solution that worked for me:
```
def myUDF: UserDefinedFunction = udf(
(s1: String, s2: String) => {
val splitted1 = s1.split(",")
val splitted2 = s2.split(",")
splitted1.intersect(splitted2).length
})
val spark = SparkSession.builder().master("local").getOrCr... |
38,213,701 | I'm trying in regular expression to not match if '-' is at the end of a string.
Here's a partial of my regex (this is looking at domain part of url, which can't have symbols at beginning or end, but can have '-' in middle of string:
```
(([A-Z0-9])([A-Z0-9-]){0,61}([A-Z0-9]?)[\.]){1,8}
```
This also has to match 1-c... | 2016/07/05 | [
"https://Stackoverflow.com/questions/38213701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1429261/"
] | >
> in short is there a regex code to prevent matching for '-' if it's at the end of the string? And if you can prevent it for beginning, then that would be great too.
>
>
>
Yes you can use negative lookaheads for this:
```
/^(?!-|.*(\.[.-]|-\.|-$))(?:[A-Z0-9-]{0,62}\.){1,8}[A-Z0-9]{3}$/gim
```
[RegEx Demo](htt... | Try:
```
^(([A-Z0-9^-])([A-Z0-9-]){0,61}([A-Z0-9]?)[\.^-]){1,8}$
```
I'm not 100% sure it will work with JS regexes. The idea is: `^` matches beginning of string, `$` matches end, and `^-` in a character class means "anything not a hyphen". |
1,687,282 | I have Google admanager and Jquery and Jquery UI.
But it takes a long time to load the Jquery because Google Admanager.
I have about 30 banners in Google Admanager.
Anybody know how to get the Jquery load first?
Thanks | 2009/11/06 | [
"https://Stackoverflow.com/questions/1687282",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1102592/"
] | I don't think it'll do your folding, but if you're using SQL Server I'd highly recommend [SQL Prompt](http://www.red-gate.com/products/SQL_Prompt/index.htm) which includes a command to reformat SQL. I've found this to be a massive help when debugging/understanding huge and unwieldy stored procedures. | Edit: Nevermind, it doesn't work. `)` isn't being treated as close. Leaving the answer so nobody else wastes their time trying it.
If you're willing to split the lines so there's only one open or close parenthesis on a line, you can use the User Define Language in Notepad++ and make `(` and `)`the folder open and clos... |
1,687,282 | I have Google admanager and Jquery and Jquery UI.
But it takes a long time to load the Jquery because Google Admanager.
I have about 30 banners in Google Admanager.
Anybody know how to get the Jquery load first?
Thanks | 2009/11/06 | [
"https://Stackoverflow.com/questions/1687282",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1102592/"
] | I have a need to do a similar thing. I posted a request for comments and suggests (an RFC you could say). The link to it is here: [Stack Overflow](https://stackoverflow.com/questions/3701317/feature-request-for-a-text-editor-with-support-for-literate-programming-closed). I'm surprised its not a standard feature in most... | Edit: Nevermind, it doesn't work. `)` isn't being treated as close. Leaving the answer so nobody else wastes their time trying it.
If you're willing to split the lines so there's only one open or close parenthesis on a line, you can use the User Define Language in Notepad++ and make `(` and `)`the folder open and clos... |
1,687,282 | I have Google admanager and Jquery and Jquery UI.
But it takes a long time to load the Jquery because Google Admanager.
I have about 30 banners in Google Admanager.
Anybody know how to get the Jquery load first?
Thanks | 2009/11/06 | [
"https://Stackoverflow.com/questions/1687282",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1102592/"
] | See [HideShow mode](http://www.emacswiki.org/emacs/HideShow "HideShow mode") for emacs, which does exactly what you want in lisp-mode. | Edit: Nevermind, it doesn't work. `)` isn't being treated as close. Leaving the answer so nobody else wastes their time trying it.
If you're willing to split the lines so there's only one open or close parenthesis on a line, you can use the User Define Language in Notepad++ and make `(` and `)`the folder open and clos... |
16,049,020 | I'm a beginner in PHP. In my code, i want the php script to be executed only when the submit button is clicked (set). So when the page is refreshed, the isset() function should return false. Here is the code for test.php
```
<html>
<head>
<title>A BASIC HTML FORM</title>
<?PHP
if (isset($_POST['Submit1'])) {
$user... | 2013/04/16 | [
"https://Stackoverflow.com/questions/16049020",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1917222/"
] | Realized that my comment was really an answer...
When you "refresh", you refresh the page INCLUDING the POST data (since that was the last "request" made). You would have to re-enter the address of the page to clear it. Sometimes you see "do you really want to send this form again?" prompt when you refresh - this is w... | Refreshing the page will post the already posted form variables again so every time you refresh your page you are re submitting your form and by this you will have always the `isset` condition to true :)
I f you need more explaining tell me :) |
16,049,020 | I'm a beginner in PHP. In my code, i want the php script to be executed only when the submit button is clicked (set). So when the page is refreshed, the isset() function should return false. Here is the code for test.php
```
<html>
<head>
<title>A BASIC HTML FORM</title>
<?PHP
if (isset($_POST['Submit1'])) {
$user... | 2013/04/16 | [
"https://Stackoverflow.com/questions/16049020",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1917222/"
] | Realized that my comment was really an answer...
When you "refresh", you refresh the page INCLUDING the POST data (since that was the last "request" made). You would have to re-enter the address of the page to clear it. Sometimes you see "do you really want to send this form again?" prompt when you refresh - this is w... | Isset() is used to check if a variable example : $variable is actually "set" and is not null. Also when doing a refresh you also refresh the action you have committed and the form data that you have passed. You can think of it as this :
If you go to a shopping website and they tell you to not refresh while your order... |
16,049,020 | I'm a beginner in PHP. In my code, i want the php script to be executed only when the submit button is clicked (set). So when the page is refreshed, the isset() function should return false. Here is the code for test.php
```
<html>
<head>
<title>A BASIC HTML FORM</title>
<?PHP
if (isset($_POST['Submit1'])) {
$user... | 2013/04/16 | [
"https://Stackoverflow.com/questions/16049020",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1917222/"
] | Isset() is used to check if a variable example : $variable is actually "set" and is not null. Also when doing a refresh you also refresh the action you have committed and the form data that you have passed. You can think of it as this :
If you go to a shopping website and they tell you to not refresh while your order... | Refreshing the page will post the already posted form variables again so every time you refresh your page you are re submitting your form and by this you will have always the `isset` condition to true :)
I f you need more explaining tell me :) |
71,240,356 | I prefer `df.plot.scatter()` rather than `plt.scatter()` when doing data exploration. However I'm unable
### Generate Data
```py
n = 1000
data = dict(
x = np.random.rand(n) + np.random.rand(1)[0],
y = np.random.rand(n) + np.random.rand(1)[0],
# color dimension
z = np.exp(np.random.rand(n)) - np.exp(np... | 2022/02/23 | [
"https://Stackoverflow.com/questions/71240356",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5684214/"
] | **Update:**
Starting in pandas 1.5.0, the `norm` parameter will work as expected with `df.plot.scatter`. The bug got fixed in [PR #45966](http://github.com/pandas-dev/pandas/pull/45966).
---
**Original bug:**
[`df.plot.scatter`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.scatter.html) passes... | As mentioned by @tdy, unpacking kwargs doesn't do the trick.
The function [`df.plot.scatter`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.scatter.html) takes the parameters `x, y, s, c`. Additional kwargs are passed to [`df.plot`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plo... |
36,378 | We create PDF files as relevant to a customer's e-mail communication. These PDF's contain some personal information, specific to the client.
The client is emailed a link to the PDF. The link to the PDF contains a 40 byte unique string specific to this communication to ensure uniqueness and to avoid guessing.
Is there ... | 2013/05/23 | [
"https://security.stackexchange.com/questions/36378",
"https://security.stackexchange.com",
"https://security.stackexchange.com/users/26319/"
] | My suggestion would be as follows:
* Store the PDFs on a [LUKS](http://en.wikipedia.org/wiki/LUKS) partition (or GPG full-disk / TrueCrypt full-disk), so that theft of the physical disks should not yield the data.
* Run a secondary HTTP server whose sole job it is to serve these files. Configure your file permissions ... | Regardless of the length and complexity of the unique string, a file name can be guessed or a compromised communication link may be intercepted to learn the file names.
Why aren't you utilizing a method like scp, if all you are doing is to make pdf files available to your client ? This way, you can either force the us... |
36,755,755 | So I have a serializer that looks like this
```
class BuildingsSerializer(serializers.ModelSerializer):
masterlisting_set = serializers.PrimaryKeyRelatedField(many=True,
queryset=Masterlistings.objects.all())
```
and it works great
```
serializer = BuildingsSerializer(Buildi... | 2016/04/20 | [
"https://Stackoverflow.com/questions/36755755",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1401040/"
] | As pointed out by @zymud, queryset argument in PrimaryKeyRelatedField is used for validating field input for creating new entries.
Another solution for filtering out masterlistings\_set is to use serializers.SerializerMethodField() as follows:
```
class BuildingsSerializer(serializers.ModelSerializer):
masterlist... | `queryset` in related field limits only acceptable values. So with `queryset=[]` you will not be able to add new values to `masterlisting_set` or create new `Buildings`.
**UPDATE. How to use queryset for filtering**
This is a little bi tricky - you need to rewrite `ManyRelatedField` and `many_init` method in your `Re... |
21,084,292 | am trying to assign time duration to the playlist.... but as am using onend that function is calling after completing that video, but what i want is the video should play only on its assigned time duration after that it should stops and next video should play..am using following code...
```
<video id="myVideo" height... | 2014/01/13 | [
"https://Stackoverflow.com/questions/21084292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3145475/"
] | Based on the comments on my first answer, here's a reworked one more suited to your needs.
Create a model, e.g. ServiceHours, that next to the data you want to collect (hours done, supervisor\_email, ...), has the following fields:
```
activation_key=models.CharField(_('activation key'), max_length=40, null=True, bla... | You might want to set/unset the `is_active` flag on the user.
Conceptually:
* When a user registers succesfully, be sure to set the flag to False;
* Autogenerate a unique string that is tied to the user's ID and send the activation url via email;
* In the activation view, decompose the key into the user ID and set t... |
492,956 | Was curious if you anyone had information as to why 5GHz wifi is more susceptible to walls and floors in buildings (as compared to 2.4Ghz) but the opposite seems to be true for VHF vs UHF. We tend to use VHF radios outdoors and UHF radios more indoors. Seems like 5GHz is to UHF (both higher freq) as 2.4GHz is to VHF (b... | 2020/04/14 | [
"https://electronics.stackexchange.com/questions/492956",
"https://electronics.stackexchange.com",
"https://electronics.stackexchange.com/users/247424/"
] | This is not the answer that you want to hear :-) :-(.
Propagation in buildings and tunnels and similar is complex.
During "911" they had disastrous results trying to use radios in buildings. A significant number of reports were written and they tended to conclude that around 800 Mhz was optimum. I read through th... | It’s used because it’s an available unlicensed spectrum (same for 2.4GHz and 929-933 MHz.)
But, yes, range through obstructions for these Wi-Fi bands is poor. |
4,431,819 | What are the differences between a program and an application?
I am trying to understand this to form a concept in ontology. Can anyone explain? | 2010/12/13 | [
"https://Stackoverflow.com/questions/4431819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/540863/"
] | My understanding is this:
* A **[computer program](http://en.wikipedia.org/wiki/Computer_program)** is a set of instructions that can be executed on a computer.
* An **[application](http://en.wikipedia.org/wiki/Application_software)** is software that directly helps a user perform tasks.
* The two intersect, but are n... | i guess you mean System Programs and Application programs
System Programs makes the hardware run , Applications are for specific tasks
an Example for System Programs are Device Drivers
as for the Applications you can say web browsers , word porcessros etc |
4,431,819 | What are the differences between a program and an application?
I am trying to understand this to form a concept in ontology. Can anyone explain? | 2010/12/13 | [
"https://Stackoverflow.com/questions/4431819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/540863/"
] | My understanding is this:
* A **[computer program](http://en.wikipedia.org/wiki/Computer_program)** is a set of instructions that can be executed on a computer.
* An **[application](http://en.wikipedia.org/wiki/Application_software)** is software that directly helps a user perform tasks.
* The two intersect, but are n... | A "program" can be as simple as a "set of instructions" to implement a logic.
It can be part of an "application", "component", "service" or another "program".
Application is a possibly a collection of coordinating program instances to solve a user's purpose. |
4,431,819 | What are the differences between a program and an application?
I am trying to understand this to form a concept in ontology. Can anyone explain? | 2010/12/13 | [
"https://Stackoverflow.com/questions/4431819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/540863/"
] | When I studied IT in college my prof. made it simple for me:
"A computer "program" and an "application" (a.k.a. 'app') are one-in-the-same.
The only difference is a technical one. While both are the same, an 'application' is a computer program launched and dependent upon an operating system to execute."
Got it right ... | A "program" can be as simple as a "set of instructions" to implement a logic.
It can be part of an "application", "component", "service" or another "program".
Application is a possibly a collection of coordinating program instances to solve a user's purpose. |
4,431,819 | What are the differences between a program and an application?
I am trying to understand this to form a concept in ontology. Can anyone explain? | 2010/12/13 | [
"https://Stackoverflow.com/questions/4431819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/540863/"
] | My understanding is this:
* A **[computer program](http://en.wikipedia.org/wiki/Computer_program)** is a set of instructions that can be executed on a computer.
* An **[application](http://en.wikipedia.org/wiki/Application_software)** is software that directly helps a user perform tasks.
* The two intersect, but are n... | I use the term program to include applications (apps), utilities and even operating systems like windows, linux and mac OS. We kinda need an overall term for all the different terms available. It might be wrong but works for me. :) |
4,431,819 | What are the differences between a program and an application?
I am trying to understand this to form a concept in ontology. Can anyone explain? | 2010/12/13 | [
"https://Stackoverflow.com/questions/4431819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/540863/"
] | When I studied IT in college my prof. made it simple for me:
"A computer "program" and an "application" (a.k.a. 'app') are one-in-the-same.
The only difference is a technical one. While both are the same, an 'application' is a computer program launched and dependent upon an operating system to execute."
Got it right ... | Without more information about the question, the terms 'program' and 'application' are nearly synonymous.
As Saif has indicated, 'application' tends to be used more for non-system related programs. That being said, I don't think it's wrong to describe the operating system as an special application that provides an en... |
4,431,819 | What are the differences between a program and an application?
I am trying to understand this to form a concept in ontology. Can anyone explain? | 2010/12/13 | [
"https://Stackoverflow.com/questions/4431819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/540863/"
] | Without more information about the question, the terms 'program' and 'application' are nearly synonymous.
As Saif has indicated, 'application' tends to be used more for non-system related programs. That being said, I don't think it's wrong to describe the operating system as an special application that provides an en... | I use the term program to include applications (apps), utilities and even operating systems like windows, linux and mac OS. We kinda need an overall term for all the different terms available. It might be wrong but works for me. :) |
4,431,819 | What are the differences between a program and an application?
I am trying to understand this to form a concept in ontology. Can anyone explain? | 2010/12/13 | [
"https://Stackoverflow.com/questions/4431819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/540863/"
] | My understanding is this:
* A **[computer program](http://en.wikipedia.org/wiki/Computer_program)** is a set of instructions that can be executed on a computer.
* An **[application](http://en.wikipedia.org/wiki/Application_software)** is software that directly helps a user perform tasks.
* The two intersect, but are n... | Without more information about the question, the terms 'program' and 'application' are nearly synonymous.
As Saif has indicated, 'application' tends to be used more for non-system related programs. That being said, I don't think it's wrong to describe the operating system as an special application that provides an en... |
4,431,819 | What are the differences between a program and an application?
I am trying to understand this to form a concept in ontology. Can anyone explain? | 2010/12/13 | [
"https://Stackoverflow.com/questions/4431819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/540863/"
] | My understanding is this:
* A **[computer program](http://en.wikipedia.org/wiki/Computer_program)** is a set of instructions that can be executed on a computer.
* An **[application](http://en.wikipedia.org/wiki/Application_software)** is software that directly helps a user perform tasks.
* The two intersect, but are n... | When I studied IT in college my prof. made it simple for me:
"A computer "program" and an "application" (a.k.a. 'app') are one-in-the-same.
The only difference is a technical one. While both are the same, an 'application' is a computer program launched and dependent upon an operating system to execute."
Got it right ... |
4,431,819 | What are the differences between a program and an application?
I am trying to understand this to form a concept in ontology. Can anyone explain? | 2010/12/13 | [
"https://Stackoverflow.com/questions/4431819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/540863/"
] | When I studied IT in college my prof. made it simple for me:
"A computer "program" and an "application" (a.k.a. 'app') are one-in-the-same.
The only difference is a technical one. While both are the same, an 'application' is a computer program launched and dependent upon an operating system to execute."
Got it right ... | I use the term program to include applications (apps), utilities and even operating systems like windows, linux and mac OS. We kinda need an overall term for all the different terms available. It might be wrong but works for me. :) |
4,431,819 | What are the differences between a program and an application?
I am trying to understand this to form a concept in ontology. Can anyone explain? | 2010/12/13 | [
"https://Stackoverflow.com/questions/4431819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/540863/"
] | A "program" can be as simple as a "set of instructions" to implement a logic.
It can be part of an "application", "component", "service" or another "program".
Application is a possibly a collection of coordinating program instances to solve a user's purpose. | I use the term program to include applications (apps), utilities and even operating systems like windows, linux and mac OS. We kinda need an overall term for all the different terms available. It might be wrong but works for me. :) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.