qid int64 1 74.7M | question stringlengths 0 58.3k | date stringlengths 10 10 | metadata list | response_j stringlengths 2 48.3k | response_k stringlengths 2 40.5k |
|---|---|---|---|---|---|
110,870 | In chapter 80, *The Primary*, Neal Stephenson has one of his character describe how the drives of a computer carried through a door (by the police, who where raiding the facility) will have been erased.
Basically, there's an enormous electromagnet around the door frame:
>
> Cantrell is now drawing an elaborate dia... | 2014/05/01 | [
"https://physics.stackexchange.com/questions/110870",
"https://physics.stackexchange.com",
"https://physics.stackexchange.com/users/45702/"
] | There's really two parts to your question, which I'm going to answer separately. First of all, the explicit question:
Could a huge electromagnetic coil erase a hard drive carried through it?
------------------------------------------------------------------------
Sure it could. That's pretty much what a [degausser](h... | I agree that **some** hard drives could be "erased" with the described electromagnet. However, if the hard drive is "magnetically shielded," then it is highly unlikely. If a "high enough" (> 50,000 hertz) frequency is used, the presence of the electromagnet should not be "humanly" detectable. |
110,870 | In chapter 80, *The Primary*, Neal Stephenson has one of his character describe how the drives of a computer carried through a door (by the police, who where raiding the facility) will have been erased.
Basically, there's an enormous electromagnet around the door frame:
>
> Cantrell is now drawing an elaborate dia... | 2014/05/01 | [
"https://physics.stackexchange.com/questions/110870",
"https://physics.stackexchange.com",
"https://physics.stackexchange.com/users/45702/"
] | **Possibly**.
[Degaussing](http://www.dataerasure.com/degauss.php) is the process of destroying data on a hard drive using an electromagnetic field, so there's some scientific basis to the idea. Assuming the electromagnet was sufficiently strong and there was no or very little shielding around the hard drive - which, ... | Yes.
It is definitely possible to erase a hard drive with a strong enough magnetic field. Machines called "degaussers" exist only to erase hard drives in this manner, specifically without removing the drive platters (disks) from an enclosure.
Most degaussers appear to be rated at 8000-10000 Gauss. At the top end, the... |
4,682,796 | I wrote custom Twig loader that fetch templates from database and it works in Twig "standalone" library.
Now i want to use that in Symfony2 but can't find where to change Twig loader via Symfony2 settings.
Thx in advance for any tips on that | 2011/01/13 | [
"https://Stackoverflow.com/questions/4682796",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/201720/"
] | Have a look at [this page](https://github.com/fabpot/symfony/blob/master/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml) at GitHub. Specially `<parameter key="twig.loader.class">Symfony\Bundle\TwigBundle\Loader\Loader</parameter>`
You can configure this key in your config.yml | To overwrite the key in your config.yml you need to do it under services not twig as it's not support in the configuration parser at the moment (2.0.9)
```
twig:
cache:...
debug:...
...
services:
twig.loader:
class: Acme\CoreBundle\Twig\Loader\FilesystemLoader
``` |
4,682,796 | I wrote custom Twig loader that fetch templates from database and it works in Twig "standalone" library.
Now i want to use that in Symfony2 but can't find where to change Twig loader via Symfony2 settings.
Thx in advance for any tips on that | 2011/01/13 | [
"https://Stackoverflow.com/questions/4682796",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/201720/"
] | Register your own twig loader + tell Twig\_Loader\_Chain to try loading with your loader at first. You can create and add as many loaders to your [Twig\_Loader\_Chain](https://github.com/fabpot/Twig/blob/master/lib/Twig/Loader/Chain.php) as you want.
```
services:
Acme.corebundle.twig.loader.filesystem:
cl... | To overwrite the key in your config.yml you need to do it under services not twig as it's not support in the configuration parser at the moment (2.0.9)
```
twig:
cache:...
debug:...
...
services:
twig.loader:
class: Acme\CoreBundle\Twig\Loader\FilesystemLoader
``` |
158,462 | Problem states:
>
> Consider two events $A$ and $B$, with $P(A) = 0.4$ and $Pr(B) = 0.7$. Determine the maximum and the minimum possible values for $P(A \& B)$ and the conditions under which each of these values is attained.
>
>
>
To solve, I considered the event with the lowest probability $A$ to be a subset of ... | 2012/06/14 | [
"https://math.stackexchange.com/questions/158462",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/33007/"
] | Use the fact that
$$P(A\cup B) = P(A) + P(B) - P(A\cap B).$$
This gives you
$$P(A\cup B) = 1.1 - P(A\cap B).$$
Since $P(A\cup B) \le 1$ we have
$$1\ge 1.1 - P(A\cap B),$$
yielding $P(A\cap B)\ge .1$.
If $A\subseteq B$, then $P(A\cap B) = P(A) = .4.$
This represents the largest possible value for $P(A\cap B)$.
so $.1\l... | $$
\begin{align\*}
0\leq P(A \cup B) \leq 1 & \implies 0 \leq P(A)+P(B)-P(A \cap B) \leq 1\\
& \implies 0\leq 0.4 + 0.7 - P(A\cap B) \leq 1 \\
& \implies -1.1\lt -P(A\cap B)\leq -0.1 \\
& \implies 0.1 \leq P(A\cap B) \lt 1.1.
\end{align\*}
$$
So, the minimum possible value of $P(A\cap B)$ is $0.1$ and this is possible... |
1,845,351 | I would like to do something like play.clubpenguin.com.
What it does is that, when you visit the site, maybe using firefox or IE, if you opened a new tab or use other browser, when you visit that site again, it will show something like: "Please close the other browser that opened this page" or something like that.
... | 2009/12/04 | [
"https://Stackoverflow.com/questions/1845351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/224567/"
] | Each time you serve the flash page to the user, generate a random token. Embed this token somewhere in the page, for example as a flashVar. Also, store the most recently generated token in the user's session.
Whenever the flash posts something back to the server, post the token as well. If the token does not match the... | A few options spring to mind...
1. When they first open the site, you'd need to store the user's current state in a cookie or similar, which you'd check for every time you open the site. If the state is Active, then it means they have another window open. The problem in ensuring that the state is cleared when they lea... |
1,845,351 | I would like to do something like play.clubpenguin.com.
What it does is that, when you visit the site, maybe using firefox or IE, if you opened a new tab or use other browser, when you visit that site again, it will show something like: "Please close the other browser that opened this page" or something like that.
... | 2009/12/04 | [
"https://Stackoverflow.com/questions/1845351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/224567/"
] | A few options spring to mind...
1. When they first open the site, you'd need to store the user's current state in a cookie or similar, which you'd check for every time you open the site. If the state is Active, then it means they have another window open. The problem in ensuring that the state is cleared when they lea... | Solution:
Response your clients request with a NO, because you are the webdesign guru that knows what's the best for the client's visitors. the website doens't have to appeal to your client but the client's visitors. and when they are limited so hard on their own computers they are everything but satisfied. |
1,845,351 | I would like to do something like play.clubpenguin.com.
What it does is that, when you visit the site, maybe using firefox or IE, if you opened a new tab or use other browser, when you visit that site again, it will show something like: "Please close the other browser that opened this page" or something like that.
... | 2009/12/04 | [
"https://Stackoverflow.com/questions/1845351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/224567/"
] | try using the below code:
```
window.onload = function(){
if (document.cookie.indexOf("_instance=true") === -1) {
document.cookie = "_instance=true";
// Set the onunload function
window.onunload = function(){
document.cookie ="_instance=true;expires=Thu, 01-Jan-1970 00:00:01 GMT";
};
... | A few options spring to mind...
1. When they first open the site, you'd need to store the user's current state in a cookie or similar, which you'd check for every time you open the site. If the state is Active, then it means they have another window open. The problem in ensuring that the state is cleared when they lea... |
1,845,351 | I would like to do something like play.clubpenguin.com.
What it does is that, when you visit the site, maybe using firefox or IE, if you opened a new tab or use other browser, when you visit that site again, it will show something like: "Please close the other browser that opened this page" or something like that.
... | 2009/12/04 | [
"https://Stackoverflow.com/questions/1845351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/224567/"
] | Each time you serve the flash page to the user, generate a random token. Embed this token somewhere in the page, for example as a flashVar. Also, store the most recently generated token in the user's session.
Whenever the flash posts something back to the server, post the token as well. If the token does not match the... | If you want to forbid access with 2 different logins, you can enforce a rule that lock on a given resource.
The client IP could be one of this lockable ressource: only one session allowed for one given IP address. That would reduce the cheating to people that have multiple public IP addresses. People that shares publ... |
1,845,351 | I would like to do something like play.clubpenguin.com.
What it does is that, when you visit the site, maybe using firefox or IE, if you opened a new tab or use other browser, when you visit that site again, it will show something like: "Please close the other browser that opened this page" or something like that.
... | 2009/12/04 | [
"https://Stackoverflow.com/questions/1845351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/224567/"
] | If you want to forbid access with 2 different logins, you can enforce a rule that lock on a given resource.
The client IP could be one of this lockable ressource: only one session allowed for one given IP address. That would reduce the cheating to people that have multiple public IP addresses. People that shares publ... | Solution:
Response your clients request with a NO, because you are the webdesign guru that knows what's the best for the client's visitors. the website doens't have to appeal to your client but the client's visitors. and when they are limited so hard on their own computers they are everything but satisfied. |
1,845,351 | I would like to do something like play.clubpenguin.com.
What it does is that, when you visit the site, maybe using firefox or IE, if you opened a new tab or use other browser, when you visit that site again, it will show something like: "Please close the other browser that opened this page" or something like that.
... | 2009/12/04 | [
"https://Stackoverflow.com/questions/1845351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/224567/"
] | try using the below code:
```
window.onload = function(){
if (document.cookie.indexOf("_instance=true") === -1) {
document.cookie = "_instance=true";
// Set the onunload function
window.onunload = function(){
document.cookie ="_instance=true;expires=Thu, 01-Jan-1970 00:00:01 GMT";
};
... | If you want to forbid access with 2 different logins, you can enforce a rule that lock on a given resource.
The client IP could be one of this lockable ressource: only one session allowed for one given IP address. That would reduce the cheating to people that have multiple public IP addresses. People that shares publ... |
1,845,351 | I would like to do something like play.clubpenguin.com.
What it does is that, when you visit the site, maybe using firefox or IE, if you opened a new tab or use other browser, when you visit that site again, it will show something like: "Please close the other browser that opened this page" or something like that.
... | 2009/12/04 | [
"https://Stackoverflow.com/questions/1845351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/224567/"
] | Each time you serve the flash page to the user, generate a random token. Embed this token somewhere in the page, for example as a flashVar. Also, store the most recently generated token in the user's session.
Whenever the flash posts something back to the server, post the token as well. If the token does not match the... | Solution:
Response your clients request with a NO, because you are the webdesign guru that knows what's the best for the client's visitors. the website doens't have to appeal to your client but the client's visitors. and when they are limited so hard on their own computers they are everything but satisfied. |
1,845,351 | I would like to do something like play.clubpenguin.com.
What it does is that, when you visit the site, maybe using firefox or IE, if you opened a new tab or use other browser, when you visit that site again, it will show something like: "Please close the other browser that opened this page" or something like that.
... | 2009/12/04 | [
"https://Stackoverflow.com/questions/1845351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/224567/"
] | Each time you serve the flash page to the user, generate a random token. Embed this token somewhere in the page, for example as a flashVar. Also, store the most recently generated token in the user's session.
Whenever the flash posts something back to the server, post the token as well. If the token does not match the... | try using the below code:
```
window.onload = function(){
if (document.cookie.indexOf("_instance=true") === -1) {
document.cookie = "_instance=true";
// Set the onunload function
window.onunload = function(){
document.cookie ="_instance=true;expires=Thu, 01-Jan-1970 00:00:01 GMT";
};
... |
1,845,351 | I would like to do something like play.clubpenguin.com.
What it does is that, when you visit the site, maybe using firefox or IE, if you opened a new tab or use other browser, when you visit that site again, it will show something like: "Please close the other browser that opened this page" or something like that.
... | 2009/12/04 | [
"https://Stackoverflow.com/questions/1845351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/224567/"
] | try using the below code:
```
window.onload = function(){
if (document.cookie.indexOf("_instance=true") === -1) {
document.cookie = "_instance=true";
// Set the onunload function
window.onunload = function(){
document.cookie ="_instance=true;expires=Thu, 01-Jan-1970 00:00:01 GMT";
};
... | Solution:
Response your clients request with a NO, because you are the webdesign guru that knows what's the best for the client's visitors. the website doens't have to appeal to your client but the client's visitors. and when they are limited so hard on their own computers they are everything but satisfied. |
9,661,008 | I am trying to generate a SHA256 hash in android, that I then pass to an ASP.NET Web API web service and compare the hash there. As such, I need to construct a hash in Android, that given the same inputs in ASP.NET will generate an equivalent hash. I'm pulling my hair out trying to figure out what I'm doing wrong.
Her... | 2012/03/12 | [
"https://Stackoverflow.com/questions/9661008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/988216/"
] | Your Java code is wrong: you are adding the input bytes twice. If you are calculating this in one go, you need to either call only `digest(bytes)` or call `digest()` after `update(bytes)`; | I was looking for a **Kotlin** version for my Android app.
I could not find one; here is what I came up with:
```
fun String.getSha256(): String {
val digest = MessageDigest.getInstance("SHA-256").apply { reset() }
val byteData: ByteArray = digest.digest(this.toByteArray())
return StringBuffer().apply {
... |
9,661,008 | I am trying to generate a SHA256 hash in android, that I then pass to an ASP.NET Web API web service and compare the hash there. As such, I need to construct a hash in Android, that given the same inputs in ASP.NET will generate an equivalent hash. I'm pulling my hair out trying to figure out what I'm doing wrong.
Her... | 2012/03/12 | [
"https://Stackoverflow.com/questions/9661008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/988216/"
] | Your Java code is wrong: you are adding the input bytes twice. If you are calculating this in one go, you need to either call only `digest(bytes)` or call `digest()` after `update(bytes)`; | Migrating OP's solution from the question to an answer:
>
> Here is the corrected Android/Java implementation (based on [Nikolay Elenkov's answer](https://stackoverflow.com/questions/9661008/compute-sha256-hash-in-android-java-and-c-sharp/9661804#9661804)):
>
>
>
> ```
> public String computeHash(String input) thr... |
9,661,008 | I am trying to generate a SHA256 hash in android, that I then pass to an ASP.NET Web API web service and compare the hash there. As such, I need to construct a hash in Android, that given the same inputs in ASP.NET will generate an equivalent hash. I'm pulling my hair out trying to figure out what I'm doing wrong.
Her... | 2012/03/12 | [
"https://Stackoverflow.com/questions/9661008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/988216/"
] | I was looking for a **Kotlin** version for my Android app.
I could not find one; here is what I came up with:
```
fun String.getSha256(): String {
val digest = MessageDigest.getInstance("SHA-256").apply { reset() }
val byteData: ByteArray = digest.digest(this.toByteArray())
return StringBuffer().apply {
... | Migrating OP's solution from the question to an answer:
>
> Here is the corrected Android/Java implementation (based on [Nikolay Elenkov's answer](https://stackoverflow.com/questions/9661008/compute-sha256-hash-in-android-java-and-c-sharp/9661804#9661804)):
>
>
>
> ```
> public String computeHash(String input) thr... |
35,626 | As I prepare for fall around here (USDA zone 8a, max low ~10f, average low ~45f) I long for a greenhouse to bet overwinter some of our showy pots, and perhaps get a jump on some annuals and veggies as next spring rolls around. It's no small task to add a greenhouse to our property (plus I have to check local building c... | 2017/09/26 | [
"https://gardening.stackexchange.com/questions/35626",
"https://gardening.stackexchange.com",
"https://gardening.stackexchange.com/users/16406/"
] | Easy as can be. Seeds are not some magical movie monster that cannot be killed.
Put them in a pan, bake at 250°F / 120°C (or higher, but that should be adequate) for an hour, they should be good and dead.
Or - wrap in aluminum foil, place in fire, cover with coals (if you don't want them in your oven/house) You could... | Oh shoot. If you are looking at dried seeds it is way too late to do anything at all about deactivating those seed. Sorrryyy. The best time to stop weeds is before the plant is able to flower or shortly after the seeds germinate. Baby plants easily killed.
This plant is a biennial...yes? So easy to eradicate by 'weed ... |
35,626 | As I prepare for fall around here (USDA zone 8a, max low ~10f, average low ~45f) I long for a greenhouse to bet overwinter some of our showy pots, and perhaps get a jump on some annuals and veggies as next spring rolls around. It's no small task to add a greenhouse to our property (plus I have to check local building c... | 2017/09/26 | [
"https://gardening.stackexchange.com/questions/35626",
"https://gardening.stackexchange.com",
"https://gardening.stackexchange.com/users/16406/"
] | You could always just dig a hole and throw them all in (and bury them). Seeds planted too deeply are known not to sprout above the soil, if at all. If it's Morning Glory, you might consider another option.
Another alternative is throwing them in the trash.
If you can't get rid of them and don't want to dig a hole (or... | Oh shoot. If you are looking at dried seeds it is way too late to do anything at all about deactivating those seed. Sorrryyy. The best time to stop weeds is before the plant is able to flower or shortly after the seeds germinate. Baby plants easily killed.
This plant is a biennial...yes? So easy to eradicate by 'weed ... |
41,015,191 | I'm looking for a way to auto connect to people found via the LinkedIn advanced search function. There's plenty of information on doing this from the 'people you may know' page but I can only find the code below that is meant to work on the advanced search page, but doesn't. Any ideas?
```
setInterval(function () {var... | 2016/12/07 | [
"https://Stackoverflow.com/questions/41015191",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7261724/"
] | ```
var i;
var res;
var str1 = "ember";
for(i=0;i < 10000;i++)
{
try {
res = str1.concat(i);
if(document.getElementById(res).innerText == "Connect"){
document.getElementById(res).click();}
console.log(document.getElementById(res).innerText == "Connect");
}
catch(err) {
}
}
``` | There are a few illegal tokens in the code such as `‘,’,“,”` as well as the minus sign `—` which are not the ones used for parsing JavaScript. They should be replaced with `',',",",-`, respectively.
This problem usually happens when you copy text from a PDF or something which is not in pure text format.
```js
setInte... |
41,015,191 | I'm looking for a way to auto connect to people found via the LinkedIn advanced search function. There's plenty of information on doing this from the 'people you may know' page but I can only find the code below that is meant to work on the advanced search page, but doesn't. Any ideas?
```
setInterval(function () {var... | 2016/12/07 | [
"https://Stackoverflow.com/questions/41015191",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7261724/"
] | ```
var i;
var res;
var str1 = "ember";
for(i=0;i < 10000;i++)
{
try {
res = str1.concat(i);
if(document.getElementById(res).innerText == "Connect"){
document.getElementById(res).click();}
console.log(document.getElementById(res).innerText == "Connect");
}
catch(err) {
}
}
``` | Linkedin auto invite (add) script class (JS)
============================================
*For use to connect to other people 1-3rd in Linkedin custom search*
Hello developers, how are you?
I went behind a plugin for Chrome or Firefox that did this type of action, however I only found useless or discontinued codes.
... |
41,015,191 | I'm looking for a way to auto connect to people found via the LinkedIn advanced search function. There's plenty of information on doing this from the 'people you may know' page but I can only find the code below that is meant to work on the advanced search page, but doesn't. Any ideas?
```
setInterval(function () {var... | 2016/12/07 | [
"https://Stackoverflow.com/questions/41015191",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7261724/"
] | ```
var i;
var res;
var str1 = "ember";
for(i=0;i < 10000;i++)
{
try {
res = str1.concat(i);
if(document.getElementById(res).innerText == "Connect"){
document.getElementById(res).click();}
console.log(document.getElementById(res).innerText == "Connect");
}
catch(err) {
}
}
``` | looks like this is not working anymore...
Seems that LinkedIn not use jQuery anymore.
```
VM4213:158 Uncaught ReferenceError: $ is not defined
at Object.setScroll (<anonymous>:158:9)
at <anonymous>:164:22
``` |
58,583,441 | If I have a recycler view that has a few cards and some of the cards are basically a `TextView` which a huge amount of text e.g. spanning 3 screens essentially as the user scrolls, are all the benefits of a recycler view essentially gone and I could have gone with a LinearLayout? | 2019/10/27 | [
"https://Stackoverflow.com/questions/58583441",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9055634/"
] | I am guessing the a variable tracks the row index. You could get the index of the next empty row cell in the column you are adding the values to.
```
def next_available_row(worksheet, col):
return len(worksheet.col_values(col)) + 1
sheet = client.open("Movie Fridays").sheet1
sheet.update_cell(next_available_row(s... | You are going to need to save the current or next value of your a variable somewhere and update it every time the script runs.
You could abuse a cell in the spreadsheet for this, or write it out to a file. |
26,348,737 | Is there a good way to add a certain value to each element in an array in javascript? Essentially, this should be a better way of writing the following:
```
a = [1,2,3,4];
for (i = 0; i < a.length; i++) {
a[i] += 7;
}
```
Maybe using map (but not necessarily)?
Edit:
Or a more interestin... | 2014/10/13 | [
"https://Stackoverflow.com/questions/26348737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/899470/"
] | The following will answer your question, assuming your UIImageView used UIViewContentModeAspectFit:
You have to regard the image sizing of the image inside UIImageView. This depends on how you set the contentMode. According your description, I assume you are using UIViewContentModeAspectFit. The resulting image will a... | Swift 4.2 & 5.0
===============
```
func calculateRectOfImageInImageView(imageView: UIImageView) -> CGRect {
let imageViewSize = imageView.frame.size
let imgSize = imageView.image?.size
guard let imageSize = imgSize else {
return CGRect.zero
}
let scaleWidth = imag... |
26,348,737 | Is there a good way to add a certain value to each element in an array in javascript? Essentially, this should be a better way of writing the following:
```
a = [1,2,3,4];
for (i = 0; i < a.length; i++) {
a[i] += 7;
}
```
Maybe using map (but not necessarily)?
Edit:
Or a more interestin... | 2014/10/13 | [
"https://Stackoverflow.com/questions/26348737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/899470/"
] | The following will answer your question, assuming your UIImageView used UIViewContentModeAspectFit:
You have to regard the image sizing of the image inside UIImageView. This depends on how you set the contentMode. According your description, I assume you are using UIViewContentModeAspectFit. The resulting image will a... | I recommend using built in function AVMakeRectWithAspectRatio.
```
func AVMakeRectWithAspectRatioInsideRect(_ aspectRatio: CGSize, _ boundingRect: CGRect) -> CGRect
```
**Parameters:**
**aspectRatio:**
The width and height ratio (aspect ratio) you want to maintain.
**boundingRect:**
The bounding rectangle you ... |
26,348,737 | Is there a good way to add a certain value to each element in an array in javascript? Essentially, this should be a better way of writing the following:
```
a = [1,2,3,4];
for (i = 0; i < a.length; i++) {
a[i] += 7;
}
```
Maybe using map (but not necessarily)?
Edit:
Or a more interestin... | 2014/10/13 | [
"https://Stackoverflow.com/questions/26348737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/899470/"
] | The following will answer your question, assuming your UIImageView used UIViewContentModeAspectFit:
You have to regard the image sizing of the image inside UIImageView. This depends on how you set the contentMode. According your description, I assume you are using UIViewContentModeAspectFit. The resulting image will a... | Based on the wonderfully simple solution from Janusz, here's what I did:
```
let visibleRect = AVMakeRect(aspectRatio: CGSize(width: image.size.width, height: image.size.height), insideRect: self.frame)
if visibleRect.contains(point) {
// Do something great here...
}
``` |
26,348,737 | Is there a good way to add a certain value to each element in an array in javascript? Essentially, this should be a better way of writing the following:
```
a = [1,2,3,4];
for (i = 0; i < a.length; i++) {
a[i] += 7;
}
```
Maybe using map (but not necessarily)?
Edit:
Or a more interestin... | 2014/10/13 | [
"https://Stackoverflow.com/questions/26348737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/899470/"
] | The following will answer your question, assuming your UIImageView used UIViewContentModeAspectFit:
You have to regard the image sizing of the image inside UIImageView. This depends on how you set the contentMode. According your description, I assume you are using UIViewContentModeAspectFit. The resulting image will a... | **Swift 3.0**
I know its quite late but might help someone in future. Its very simple and inbuilt solution provided by iOS. Just need to:
`import AVFoundation
let imageRect = AVMakeRect(aspectRatio: image.size, insideRect: self.imageView.bounds)` |
26,348,737 | Is there a good way to add a certain value to each element in an array in javascript? Essentially, this should be a better way of writing the following:
```
a = [1,2,3,4];
for (i = 0; i < a.length; i++) {
a[i] += 7;
}
```
Maybe using map (but not necessarily)?
Edit:
Or a more interestin... | 2014/10/13 | [
"https://Stackoverflow.com/questions/26348737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/899470/"
] | Swift 4.2 & 5.0
===============
```
func calculateRectOfImageInImageView(imageView: UIImageView) -> CGRect {
let imageViewSize = imageView.frame.size
let imgSize = imageView.image?.size
guard let imageSize = imgSize else {
return CGRect.zero
}
let scaleWidth = imag... | I recommend using built in function AVMakeRectWithAspectRatio.
```
func AVMakeRectWithAspectRatioInsideRect(_ aspectRatio: CGSize, _ boundingRect: CGRect) -> CGRect
```
**Parameters:**
**aspectRatio:**
The width and height ratio (aspect ratio) you want to maintain.
**boundingRect:**
The bounding rectangle you ... |
26,348,737 | Is there a good way to add a certain value to each element in an array in javascript? Essentially, this should be a better way of writing the following:
```
a = [1,2,3,4];
for (i = 0; i < a.length; i++) {
a[i] += 7;
}
```
Maybe using map (but not necessarily)?
Edit:
Or a more interestin... | 2014/10/13 | [
"https://Stackoverflow.com/questions/26348737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/899470/"
] | Swift 4.2 & 5.0
===============
```
func calculateRectOfImageInImageView(imageView: UIImageView) -> CGRect {
let imageViewSize = imageView.frame.size
let imgSize = imageView.image?.size
guard let imageSize = imgSize else {
return CGRect.zero
}
let scaleWidth = imag... | Based on the wonderfully simple solution from Janusz, here's what I did:
```
let visibleRect = AVMakeRect(aspectRatio: CGSize(width: image.size.width, height: image.size.height), insideRect: self.frame)
if visibleRect.contains(point) {
// Do something great here...
}
``` |
26,348,737 | Is there a good way to add a certain value to each element in an array in javascript? Essentially, this should be a better way of writing the following:
```
a = [1,2,3,4];
for (i = 0; i < a.length; i++) {
a[i] += 7;
}
```
Maybe using map (but not necessarily)?
Edit:
Or a more interestin... | 2014/10/13 | [
"https://Stackoverflow.com/questions/26348737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/899470/"
] | Swift 4.2 & 5.0
===============
```
func calculateRectOfImageInImageView(imageView: UIImageView) -> CGRect {
let imageViewSize = imageView.frame.size
let imgSize = imageView.image?.size
guard let imageSize = imgSize else {
return CGRect.zero
}
let scaleWidth = imag... | **Swift 3.0**
I know its quite late but might help someone in future. Its very simple and inbuilt solution provided by iOS. Just need to:
`import AVFoundation
let imageRect = AVMakeRect(aspectRatio: image.size, insideRect: self.imageView.bounds)` |
26,348,737 | Is there a good way to add a certain value to each element in an array in javascript? Essentially, this should be a better way of writing the following:
```
a = [1,2,3,4];
for (i = 0; i < a.length; i++) {
a[i] += 7;
}
```
Maybe using map (but not necessarily)?
Edit:
Or a more interestin... | 2014/10/13 | [
"https://Stackoverflow.com/questions/26348737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/899470/"
] | I recommend using built in function AVMakeRectWithAspectRatio.
```
func AVMakeRectWithAspectRatioInsideRect(_ aspectRatio: CGSize, _ boundingRect: CGRect) -> CGRect
```
**Parameters:**
**aspectRatio:**
The width and height ratio (aspect ratio) you want to maintain.
**boundingRect:**
The bounding rectangle you ... | **Swift 3.0**
I know its quite late but might help someone in future. Its very simple and inbuilt solution provided by iOS. Just need to:
`import AVFoundation
let imageRect = AVMakeRect(aspectRatio: image.size, insideRect: self.imageView.bounds)` |
26,348,737 | Is there a good way to add a certain value to each element in an array in javascript? Essentially, this should be a better way of writing the following:
```
a = [1,2,3,4];
for (i = 0; i < a.length; i++) {
a[i] += 7;
}
```
Maybe using map (but not necessarily)?
Edit:
Or a more interestin... | 2014/10/13 | [
"https://Stackoverflow.com/questions/26348737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/899470/"
] | Based on the wonderfully simple solution from Janusz, here's what I did:
```
let visibleRect = AVMakeRect(aspectRatio: CGSize(width: image.size.width, height: image.size.height), insideRect: self.frame)
if visibleRect.contains(point) {
// Do something great here...
}
``` | **Swift 3.0**
I know its quite late but might help someone in future. Its very simple and inbuilt solution provided by iOS. Just need to:
`import AVFoundation
let imageRect = AVMakeRect(aspectRatio: image.size, insideRect: self.imageView.bounds)` |
55,997,376 | I created a MongoDB GCE instance using Vagrantfile. Then enabled 'Allow HTTP traffic' and added protocol:port tcp:27017 using the console. Everything works fine, but I want to avoid using the console.
Can anyone help me enable 'Allow HTTP traffic' and add 'port tcp:27017' with Vagrantfile?
Here is part of my Vagrantfi... | 2019/05/05 | [
"https://Stackoverflow.com/questions/55997376",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4833901/"
] | you will have to add a firewall rule and add a "target tag" on it e.g. test-1, then on your vagrant file you will have to use this line google.tags = ['test-1']
Vagrant.configure("2") do |config|
config.vm.box = "google/gce"
```
config.ssh.forward_agent = true
config.vm.provider :google do |google, override|
goo... | Did you check the vagrant [documentation on forwarded ports](https://www.vagrantup.com/docs/networking/forwarded_ports.html#defining-a-forwarded-port)?
Should be something like:
```
Vagrant.configure("2") do |config|
config.vm.box = "google/gce"
config.vm.network "forwarded_port", guest: 80, host: 27017
#... re... |
55,997,376 | I created a MongoDB GCE instance using Vagrantfile. Then enabled 'Allow HTTP traffic' and added protocol:port tcp:27017 using the console. Everything works fine, but I want to avoid using the console.
Can anyone help me enable 'Allow HTTP traffic' and add 'port tcp:27017' with Vagrantfile?
Here is part of my Vagrantfi... | 2019/05/05 | [
"https://Stackoverflow.com/questions/55997376",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4833901/"
] | you will have to add a firewall rule and add a "target tag" on it e.g. test-1, then on your vagrant file you will have to use this line google.tags = ['test-1']
Vagrant.configure("2") do |config|
config.vm.box = "google/gce"
```
config.ssh.forward_agent = true
config.vm.provider :google do |google, override|
goo... | Adding network tags does the job.
`google.tags = ['http-server']` |
3,987,710 | Ello,
I am looking for solutions to equations such as
$$ U ^ \prime (y) - y^{\prime \prime} + \beta y^{\textit{IV}} = 0$$
where $\beta >0$ is a constant and $U(x)$ is a function whose Taylor expansion at the origin equals $ \alpha x^2 + \dots$ for $\alpha >0$ and such that $\lim\_{x \to \infty} = -\infty$.
A prototyp... | 2021/01/16 | [
"https://math.stackexchange.com/questions/3987710",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/143679/"
] | Let G be event that George is selected and J be when John is selected .$$P(G|J)=\frac{n(G\cap J)}{n(J)}=\frac{\binom{8}{1}}{\binom{9}{2}}=2/9$$
**Explanation**: $n(J\cap G)=\binom{8}{1}$ as we are already having to select george and John and we are left to select one person from the rest $ 8$. | It is simply $\frac{2}{9}$ as there are two spots leaving John. So for George to be selected, he has to be one of the two getting selected. Here is another way to look at it -
$P = \frac{8}{9} \times \frac{1}{8} + \frac{1}{9} \times \frac{8}{8} = \frac{2}{9}$ |
3,987,710 | Ello,
I am looking for solutions to equations such as
$$ U ^ \prime (y) - y^{\prime \prime} + \beta y^{\textit{IV}} = 0$$
where $\beta >0$ is a constant and $U(x)$ is a function whose Taylor expansion at the origin equals $ \alpha x^2 + \dots$ for $\alpha >0$ and such that $\lim\_{x \to \infty} = -\infty$.
A prototyp... | 2021/01/16 | [
"https://math.stackexchange.com/questions/3987710",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/143679/"
] | To answer your question about what went wrong with your approach:
I think your solution has a numerator of picking one student from $9$, but it should be $1$ student from $8$ since George and John will have been already selected in this scenario.
Then you get $\frac{8\choose1}{9\choose2}$ giving the correct answer of... | It is simply $\frac{2}{9}$ as there are two spots leaving John. So for George to be selected, he has to be one of the two getting selected. Here is another way to look at it -
$P = \frac{8}{9} \times \frac{1}{8} + \frac{1}{9} \times \frac{8}{8} = \frac{2}{9}$ |
206,664 | I've been developing a custom PHP template engine to suit just my needs and also to get a little more practice with PHP.
What I did was to create a Template class that simply receives as constructor parameter a path to a template file and a string that should be the placeholder for the contents of the pages. In that ... | 2013/07/31 | [
"https://softwareengineering.stackexchange.com/questions/206664",
"https://softwareengineering.stackexchange.com",
"https://softwareengineering.stackexchange.com/users/82383/"
] | I'm not sure if I've understood your problem correctly or not, but that seems to me that *Loading* the data is your problem, not anything else related to your template engine, right?
If yes, my questions is, where are the other contents of your application? I mean where is the page content? Put the meta tags, titles, ... | I cannot give you a specific code example for your problem but the general direction for your problem. If you use a template engine (self programmed or not), it should have the ability to parse templates based on method calls and the ability to assign variables (look for Smarty).
Example:
```
public function display(... |
206,664 | I've been developing a custom PHP template engine to suit just my needs and also to get a little more practice with PHP.
What I did was to create a Template class that simply receives as constructor parameter a path to a template file and a string that should be the placeholder for the contents of the pages. In that ... | 2013/07/31 | [
"https://softwareengineering.stackexchange.com/questions/206664",
"https://softwareengineering.stackexchange.com",
"https://softwareengineering.stackexchange.com/users/82383/"
] | The idea behind using templates (and a template engine) is that you separate the (dynamic) content producing code from the code that is responsible for the visual appearance of the page. To make this separation successful, the application code should not be aware the fact that title and meta tags go in the HTML `<head>... | I cannot give you a specific code example for your problem but the general direction for your problem. If you use a template engine (self programmed or not), it should have the ability to parse templates based on method calls and the ability to assign variables (look for Smarty).
Example:
```
public function display(... |
45,546,644 | this error comes up when I try to makemigrations for my python project.
I don't where to look because i have 5 apps with 5 models and views !
does it have relation with attributes with the same name in different models ?
(i added `related_name='+'` to avoid conflict names).
My django version is : 1.11.3
this is what... | 2017/08/07 | [
"https://Stackoverflow.com/questions/45546644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5968293/"
] | So I created a function `searchForDate` that would check if the date exist in the second array or not, try the below code and here is the [demo](https://eval.in/842443):
```
<?php
$daterange = ['01/10/2017','02/10/2017','03/10/2017','04/10/2017','05/10/2017'];
<table>
<?php foreach($daterange as $key=>$day)
{
?>... | ```
$job = [0 => ['id' =>1,'date' => '03/10/2017'/* ' here*/ ],
1 => ['id' =>2,'date' => '12/10/2017'],
2 => ['id' =>3,'date' => '14/10/2017'],
3 => ['id' =>4,'date' => '13/10/2017'],
4 => ['id' =>5,'date' => '03/10/2017'],
5 => ['id' =>6,'date' => '04/10/2017'],
6 => ['id' =>7,'date' => '05/10/... |
45,546,644 | this error comes up when I try to makemigrations for my python project.
I don't where to look because i have 5 apps with 5 models and views !
does it have relation with attributes with the same name in different models ?
(i added `related_name='+'` to avoid conflict names).
My django version is : 1.11.3
this is what... | 2017/08/07 | [
"https://Stackoverflow.com/questions/45546644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5968293/"
] | Here you have my solution, very similar to yours.
I tried it and it works ok.
```
<?php
$daterange = ['01/10/2017', '02/10/2017', '03/10/2017', '04/10/2017', '05/10/2017'];
$job = [0 => ['id' => 1, 'date' => '03/10/2017'],
1 => ['id' => 2, 'date' => '12/10/2017'],
2 => ['id' => 3, 'date' => '14/10/2017'],
... | ```
$job = [0 => ['id' =>1,'date' => '03/10/2017'/* ' here*/ ],
1 => ['id' =>2,'date' => '12/10/2017'],
2 => ['id' =>3,'date' => '14/10/2017'],
3 => ['id' =>4,'date' => '13/10/2017'],
4 => ['id' =>5,'date' => '03/10/2017'],
5 => ['id' =>6,'date' => '04/10/2017'],
6 => ['id' =>7,'date' => '05/10/... |
45,546,644 | this error comes up when I try to makemigrations for my python project.
I don't where to look because i have 5 apps with 5 models and views !
does it have relation with attributes with the same name in different models ?
(i added `related_name='+'` to avoid conflict names).
My django version is : 1.11.3
this is what... | 2017/08/07 | [
"https://Stackoverflow.com/questions/45546644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5968293/"
] | You only need one loop for this task and you shouldn't repeat whole lines when you are only modifying a single attribute in the line (as a matter of DRYness).
`array_column()` will sufficiently prepare the `$job` data.
This is what I recommend: ([Demo](http://sandbox.onlinephpfunctions.com/code/e0e8eaaf9124f8bb823724... | ```
$job = [0 => ['id' =>1,'date' => '03/10/2017'/* ' here*/ ],
1 => ['id' =>2,'date' => '12/10/2017'],
2 => ['id' =>3,'date' => '14/10/2017'],
3 => ['id' =>4,'date' => '13/10/2017'],
4 => ['id' =>5,'date' => '03/10/2017'],
5 => ['id' =>6,'date' => '04/10/2017'],
6 => ['id' =>7,'date' => '05/10/... |
45,546,644 | this error comes up when I try to makemigrations for my python project.
I don't where to look because i have 5 apps with 5 models and views !
does it have relation with attributes with the same name in different models ?
(i added `related_name='+'` to avoid conflict names).
My django version is : 1.11.3
this is what... | 2017/08/07 | [
"https://Stackoverflow.com/questions/45546644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5968293/"
] | So I created a function `searchForDate` that would check if the date exist in the second array or not, try the below code and here is the [demo](https://eval.in/842443):
```
<?php
$daterange = ['01/10/2017','02/10/2017','03/10/2017','04/10/2017','05/10/2017'];
<table>
<?php foreach($daterange as $key=>$day)
{
?>... | Try this as your for loop.
```
<table>
<?php
foreach ($job as $key => $jdata) {
if (in_array($jdata['date'], $daterange)) {
?>
<tr>
<td>
<input type="radio" checked class="radio-check" name="date" value="">
</td>
... |
45,546,644 | this error comes up when I try to makemigrations for my python project.
I don't where to look because i have 5 apps with 5 models and views !
does it have relation with attributes with the same name in different models ?
(i added `related_name='+'` to avoid conflict names).
My django version is : 1.11.3
this is what... | 2017/08/07 | [
"https://Stackoverflow.com/questions/45546644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5968293/"
] | Here you have my solution, very similar to yours.
I tried it and it works ok.
```
<?php
$daterange = ['01/10/2017', '02/10/2017', '03/10/2017', '04/10/2017', '05/10/2017'];
$job = [0 => ['id' => 1, 'date' => '03/10/2017'],
1 => ['id' => 2, 'date' => '12/10/2017'],
2 => ['id' => 3, 'date' => '14/10/2017'],
... | Try this as your for loop.
```
<table>
<?php
foreach ($job as $key => $jdata) {
if (in_array($jdata['date'], $daterange)) {
?>
<tr>
<td>
<input type="radio" checked class="radio-check" name="date" value="">
</td>
... |
45,546,644 | this error comes up when I try to makemigrations for my python project.
I don't where to look because i have 5 apps with 5 models and views !
does it have relation with attributes with the same name in different models ?
(i added `related_name='+'` to avoid conflict names).
My django version is : 1.11.3
this is what... | 2017/08/07 | [
"https://Stackoverflow.com/questions/45546644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5968293/"
] | You only need one loop for this task and you shouldn't repeat whole lines when you are only modifying a single attribute in the line (as a matter of DRYness).
`array_column()` will sufficiently prepare the `$job` data.
This is what I recommend: ([Demo](http://sandbox.onlinephpfunctions.com/code/e0e8eaaf9124f8bb823724... | Try this as your for loop.
```
<table>
<?php
foreach ($job as $key => $jdata) {
if (in_array($jdata['date'], $daterange)) {
?>
<tr>
<td>
<input type="radio" checked class="radio-check" name="date" value="">
</td>
... |
45,546,644 | this error comes up when I try to makemigrations for my python project.
I don't where to look because i have 5 apps with 5 models and views !
does it have relation with attributes with the same name in different models ?
(i added `related_name='+'` to avoid conflict names).
My django version is : 1.11.3
this is what... | 2017/08/07 | [
"https://Stackoverflow.com/questions/45546644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5968293/"
] | You only need one loop for this task and you shouldn't repeat whole lines when you are only modifying a single attribute in the line (as a matter of DRYness).
`array_column()` will sufficiently prepare the `$job` data.
This is what I recommend: ([Demo](http://sandbox.onlinephpfunctions.com/code/e0e8eaaf9124f8bb823724... | So I created a function `searchForDate` that would check if the date exist in the second array or not, try the below code and here is the [demo](https://eval.in/842443):
```
<?php
$daterange = ['01/10/2017','02/10/2017','03/10/2017','04/10/2017','05/10/2017'];
<table>
<?php foreach($daterange as $key=>$day)
{
?>... |
45,546,644 | this error comes up when I try to makemigrations for my python project.
I don't where to look because i have 5 apps with 5 models and views !
does it have relation with attributes with the same name in different models ?
(i added `related_name='+'` to avoid conflict names).
My django version is : 1.11.3
this is what... | 2017/08/07 | [
"https://Stackoverflow.com/questions/45546644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5968293/"
] | You only need one loop for this task and you shouldn't repeat whole lines when you are only modifying a single attribute in the line (as a matter of DRYness).
`array_column()` will sufficiently prepare the `$job` data.
This is what I recommend: ([Demo](http://sandbox.onlinephpfunctions.com/code/e0e8eaaf9124f8bb823724... | Here you have my solution, very similar to yours.
I tried it and it works ok.
```
<?php
$daterange = ['01/10/2017', '02/10/2017', '03/10/2017', '04/10/2017', '05/10/2017'];
$job = [0 => ['id' => 1, 'date' => '03/10/2017'],
1 => ['id' => 2, 'date' => '12/10/2017'],
2 => ['id' => 3, 'date' => '14/10/2017'],
... |
22,175,505 | This works vertically but I am trying to rotate horizontally by clicking on the image. Can not figure this out! Or there might be an easier way of doing this as well.
```
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Flip Image</title>
<style>
canvas{border:1px sol... | 2014/03/04 | [
"https://Stackoverflow.com/questions/22175505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/844930/"
] | You can rotate image to any angle by just a simple mathematical logic. For example if you want to rotate image to 90 degree. Just use:
```
ctx.rotate(90 * Math.PI/180);
```
*You can set your desired angle in above code and rotate image.*
**UPDATE**
I am adding some code according to your needs. that works on canvas... | I agree to Rajesh's comment, you can set your angle and that will rotate according to the translation performed prior to that. I'd prefer using webkit over canvas sometimes. Here is a fiddle that does the rotation horizontally using CSS webkit, it's much simpler in my opinion.
[Horizontal Rotation Using Webkit](http:/... |
22,175,505 | This works vertically but I am trying to rotate horizontally by clicking on the image. Can not figure this out! Or there might be an easier way of doing this as well.
```
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Flip Image</title>
<style>
canvas{border:1px sol... | 2014/03/04 | [
"https://Stackoverflow.com/questions/22175505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/844930/"
] | You can rotate image to any angle by just a simple mathematical logic. For example if you want to rotate image to 90 degree. Just use:
```
ctx.rotate(90 * Math.PI/180);
```
*You can set your desired angle in above code and rotate image.*
**UPDATE**
I am adding some code according to your needs. that works on canvas... | check that jsfiddle may it help
```
.imageRotateHorizontal{
-moz-animation: spinHorizontal .8s infinite linear;
-o-animation: spinHorizontal .8s infinite linear;
-webkit-animation: spinHorizontal .8s infinite linear;
animation: spinHorizontal .8s infinite linear;
}
@keyframes spinHorizontal {
... |
73,248 | If I want to say that there are two people and each one of them is found in other side of the house. What is the correct way to say it?
>
> 1) There are two people in each side of the house
>
>
> 2) There are two people in each side**s** of the house
>
>
>
And by the way (in the same topic), are the two follow... | 2015/11/14 | [
"https://ell.stackexchange.com/questions/73248",
"https://ell.stackexchange.com",
"https://ell.stackexchange.com/users/12430/"
] | *Two people on each side* means *two people on this side and two people on that side*—four people in all (if there are two sides).
What you mean is *one person on each* side, one on this side and one on that.
If you have not already explained that two sides are involved, you need to say so explicitly:
>
> There is ... | *Each* is used before a singular noun and a singular verb/pronoun is used for it.
>
> Each **item** **consists** of 10 questions. (if there are two items, there are 20 questions)
>
>
> Each of these people **has** some useful talent.
>
>
> Each component can be replaced separately if **it** breaks.
>
>
>
As t... |
264,344 | I have a large file which has special characters in it. There is a multi line code there, that I want to replace with `sed`.
This:
```
text = "\
------ ------\n\n\
This message was automatically generated by email software\n\
The delivery of you... | 2016/02/19 | [
"https://unix.stackexchange.com/questions/264344",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/54880/"
] | Perl to the rescue:
```
perl -i~ -0777 -pe 's/text = "[^"]+"/text = ""/g' input-file
```
* `-i~` will edit the file "in place", leaving a backup copy
* `-0777` reads the whole file at once, not line by line
The substitution `s///` works similarly as in sed (i.e. it matches `text = "` followed by anything but double... | Personally, I would do this in Perl. If we can assume that there are no `"` before the closing `"`, you can do:
```
perl -0pe 's/(text\s*=\s*)".*?"/$1""/s' file
```
The `-0` slurps the entire file, reading it into memory. The `-p` means "print every line (here, a "line" will be the entire file) after applying the sc... |
264,344 | I have a large file which has special characters in it. There is a multi line code there, that I want to replace with `sed`.
This:
```
text = "\
------ ------\n\n\
This message was automatically generated by email software\n\
The delivery of you... | 2016/02/19 | [
"https://unix.stackexchange.com/questions/264344",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/54880/"
] | Perl to the rescue:
```
perl -i~ -0777 -pe 's/text = "[^"]+"/text = ""/g' input-file
```
* `-i~` will edit the file "in place", leaving a backup copy
* `-0777` reads the whole file at once, not line by line
The substitution `s///` works similarly as in sed (i.e. it matches `text = "` followed by anything but double... | You have to check the pattern space and keep pulling in the `N`ext line if it doesn't match e.g.
```
sed '/text = "/{ # if line matches text = "
:b # label b
$!N # pull in the next line (if not the last one)
/"$/!bb # if pattern sp... |
264,344 | I have a large file which has special characters in it. There is a multi line code there, that I want to replace with `sed`.
This:
```
text = "\
------ ------\n\n\
This message was automatically generated by email software\n\
The delivery of you... | 2016/02/19 | [
"https://unix.stackexchange.com/questions/264344",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/54880/"
] | You have to check the pattern space and keep pulling in the `N`ext line if it doesn't match e.g.
```
sed '/text = "/{ # if line matches text = "
:b # label b
$!N # pull in the next line (if not the last one)
/"$/!bb # if pattern sp... | Personally, I would do this in Perl. If we can assume that there are no `"` before the closing `"`, you can do:
```
perl -0pe 's/(text\s*=\s*)".*?"/$1""/s' file
```
The `-0` slurps the entire file, reading it into memory. The `-p` means "print every line (here, a "line" will be the entire file) after applying the sc... |
48,648,018 | I use Framework7 with Phonegap and tried to build a simplistic app. I followed the documentation from here <https://framework7.io/docs/routes.html> to define a custom route, which I further streamlined to just load an about page, but cannot get it to work. In both browser and Phonegap App the link to my custom route do... | 2018/02/06 | [
"https://Stackoverflow.com/questions/48648018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/87994/"
] | >
> the changes get committed to remote repo (force pushed)
>
>
>
That only happens when whoever's doing the push goes out of their way to force it.
That's your problem: people deciding to explicitly overwrite work they didn't do.
In Git, you do
```
git config receive.denyNonFastForwards true
git config receive... | **UPDATE** - Question originally did not specify force push. This completely changes the answer (though not in a way the asker will likely appreciate); preserving the original answer for reference, because it is still the correct way to coordinate changes.
---
A force push specifically means that the person pushing w... |
11,294,361 | I am reading [Computer Networking: A Top-Down Approach 5th (fifth) edition](https://rads.stackoverflow.com/amzn/click/com/B005GLUZ2Q). I have reached chapter two and I wonder if it is possible to actually try out the different application protocols by writing the requests etc? I am using Windows if that matter if you n... | 2012/07/02 | [
"https://Stackoverflow.com/questions/11294361",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/454049/"
] | You should use `telnet` to connect to all of these protocol, do your request, reading the answer and so on.
I'm reading that `telnet` is disabled by default on newer windows version (unbelievable, why? Thank goodness I stopped using it!)... Follow [this guide](http://www.fettesps.com/windows-7-enable-telnet/) to re-en... | Well you can them out like this.... just to name a few...
**Ftp :** `ftp ip_addr` or `ftp domain_name`
**Telnet :** `telnet ip_addr` or `telnet ip_addr:port_no` or `tracert domain_name`
**tracert :** `tracert ip_addr` or `tracert domain_name`
**ping :** `ping ip_addr` or `ping domain_name` |
2,011,375 | Given a permutation, for example:
1234
1243
.
.
4321
Can anybody explain why the differences between numbers are always (no proof, but for all simple permutations) divisible by 9? | 2016/11/13 | [
"https://math.stackexchange.com/questions/2011375",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/388740/"
] | The difference between two numbers of that type is the sum of terms like this:
\begin{equation}
x(10^p-10^q)
\end{equation}
where $x$ is one of the digits (1,2,3 or 4). If $p>q$ you can write:
\begin{equation}
10^p-10^q=10^q(10^{p-q}-1)
\end{equation}
the term between brackets is a power of 10 minus 1, so it is divi... | The digit sum $S()$ of a number $x$, $S(x) \equiv x \bmod 9$.
Therefore every digit permutation $\pi()$ of a number has the same residue $\bmod 9$. This means that the difference between them has zero residue $\bmod 9$:
$x-\pi(x) \equiv S(x) - S(x) \equiv 0 \bmod 9$
And thus the difference is divisble by $9$. |
291,559 | I read this book called Practical Electronics for Invetors,and it says that one of the ways to increase magnetic field strenght of solenoid is to increase the current or increase the number of turns.
That got me thinking,why do induction heaters and induction coupled plasma use small number of turns and high current? ... | 2017/03/10 | [
"https://electronics.stackexchange.com/questions/291559",
"https://electronics.stackexchange.com",
"https://electronics.stackexchange.com/users/141377/"
] | Especially considering size and weight, I'd use a PIC 10F200 microcontroller. It has a oscillator built in, and needs no other components other than a bypass cap to drive a LED. It can also run from a reasonably wide voltage range, including 3.7 V.
The internal oscillator is good to a few percent. The instruction cycl... | Once you started actually talking about your problem, it became clear that you were indeed asking an xy question. The question you really want answered, is "How can I identify a drone by blinking its orientation lights?" or even better, "I'd like to identify a drone by blinking its orientation lights. What should I be ... |
291,559 | I read this book called Practical Electronics for Invetors,and it says that one of the ways to increase magnetic field strenght of solenoid is to increase the current or increase the number of turns.
That got me thinking,why do induction heaters and induction coupled plasma use small number of turns and high current? ... | 2017/03/10 | [
"https://electronics.stackexchange.com/questions/291559",
"https://electronics.stackexchange.com",
"https://electronics.stackexchange.com/users/141377/"
] | Especially considering size and weight, I'd use a PIC 10F200 microcontroller. It has a oscillator built in, and needs no other components other than a bypass cap to drive a LED. It can also run from a reasonably wide voltage range, including 3.7 V.
The internal oscillator is good to a few percent. The instruction cycl... | Here is a quick and dirty design using a ZSCT1555 CMOS timer IC as a VCO and PWM to change not only the duty cycle of color from Yellow to Red with battery voltage but also the frequency up to a 2:1 range for an input voltage range of 3.6 to 3.3V .
I chose ~2kHz high to 4kHz when low Vbat and simulated it here with [*... |
291,559 | I read this book called Practical Electronics for Invetors,and it says that one of the ways to increase magnetic field strenght of solenoid is to increase the current or increase the number of turns.
That got me thinking,why do induction heaters and induction coupled plasma use small number of turns and high current? ... | 2017/03/10 | [
"https://electronics.stackexchange.com/questions/291559",
"https://electronics.stackexchange.com",
"https://electronics.stackexchange.com/users/141377/"
] | Here is a quick and dirty design using a ZSCT1555 CMOS timer IC as a VCO and PWM to change not only the duty cycle of color from Yellow to Red with battery voltage but also the frequency up to a 2:1 range for an input voltage range of 3.6 to 3.3V .
I chose ~2kHz high to 4kHz when low Vbat and simulated it here with [*... | Once you started actually talking about your problem, it became clear that you were indeed asking an xy question. The question you really want answered, is "How can I identify a drone by blinking its orientation lights?" or even better, "I'd like to identify a drone by blinking its orientation lights. What should I be ... |
2,540,882 | I am very confused the View and corresponding controller has to be set in MVC 1.0 project structure. Currently in a default application we have About.aspx page under Home folder and all the controller action is handled in HomeController. This controller mixes up Home action and About action. It makes things messy. I li... | 2010/03/29 | [
"https://Stackoverflow.com/questions/2540882",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/296879/"
] | I think they would want you to have
Views/About/Index.aspx
which /Views/AboutController Index() would point to
Routing Example:
in Global.asax:
```
protected void Application_Start()
{
MyRoutes.RegisterRoutes(RouteTable.Routes);
}
```
then in the MyRoutes class:
```
public class MyRoutes
{
int... | You should probably look at the basic tutorials for the ASP.Net MVC framework. It operates under several conventions - and one of the biggest conventions is the file naming and folder structure.
While the structure you like may be good for simple projects or your personal preference, it's not ideal for large projects.... |
9,960,178 | Why would the function safeBreak() perform as expected in Call 1, but not in Call 2 or Call 2.1?
I'm working on my Minecraft Bukkit plugin [ToolBelt](http://dev.bukkit.org/server-mods/toolbelt/).
One of the tools (PickHax) in my plugin allows the player to delete a block while holding a defined material (default DIAM... | 2012/03/31 | [
"https://Stackoverflow.com/questions/9960178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1038644/"
] | The issue was at a level higher then I posted. Sorry for not including enough data. The original Case 1 call was:
```
if(isUseEvent())
safeBreak(target,event.getPlayer(),physics);
else {
target.setTypeId(0,physics);
subject.sendBlockChange(target.getLocation(), 0, (byte)0);
}
```
The Case 2 call was
``... | Checking an [l-value](http://en.wikipedia.org/wiki/Value_%28computer_science%29) has no effect on the code which generated the l-value. This means the code in the "then" section of your if statement is likely the culprit.
Depending on how the third-party code you're integrating with is designed, things like exceptions... |
199,765 | The first thing that I tried to do is: let y be an arbitrary natural number. I then tried to choose a value for x, but I cannot think of a value in which 2x ≤ y + 1..
So I then tried to prove the negation: ∀x ∈ N, ∃y ∈ N, 2x > y + 1
So I then let x be an arbitrary natural number and tried to set a value for y .... b... | 2012/09/20 | [
"https://math.stackexchange.com/questions/199765",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/41876/"
] | Translate the statement into simple English:
>
> Is there a natural number (call it $x$), such that for every other natural number $y$, the number $y + 1$ is at least twice as large as $x$?
>
>
>
And try rephrasing/simplifying that statement:
>
> Is there a natural number $x$ which is less than or equal to $(y+... | Hint: Let $x$ be the smallest natural number ($0$ or $1$, depending on the convention being used). |
4,205,141 | I have a base path /whatever/foo/
and
`$_GET['path']` should be relative to it.
However how do I accomplish this (reading the directory), without allowing directory traversal?
eg.
```
/\.\.|\.\./
```
Will not filter properly. | 2010/11/17 | [
"https://Stackoverflow.com/questions/4205141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/431790/"
] | It is not sufficient to check for patterns like ../ or the likes. Take "../" for instance which URI encodes to "%2e%2e%2f". If your pattern check happens before a decode, you would miss this traversal attempt. There are some other tricks hackers can do to circumvent a pattern checker especially when using encoded strin... | 1
=
put a null index.htm for -Index block
2
=
filter sQS on start
```
// Path Traversal Attack
if( strpos($_SERVER["QUERY_STRING"], "../") ){
exit("P.T.A. B-(");
}
``` |
4,205,141 | I have a base path /whatever/foo/
and
`$_GET['path']` should be relative to it.
However how do I accomplish this (reading the directory), without allowing directory traversal?
eg.
```
/\.\.|\.\./
```
Will not filter properly. | 2010/11/17 | [
"https://Stackoverflow.com/questions/4205141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/431790/"
] | It is not sufficient to check for patterns like ../ or the likes. Take "../" for instance which URI encodes to "%2e%2e%2f". If your pattern check happens before a decode, you would miss this traversal attempt. There are some other tricks hackers can do to circumvent a pattern checker especially when using encoded strin... | I have written a function to check for traversal:
```
function isTraversal($basePath, $fileName)
{
if (strpos(urldecode($fileName), '..') !== false)
return true;
$realBase = realpath($basePath);
$userPath = $basePath.$fileName;
$realUserPath = realpath($userPath);
while ($realUserPath === f... |
4,205,141 | I have a base path /whatever/foo/
and
`$_GET['path']` should be relative to it.
However how do I accomplish this (reading the directory), without allowing directory traversal?
eg.
```
/\.\.|\.\./
```
Will not filter properly. | 2010/11/17 | [
"https://Stackoverflow.com/questions/4205141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/431790/"
] | ircmaxell's answer wasn't fully correct. I've seen that solution in several snippets but it has a bug which is related to the output of `realpath()`. The `realpath()` function removes the trailing directory separator, so imagine two contiguous directories such as:
```none
/foo/bar/baz/
/foo/bar/baz_baz/
```
As `rea... | I have written a function to check for traversal:
```
function isTraversal($basePath, $fileName)
{
if (strpos(urldecode($fileName), '..') !== false)
return true;
$realBase = realpath($basePath);
$userPath = $basePath.$fileName;
$realUserPath = realpath($userPath);
while ($realUserPath === f... |
4,205,141 | I have a base path /whatever/foo/
and
`$_GET['path']` should be relative to it.
However how do I accomplish this (reading the directory), without allowing directory traversal?
eg.
```
/\.\.|\.\./
```
Will not filter properly. | 2010/11/17 | [
"https://Stackoverflow.com/questions/4205141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/431790/"
] | I have written a function to check for traversal:
```
function isTraversal($basePath, $fileName)
{
if (strpos(urldecode($fileName), '..') !== false)
return true;
$realBase = realpath($basePath);
$userPath = $basePath.$fileName;
$realUserPath = realpath($userPath);
while ($realUserPath === f... | I assume you mean without allowing **users** to traverse the directory yes?
If you are trying to stop your own PHP from traversing the directory you should just make the php work properly in the first place.
What you need to stop users is a modified .htaccess file...
```
Options -Indexes
```
(This all assumes you ... |
4,205,141 | I have a base path /whatever/foo/
and
`$_GET['path']` should be relative to it.
However how do I accomplish this (reading the directory), without allowing directory traversal?
eg.
```
/\.\.|\.\./
```
Will not filter properly. | 2010/11/17 | [
"https://Stackoverflow.com/questions/4205141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/431790/"
] | Well, one option would be to compare the real paths:
```
$basepath = '/foo/bar/baz/';
$realBase = realpath($basepath);
$userpath = $basepath . $_GET['path'];
$realUserPath = realpath($userpath);
if ($realUserPath === false || strpos($realUserPath, $realBase) !== 0) {
//Directory Traversal!
} else {
//Good pa... | 1
=
put a null index.htm for -Index block
2
=
filter sQS on start
```
// Path Traversal Attack
if( strpos($_SERVER["QUERY_STRING"], "../") ){
exit("P.T.A. B-(");
}
``` |
4,205,141 | I have a base path /whatever/foo/
and
`$_GET['path']` should be relative to it.
However how do I accomplish this (reading the directory), without allowing directory traversal?
eg.
```
/\.\.|\.\./
```
Will not filter properly. | 2010/11/17 | [
"https://Stackoverflow.com/questions/4205141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/431790/"
] | Well, one option would be to compare the real paths:
```
$basepath = '/foo/bar/baz/';
$realBase = realpath($basepath);
$userpath = $basepath . $_GET['path'];
$realUserPath = realpath($userpath);
if ($realUserPath === false || strpos($realUserPath, $realBase) !== 0) {
//Directory Traversal!
} else {
//Good pa... | You may be tempted to try and use regex to remove all ../s but there are some nice functions built into PHP that will do a much better job:
```php
$page = basename(realpath($_GET));
```
basename - strips out all directory information from the path e.g. `../pages/about.php` would become `about.php`
realpath - return... |
4,205,141 | I have a base path /whatever/foo/
and
`$_GET['path']` should be relative to it.
However how do I accomplish this (reading the directory), without allowing directory traversal?
eg.
```
/\.\.|\.\./
```
Will not filter properly. | 2010/11/17 | [
"https://Stackoverflow.com/questions/4205141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/431790/"
] | Well, one option would be to compare the real paths:
```
$basepath = '/foo/bar/baz/';
$realBase = realpath($basepath);
$userpath = $basepath . $_GET['path'];
$realUserPath = realpath($userpath);
if ($realUserPath === false || strpos($realUserPath, $realBase) !== 0) {
//Directory Traversal!
} else {
//Good pa... | When looking into the creation of new files or folders, I've figured I can use a two stage approach:
First check for traversal attempts using a custom implementation of a `realpath()` like function, which however works for arbitrary paths, not just existing files. There's a good starting point [here](https://www.php.n... |
4,205,141 | I have a base path /whatever/foo/
and
`$_GET['path']` should be relative to it.
However how do I accomplish this (reading the directory), without allowing directory traversal?
eg.
```
/\.\.|\.\./
```
Will not filter properly. | 2010/11/17 | [
"https://Stackoverflow.com/questions/4205141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/431790/"
] | ircmaxell's answer wasn't fully correct. I've seen that solution in several snippets but it has a bug which is related to the output of `realpath()`. The `realpath()` function removes the trailing directory separator, so imagine two contiguous directories such as:
```none
/foo/bar/baz/
/foo/bar/baz_baz/
```
As `rea... | When looking into the creation of new files or folders, I've figured I can use a two stage approach:
First check for traversal attempts using a custom implementation of a `realpath()` like function, which however works for arbitrary paths, not just existing files. There's a good starting point [here](https://www.php.n... |
4,205,141 | I have a base path /whatever/foo/
and
`$_GET['path']` should be relative to it.
However how do I accomplish this (reading the directory), without allowing directory traversal?
eg.
```
/\.\.|\.\./
```
Will not filter properly. | 2010/11/17 | [
"https://Stackoverflow.com/questions/4205141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/431790/"
] | Well, one option would be to compare the real paths:
```
$basepath = '/foo/bar/baz/';
$realBase = realpath($basepath);
$userpath = $basepath . $_GET['path'];
$realUserPath = realpath($userpath);
if ($realUserPath === false || strpos($realUserPath, $realBase) !== 0) {
//Directory Traversal!
} else {
//Good pa... | It is not sufficient to check for patterns like ../ or the likes. Take "../" for instance which URI encodes to "%2e%2e%2f". If your pattern check happens before a decode, you would miss this traversal attempt. There are some other tricks hackers can do to circumvent a pattern checker especially when using encoded strin... |
4,205,141 | I have a base path /whatever/foo/
and
`$_GET['path']` should be relative to it.
However how do I accomplish this (reading the directory), without allowing directory traversal?
eg.
```
/\.\.|\.\./
```
Will not filter properly. | 2010/11/17 | [
"https://Stackoverflow.com/questions/4205141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/431790/"
] | Well, one option would be to compare the real paths:
```
$basepath = '/foo/bar/baz/';
$realBase = realpath($basepath);
$userpath = $basepath . $_GET['path'];
$realUserPath = realpath($userpath);
if ($realUserPath === false || strpos($realUserPath, $realBase) !== 0) {
//Directory Traversal!
} else {
//Good pa... | I assume you mean without allowing **users** to traverse the directory yes?
If you are trying to stop your own PHP from traversing the directory you should just make the php work properly in the first place.
What you need to stop users is a modified .htaccess file...
```
Options -Indexes
```
(This all assumes you ... |
62,609,862 | I am trying to improve my unit testing skills and i was wondering if someone could tell me the best way of writing a test for writing a test for "sorted odd numbers of a given array of integers". At the moment I am passing the data into the test with params but I would to verify the output is correct aswell.
```
[... | 2020/06/27 | [
"https://Stackoverflow.com/questions/62609862",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13454686/"
] | You should pass your input array and expected array as parameters in your tests .
You can use InlineData like this :
```
[Theory]
[InlineData(new[] { 0, 1, 2, 3, 4 }, new[] { 0, 2, 4 })]
[InlineData(new[] { 0, 1, 3, 4 }, new[] { 0, 4 })]
public void Should_return_odd_numbers_in_ascending_order(int[] i... | You need to pass as a parameter the expected output. From the most basic point of view the unit test should be like:
* input data, preferably all parameters required by tye method to be tested,
* name of the unit test method shoul be descriptive and tell exacly what it is cheking,
* should compare result from tested m... |
62,609,862 | I am trying to improve my unit testing skills and i was wondering if someone could tell me the best way of writing a test for writing a test for "sorted odd numbers of a given array of integers". At the moment I am passing the data into the test with params but I would to verify the output is correct aswell.
```
[... | 2020/06/27 | [
"https://Stackoverflow.com/questions/62609862",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13454686/"
] | You should pass your input array and expected array as parameters in your tests .
You can use InlineData like this :
```
[Theory]
[InlineData(new[] { 0, 1, 2, 3, 4 }, new[] { 0, 2, 4 })]
[InlineData(new[] { 0, 1, 3, 4 }, new[] { 0, 4 })]
public void Should_return_odd_numbers_in_ascending_order(int[] i... | First of all, you are writing the logic inside the test.
You want to test a separate class instead.
Second, where would you pass the expected result?
You can either find a way to pass multiple data to your test, like Arsalan said in his answer, or your assertion should check that all numbers are odd and that they ar... |
62,609,862 | I am trying to improve my unit testing skills and i was wondering if someone could tell me the best way of writing a test for writing a test for "sorted odd numbers of a given array of integers". At the moment I am passing the data into the test with params but I would to verify the output is correct aswell.
```
[... | 2020/06/27 | [
"https://Stackoverflow.com/questions/62609862",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13454686/"
] | You should pass your input array and expected array as parameters in your tests .
You can use InlineData like this :
```
[Theory]
[InlineData(new[] { 0, 1, 2, 3, 4 }, new[] { 0, 2, 4 })]
[InlineData(new[] { 0, 1, 3, 4 }, new[] { 0, 4 })]
public void Should_return_odd_numbers_in_ascending_order(int[] i... | You're not really writing a unit test. You're writing some code in your test and wanting to validate it. Typically you'd have a method elsewhere that you are trying to validate. Let's assume you do:
```
public static Numbers
{
public static IEnumerable<int> FilterAndSortOdds(IEnumerable<int> source)
=> sour... |
48,961,655 | I am trying to get a loop like this. Suppose i have 20 rows in table `test` and i need to get its id values inside a loop like below.
```
<section class="test">
<div class="n4">
<div class="n2">
1 // first row id
</div>
<div class="n21">
2 // second row id
... | 2018/02/24 | [
"https://Stackoverflow.com/questions/48961655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9405185/"
] | In the loop
```
for k,g in itertools.groupby(sorted_data1):
```
`g` is itself an iterator, it's not a collection like a list.
When you call
```
print('key: ',k,' group: ',list(g))
```
inside the loop, the `list(g)` inside the print already goes through the entire iterator `g` to create the list. So, when you cal... | Just as Dennis said, you can change your code to this to solve the problem:
```
import itertools
data1 = [100, 80, 80, 80, 80, 80, 90, 90, 85, 85, 85]
keys = []
groups = []
sorted_data1 = sorted(data1)
for k, g in itertools.groupby(sorted_data1):
group = list(g)
print('key: ', k, ' group: ', group)
keys.... |
6,485,958 | I understand that a possesive regex would go to the end of the text and would not backtrack to see if there was a match before the end. If at the end there's a match it returns true, otherwise it immidiatly returns false. I've tride this:
```
Pattern patt = Pattern.compile(".*+foo");
Matcher matcher = patt.matcher("xx... | 2011/06/26 | [
"https://Stackoverflow.com/questions/6485958",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/651216/"
] | >
> It gives me nothing even though there's a match in the end. Any ideas why?
>
>
>
The `.*+` will match the entire input string (including the last `foo`). And because it does not backtrack from the end of the string, the regex `.*+foo` does not match.
>
> Also I understand that to make a regex lazy/possessive... | Possessive quantifiers will not give up matches on a backtrack. The `.*+` matches your entire string and then there's nothing for `foo` to match.
Er, like Bart said. :)
Use possessive quantifiers only when you know that what you've matched should never be backtracked (e.g., `[^f]*+.*foo` or, if you *know* that the on... |
59,996,071 | I have a problem. I created a CollectionView with a Label as a counter on each row and a button. What I want is that when I push the button, the label value will go up by +1, depending on the row you click. I already created the button event like this:
```
private void btnPlus_Clicked(object sender, EventArgs e)
{
... | 2020/01/30 | [
"https://Stackoverflow.com/questions/59996071",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10673107/"
] | Since you had used MVVM, you would better handle the logic in ViewModel .
### in Xaml
```
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/d... | x:Name is not within the context of what you want.
To bind a property from a Template into something on the XAML.cs Back Code use:
```
PropertyOnTemplate="{Binding Path=NameOfProperty, Source={x:Reference Name=NameOfFile}}
```
Then whenever you update the property `NameOfProperty` the UI will update accordingly
Sin... |
497,035 | I'm doing math by doing practice problems in my textbook.
I was able to find the explicit formula for $a\_n$ such that $a\_{n+1}=a\_n+2^n$ (which is $2^k-1$) I understand the theorems, but I'm having trouble solving questions.
I'm stuck on the second problem already. How do I find the explicit formula for the sequenc... | 2013/09/18 | [
"https://math.stackexchange.com/questions/497035",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/95457/"
] | The radius is $40 \text{ inches} = \frac{40}{12} \text{ feet}= \frac{10}3 \text{ ft}$ since $12 \text{ inches}=1\text{ foot}$. The wheel every second moves a distance equal to the arc length subtended by a $3$ radian angle on the wheel. The arc length is given by $3\cdot \frac{10}3\text{ feet}=10\text{ ft}$. So it move... | V=r\*W
where V= linear velocity, r= radius and W=angular velocity
but first you need to convert inches to foot
r= 40 inches = 10/3 foot
now V= r\*W = 10/3 \* 3 = 10 foot per sec
V= 600 foot per min
are you from US because never heard of using foot/min |
31,728,333 | I have a text file with the list of JIRA issue numbers. How can I get the "Fix Version/s" of those Issues? I don't know REST APIs. So, is there any other way to query this from JIRA. Please let me know.
JIRA.txt
```
INF-124
INF-742
INF-998
INF-362
```
Expected output
```
INF-124 PRJ 7.1
INF-742 APP 5.2 ... | 2015/07/30 | [
"https://Stackoverflow.com/questions/31728333",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4438637/"
] | You could Export an issue search to xml and/or csv (Excel)?
But I would suggest to do it with the REST API - login to jira and try to put this in your browser to get started {base-url}/rest/api/2/issue/{issue-key}?fields=fixVersions | Let's say we use the following query in JQL - JIRA:
KEY in (INF-124, INF-742, INF-998, INF-362)
If your default columns in JIRA are Key and FixVersions, than you can get an xls file by export XLS current fields. You can even copy the link to that option so that you should have something like this:
http:///jira/sr/jira... |
67,554,621 | My db example:
```
n_historia fecha hemo_detalle
<chr> <date> <chr>
1 1155148 2020-11-01 Serratia marcescens
2 1155148 2020-11-06 Klebsiella
3 1155148 ... | 2021/05/16 | [
"https://Stackoverflow.com/questions/67554621",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11597200/"
] | You can use :
```
library(dplyr)
library(tidyr)
df %>%
group_by(n_historia) %>%
mutate(row = row_number()) %>%
pivot_wider(names_from = row, values_from = c(fecha, hemo_detalle)) %>%
ungroup
# n_historia fecha_1 fecha_2 fecha_3 hemo_detalle_1 hemo_detalle_2 hemo_detalle_3
# <int> <chr> ... | We could use `rowid`
```
library(dplyr)
library(tidyr)
library(data.table)
df %>%
mutate(row = rowid(n_historia)) %>%
pivot_wider(names_from = row, values_from = c(fecha, hemo_detalle)) %>%
ungroup
``` |
19,794,675 | I am trying to convert the value 0 to 1 and 1 to -1, but without using if statements. I tried to do some math to map it to a new range but I am not able to do it for both parameters.
Is this doable?
It has to do this without hardcoded values in a collection though, so for example:
```
initial = 0 or 1;
final_value =... | 2013/11/05 | [
"https://Stackoverflow.com/questions/19794675",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51816/"
] | ```
1-(2*variable_value)
```
would give you those values ... but there is a strong chance this is not what you want ... because its really hard to tell what you want
since you have clarified that you want speed for shaders I figured I would add this info
```
In [3]: %timeit x= 1 if not random.randint(0,1) else -1 #... | In Python:
```
arr = [1, -1]
mapped = arr[n]
``` |
37,752,718 | I´m looking for a solution to implement a JSON-POST request with OKHTTP. I´ve got an HTTP-Client.java file which handles all the methods (POST, GET, PUT, DELETE) and in the RegisterActivity I´d like to POST the user-data (from the input fields) JSON-formatted to the server.
This is my **HTTP-Client.java**
```
pu... | 2016/06/10 | [
"https://Stackoverflow.com/questions/37752718",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5534808/"
] | Try my code below
```
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
Map<String, String> params = new HashMap<String, String>();
params.put("msisdn", "123123");
params.put("name", "your name");
JSONObject parameter = new JSONObject(param);
OkHttpClient cli... | It's because you are trying to execute the HTTP query on the main thread (or UI thread). You shouldn't do a long task on the main thread because your app will hang, because the drawing routines are executed in that thread (hence his another name "UI Thread"). You should use another thread to make your request. For exam... |
37,752,718 | I´m looking for a solution to implement a JSON-POST request with OKHTTP. I´ve got an HTTP-Client.java file which handles all the methods (POST, GET, PUT, DELETE) and in the RegisterActivity I´d like to POST the user-data (from the input fields) JSON-formatted to the server.
This is my **HTTP-Client.java**
```
pu... | 2016/06/10 | [
"https://Stackoverflow.com/questions/37752718",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5534808/"
] | Try my code below
```
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
Map<String, String> params = new HashMap<String, String>();
params.put("msisdn", "123123");
params.put("name", "your name");
JSONObject parameter = new JSONObject(param);
OkHttpClient cli... | Try using **Retrofit** library for making **Post** request to the server. This provides a fast and reliable connection to the server.
You can also use **Volley** library for the same. |
32,405,752 | The `rel` parameter in YouTube API dictates whether or not related videos are shown at the end. When `rel=0` the video reverts back to the thumbnail with a play button.
However on mobile (tested on iPhone / iPad / Fire Tablet) when the video goes back to the thumbnail it cannot be played a second time. It just does no... | 2015/09/04 | [
"https://Stackoverflow.com/questions/32405752",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16940/"
] | The trouble with refreshing a webpage at a specific interval is that you dont know exactly when the video ends so you need to develop a method which the video player sends a signal when the video ends, which would then start the script to refresh the page. Otherwise you end up restarting it in the middle of the video. ... | ### Appears to have been fixed by YouTube.
I can now play the video multiple times (on multiple devices) without it getting stuck. Was too busy wondering why my question was getting so little attention that I forgot to check again to see if it was fixed ;-) |
32,405,752 | The `rel` parameter in YouTube API dictates whether or not related videos are shown at the end. When `rel=0` the video reverts back to the thumbnail with a play button.
However on mobile (tested on iPhone / iPad / Fire Tablet) when the video goes back to the thumbnail it cannot be played a second time. It just does no... | 2015/09/04 | [
"https://Stackoverflow.com/questions/32405752",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16940/"
] | Have a look at `loop` and `playlist` parameters as well. You can set playlist parameter to video ID and same video can be replayed using this.
So, it will be something like:
<http://www.youtube.com/embed/>{VIDEO\_ID}?wmode=opaque&loop=1&version=3&playlist={VIDEO\_ID}
Hope this helps! | ### Appears to have been fixed by YouTube.
I can now play the video multiple times (on multiple devices) without it getting stuck. Was too busy wondering why my question was getting so little attention that I forgot to check again to see if it was fixed ;-) |
65,132,356 | I am cleaning a dataset and I need to remove formatting errors in column A if the value in column B matches a specific string.
```
A B
foo//, cherry
bar//, orange
bar//, cherry
bar apple
```
So in this situation if column B is 'cherry' I want to replace "//," with "," in column A. The final result would... | 2020/12/03 | [
"https://Stackoverflow.com/questions/65132356",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9996914/"
] | You can simply write a function that takes in a row as `series`, checks the `cherry` condition, fixes the string with `str.replace` and returns the row. The you can use `df.apply` over `axis=1`.
```
def fix(s):
if s['B']=='cherry':
s['A']=s['A'].replace('//,',',')
return s
df.apply(fix, axis=1)
```
... | I would first check which rows contain cherry in the B column:
```
rows = df['B'].str.contains('cherry')
```
and then replace "//" with "" in these rows but A column. |
23,120,996 | I have seen many other questions like this one on this website and tried changing my code to match but it never solves the problem.
My app loads with some buttons to push. One of them opens a class file that opens a map on the screen. The code for that class is :
```
public class FuelMap extends Activity
{
pri... | 2014/04/16 | [
"https://Stackoverflow.com/questions/23120996",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3487203/"
] | try this link: [in google maps V2 ... fragment.getMap() returns null](https://stackoverflow.com/questions/14909917/in-google-maps-v2-fragment-getmap-returns-null)
it appears that the map fragment you are trying to load hasn't been instantiated yet, in the onCreateView().
Hopefully this solves the issue. You might need... | I t seems that you are using Maps V2 so your declaration in the xml is not right.
It is a fragment not a FragmentLayout as mention in the [Android Developer](https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2)
```
<?xml version="1.0" encoding="utf-8"?>
<fragm... |
23,120,996 | I have seen many other questions like this one on this website and tried changing my code to match but it never solves the problem.
My app loads with some buttons to push. One of them opens a class file that opens a map on the screen. The code for that class is :
```
public class FuelMap extends Activity
{
pri... | 2014/04/16 | [
"https://Stackoverflow.com/questions/23120996",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3487203/"
] | Thanks a ton for all the help guys. I final figured out the problem. It was the letter 's'.
In this line: `//map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map )).getMap();` I was was pulling the object called map. If you look in my activity\_Fuel\_Map layout the map object is a TextView.
```
` <... | I t seems that you are using Maps V2 so your declaration in the xml is not right.
It is a fragment not a FragmentLayout as mention in the [Android Developer](https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2)
```
<?xml version="1.0" encoding="utf-8"?>
<fragm... |
713,574 | How to show the latest sites added to bookmarks in Chrome?
I want to know this because I am looking for one site that I recently added to the bookmarks but forgot where I put into (different folders). | 2014/02/07 | [
"https://superuser.com/questions/713574",
"https://superuser.com",
"https://superuser.com/users/287844/"
] | This may be of interest to you:
tmux has been released as a cygwin package just recently!
Please have a look at the announcement at [on the Cygwin-Announce mailing list](http://www.cygwin.com/ml/cygwin-announce/2014-03/msg00001.html);
you can now simply install tmux with the common cygwin `setup-{x86|x64}.exe`. | ```
# download file on your machine:
wget raw.github.com/transcode-open/apt-cyg/master/apt-cyg
# change permissions to execute file in cygwin
chmod +x apt-cyg
# Install script to the /bin folder where - it will make the script available by name
mv apt-cyg /bin
# Example: you can install something, similar as y... |
713,574 | How to show the latest sites added to bookmarks in Chrome?
I want to know this because I am looking for one site that I recently added to the bookmarks but forgot where I put into (different folders). | 2014/02/07 | [
"https://superuser.com/questions/713574",
"https://superuser.com",
"https://superuser.com/users/287844/"
] | ```
# download file on your machine:
wget raw.github.com/transcode-open/apt-cyg/master/apt-cyg
# change permissions to execute file in cygwin
chmod +x apt-cyg
# Install script to the /bin folder where - it will make the script available by name
mv apt-cyg /bin
# Example: you can install something, similar as y... | Agreed, installing tmux works now with the setup-{x86|x64}.exe.
Adding just so that I point out that it actually works, with a more recent post, than the one on Apr 2 2019.
(I did not have to reinstall anything.)
Just put the drop-down to "Full" or "Not installed" and search for tmux, it was there. |
713,574 | How to show the latest sites added to bookmarks in Chrome?
I want to know this because I am looking for one site that I recently added to the bookmarks but forgot where I put into (different folders). | 2014/02/07 | [
"https://superuser.com/questions/713574",
"https://superuser.com",
"https://superuser.com/users/287844/"
] | I just had exactly the same issue.
I solved it by editing tty-term.c. Search for 'cur\_term' and comment out the line.
It compiled fine after that. Not sure if there are any downsides to this. Haven't seen any yet! | I'm a noob and not a single suggestion mentioned previously worked.
The solution is to reinstall cygwin and chose package you're interested in right away (you will understand what to do while installing) |
713,574 | How to show the latest sites added to bookmarks in Chrome?
I want to know this because I am looking for one site that I recently added to the bookmarks but forgot where I put into (different folders). | 2014/02/07 | [
"https://superuser.com/questions/713574",
"https://superuser.com",
"https://superuser.com/users/287844/"
] | This may be of interest to you:
tmux has been released as a cygwin package just recently!
Please have a look at the announcement at [on the Cygwin-Announce mailing list](http://www.cygwin.com/ml/cygwin-announce/2014-03/msg00001.html);
you can now simply install tmux with the common cygwin `setup-{x86|x64}.exe`. | Agreed, installing tmux works now with the setup-{x86|x64}.exe.
Adding just so that I point out that it actually works, with a more recent post, than the one on Apr 2 2019.
(I did not have to reinstall anything.)
Just put the drop-down to "Full" or "Not installed" and search for tmux, it was there. |
713,574 | How to show the latest sites added to bookmarks in Chrome?
I want to know this because I am looking for one site that I recently added to the bookmarks but forgot where I put into (different folders). | 2014/02/07 | [
"https://superuser.com/questions/713574",
"https://superuser.com",
"https://superuser.com/users/287844/"
] | ```
# download file on your machine:
wget raw.github.com/transcode-open/apt-cyg/master/apt-cyg
# change permissions to execute file in cygwin
chmod +x apt-cyg
# Install script to the /bin folder where - it will make the script available by name
mv apt-cyg /bin
# Example: you can install something, similar as y... | Use one of the [apt-cyg](https://github.com/kou1okada/apt-cyg/network) forks and simply do:
```
apt-cyg install tmux
``` |
713,574 | How to show the latest sites added to bookmarks in Chrome?
I want to know this because I am looking for one site that I recently added to the bookmarks but forgot where I put into (different folders). | 2014/02/07 | [
"https://superuser.com/questions/713574",
"https://superuser.com",
"https://superuser.com/users/287844/"
] | This may be of interest to you:
tmux has been released as a cygwin package just recently!
Please have a look at the announcement at [on the Cygwin-Announce mailing list](http://www.cygwin.com/ml/cygwin-announce/2014-03/msg00001.html);
you can now simply install tmux with the common cygwin `setup-{x86|x64}.exe`. | I'm a noob and not a single suggestion mentioned previously worked.
The solution is to reinstall cygwin and chose package you're interested in right away (you will understand what to do while installing) |
713,574 | How to show the latest sites added to bookmarks in Chrome?
I want to know this because I am looking for one site that I recently added to the bookmarks but forgot where I put into (different folders). | 2014/02/07 | [
"https://superuser.com/questions/713574",
"https://superuser.com",
"https://superuser.com/users/287844/"
] | I just had exactly the same issue.
I solved it by editing tty-term.c. Search for 'cur\_term' and comment out the line.
It compiled fine after that. Not sure if there are any downsides to this. Haven't seen any yet! | Use one of the [apt-cyg](https://github.com/kou1okada/apt-cyg/network) forks and simply do:
```
apt-cyg install tmux
``` |
713,574 | How to show the latest sites added to bookmarks in Chrome?
I want to know this because I am looking for one site that I recently added to the bookmarks but forgot where I put into (different folders). | 2014/02/07 | [
"https://superuser.com/questions/713574",
"https://superuser.com",
"https://superuser.com/users/287844/"
] | ```
# download file on your machine:
wget raw.github.com/transcode-open/apt-cyg/master/apt-cyg
# change permissions to execute file in cygwin
chmod +x apt-cyg
# Install script to the /bin folder where - it will make the script available by name
mv apt-cyg /bin
# Example: you can install something, similar as y... | I'm a noob and not a single suggestion mentioned previously worked.
The solution is to reinstall cygwin and chose package you're interested in right away (you will understand what to do while installing) |
713,574 | How to show the latest sites added to bookmarks in Chrome?
I want to know this because I am looking for one site that I recently added to the bookmarks but forgot where I put into (different folders). | 2014/02/07 | [
"https://superuser.com/questions/713574",
"https://superuser.com",
"https://superuser.com/users/287844/"
] | This may be of interest to you:
tmux has been released as a cygwin package just recently!
Please have a look at the announcement at [on the Cygwin-Announce mailing list](http://www.cygwin.com/ml/cygwin-announce/2014-03/msg00001.html);
you can now simply install tmux with the common cygwin `setup-{x86|x64}.exe`. | I just had exactly the same issue.
I solved it by editing tty-term.c. Search for 'cur\_term' and comment out the line.
It compiled fine after that. Not sure if there are any downsides to this. Haven't seen any yet! |
713,574 | How to show the latest sites added to bookmarks in Chrome?
I want to know this because I am looking for one site that I recently added to the bookmarks but forgot where I put into (different folders). | 2014/02/07 | [
"https://superuser.com/questions/713574",
"https://superuser.com",
"https://superuser.com/users/287844/"
] | I just had exactly the same issue.
I solved it by editing tty-term.c. Search for 'cur\_term' and comment out the line.
It compiled fine after that. Not sure if there are any downsides to this. Haven't seen any yet! | Agreed, installing tmux works now with the setup-{x86|x64}.exe.
Adding just so that I point out that it actually works, with a more recent post, than the one on Apr 2 2019.
(I did not have to reinstall anything.)
Just put the drop-down to "Full" or "Not installed" and search for tmux, it was there. |
60,913,091 | I want to separate hosting of my **app** and **website**. The hierarchy is as follows:
* `example.com` - website hosted at DigitalOcean
* `example.com/*` - SPA hosted at Firebase Hosting
Since DNS does not allow to point the subdirectories, is there any wiser way, to accomplish this?
Thanks in advance! | 2020/03/29 | [
"https://Stackoverflow.com/questions/60913091",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2909074/"
] | As the subdomain solution isn't favored, you could try a proxy like nginx to route traffic based on the path to different backends. An example configuration might look something like this:
```
server {
listen ...;
...
location / {
proxy_pass http://<your-website>;
}
location /app {
... | I ended up solving the problem via subdomains and decided to share this workaround.
**1. DNS records as follows**
```
www : pointing to website
* : root pointing SPA
```
**2. In my Vue app I just added a simple `window.replace` to redirect from root to `www`.**
```
if (window.location.host === 'example.com') windo... |
34,799,552 | I'm trying to select all jobs that a user has been added to, but exclude jobs that they have declined. I've been looking into NOT EXISTS, but I haven't been able to exclude declined jobs with that.
Table: declined
```
+---------+---------+---------+----------+
| id | job_id | user_id | declined |
+---------+---... | 2016/01/14 | [
"https://Stackoverflow.com/questions/34799552",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3770850/"
] | Default constructor of optional is declared `noexcept`, as per <http://en.cppreference.com/w/cpp/experimental/optional/optional>. | You're constructing an `optional<T>` from a value of T (probably a `T&&`), which in turn calls the corresponding ctor of T. If T's ctor throws, then so does optional's ctor. Depending upon what the missing code inside the `try{}` block does, your exception specification should be something like
```
noexcept(std::is_no... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.