qid int64 1 74.7M | question stringlengths 15 58.3k | date stringlengths 10 10 | metadata list | response_j stringlengths 4 30.2k | response_k stringlengths 11 36.5k |
|---|---|---|---|---|---|
43,001,690 | I found this project on the web: <http://cyntss.github.io/Parallax-img-scroll/>
And I am wondering if I want to change the `data-ps-vertical-position""` on resize how can I do that? I have tried updating the data value using the following approach: `$('div#frame-1').attr( 'data-ps-vertical-position','1900');` however ... | 2017/03/24 | [
"https://Stackoverflow.com/questions/43001690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1974930/"
] | I ended up taking a different approach. Instead, I made a wrapper class that extended EventTarget.
```
type AudioEvent = {bytes: Uint8Array};
interface IAudioEventTarget {
addListener(callback: (evt: CustomEvent<AudioEvent>) => void): void
dispatch(event: AudioEvent): boolean;
removeListener(callback: (evt: Cus... | maybe overly complicated but typesafe?
```
interface FizzInfo {
amount: string;
}
interface BuzzInfo {
level: number;
}
interface FizzBuzzEventMap {
fizz: CustomEvent<FizzInfo>;
buzz: CustomEvent<BuzzInfo>;
}
interface FizzerBuzzer extends EventTarget {
addEventListener<K extends keyof FizzBuzzEventMap>(t... |
43,001,690 | I found this project on the web: <http://cyntss.github.io/Parallax-img-scroll/>
And I am wondering if I want to change the `data-ps-vertical-position""` on resize how can I do that? I have tried updating the data value using the following approach: `$('div#frame-1').attr( 'data-ps-vertical-position','1900');` however ... | 2017/03/24 | [
"https://Stackoverflow.com/questions/43001690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1974930/"
] | The solution described in the accepted answer gets the job done but for the cost of losing type safety.
**If you want to keep the type-safety** going I would suggest the following:
Create `dom.d.ts` file in `@types` folder in your sources (or configure [`typeRoots`](https://www.typescriptlang.org/tsconfig#typeRoots) ... | Simplest way is like so:
```
window.addEventListener("beforeinstallprompt", ((event: CustomEvent) => {
console.log("Whoop!");
}) as EventListener);
``` |
43,001,690 | I found this project on the web: <http://cyntss.github.io/Parallax-img-scroll/>
And I am wondering if I want to change the `data-ps-vertical-position""` on resize how can I do that? I have tried updating the data value using the following approach: `$('div#frame-1').attr( 'data-ps-vertical-position','1900');` however ... | 2017/03/24 | [
"https://Stackoverflow.com/questions/43001690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1974930/"
] | The property name is `detail` and not `details`. The correct code needs to be:
```
let div: any = document.getElementById("my_div");
let c_event = new CustomEvent("build",{detail: 3});
div.addEventListener("build", function(e: CustomEvent) { // change here Event to CustomEvent
console.log(e.detail);
}.bind(this)... | `CustomEvent` is a generic type. You can pass the type of the `detail` property as a parameter (it defaults to `any`). Here is how it is defined in [lib.dom.d.ts](https://github.com/microsoft/TypeScript/blob/master/lib/lib.dom.d.ts) (which is in the `lib` directory of your npm typescript installation):
```js
interface... |
43,001,690 | I found this project on the web: <http://cyntss.github.io/Parallax-img-scroll/>
And I am wondering if I want to change the `data-ps-vertical-position""` on resize how can I do that? I have tried updating the data value using the following approach: `$('div#frame-1').attr( 'data-ps-vertical-position','1900');` however ... | 2017/03/24 | [
"https://Stackoverflow.com/questions/43001690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1974930/"
] | `CustomEvent` is a generic type. You can pass the type of the `detail` property as a parameter (it defaults to `any`). Here is how it is defined in [lib.dom.d.ts](https://github.com/microsoft/TypeScript/blob/master/lib/lib.dom.d.ts) (which is in the `lib` directory of your npm typescript installation):
```js
interface... | I ended up taking a different approach. Instead, I made a wrapper class that extended EventTarget.
```
type AudioEvent = {bytes: Uint8Array};
interface IAudioEventTarget {
addListener(callback: (evt: CustomEvent<AudioEvent>) => void): void
dispatch(event: AudioEvent): boolean;
removeListener(callback: (evt: Cus... |
13,063,019 | I can create an alias in solaris as below:
```
alias x86 "some_command"
```
I need something that i can pass an argument to an alias and that argument will be used to frame the complete alias.
for example:
there is a command like :
```
ct setview 1.0_myname
```
and for the above i write the alias as
```
alias ... | 2012/10/25 | [
"https://Stackoverflow.com/questions/13063019",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/134713/"
] | If you are using bash (or equivalent shell), the alias function cannot transmit arguments. Instead, you can create a function :
```
sv() { ct "setview $@_myname" ;}
```
And use it like an alias (sv 1.0)
*Depending on your config you may need to provide full path of the **ct** binary* | For csh & tcsh shells, there's limited argument substitution in aliases, using ! syntax,
such as:
```
alias sv 'ct steview \!:1_myname'
```
More details and examples at:
* [Writing Aliases in csh and tcsh](http://home.adelphi.edu/sbloch/class/archive/271/fall2005/notes/aliases.html)
* [Online Unix Help: C Shell: A... |
17,926,240 | First of all, I've seen that simliar questions have been asked and believe me, I've read the answers and comments and tried to understand. Otherwise I wouldn't post.
So, the question then:
I have a gridview that I wish to update.
**The ASP code looks like this:**
```
<asp:GridView ID="myGv" runat="server"
Aut... | 2013/07/29 | [
"https://Stackoverflow.com/questions/17926240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1323785/"
] | Seems pretty cut and dry, this is the line causing the issue:
```
e.NewValues.Add("volume", value);
```
You are telling the grid view to add the value just entered by the user into a new value called `volume`, which is a duplicate.
If you want to update the value, then do this:
```
e.NewValues["volume"] = whatever... | Try this:
```
e.NewValues["volume"] = value;
``` |
17,926,240 | First of all, I've seen that simliar questions have been asked and believe me, I've read the answers and comments and tried to understand. Otherwise I wouldn't post.
So, the question then:
I have a gridview that I wish to update.
**The ASP code looks like this:**
```
<asp:GridView ID="myGv" runat="server"
Aut... | 2013/07/29 | [
"https://Stackoverflow.com/questions/17926240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1323785/"
] | Try this:
```
e.NewValues["volume"] = value;
``` | exception message explains it all. ASP.NET automatically populates and uses the value of **textbox** for the volume. if you have to do something different ASP.NET does, for example trim the value, do something like:
```
e.NewValues["volume"] = value.Trim();
``` |
17,926,240 | First of all, I've seen that simliar questions have been asked and believe me, I've read the answers and comments and tried to understand. Otherwise I wouldn't post.
So, the question then:
I have a gridview that I wish to update.
**The ASP code looks like this:**
```
<asp:GridView ID="myGv" runat="server"
Aut... | 2013/07/29 | [
"https://Stackoverflow.com/questions/17926240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1323785/"
] | Try this:
```
e.NewValues["volume"] = value;
``` | Hi looking at you code it seems you are adding new values and elements .
```
e.NewValues.Add("volume", value);
```
adds an element with provided key and value to the system.collections.IDictionary object (As .net says)
So what happened to our old elements and values which are already present in system.collections.... |
17,926,240 | First of all, I've seen that simliar questions have been asked and believe me, I've read the answers and comments and tried to understand. Otherwise I wouldn't post.
So, the question then:
I have a gridview that I wish to update.
**The ASP code looks like this:**
```
<asp:GridView ID="myGv" runat="server"
Aut... | 2013/07/29 | [
"https://Stackoverflow.com/questions/17926240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1323785/"
] | Seems pretty cut and dry, this is the line causing the issue:
```
e.NewValues.Add("volume", value);
```
You are telling the grid view to add the value just entered by the user into a new value called `volume`, which is a duplicate.
If you want to update the value, then do this:
```
e.NewValues["volume"] = whatever... | exception message explains it all. ASP.NET automatically populates and uses the value of **textbox** for the volume. if you have to do something different ASP.NET does, for example trim the value, do something like:
```
e.NewValues["volume"] = value.Trim();
``` |
17,926,240 | First of all, I've seen that simliar questions have been asked and believe me, I've read the answers and comments and tried to understand. Otherwise I wouldn't post.
So, the question then:
I have a gridview that I wish to update.
**The ASP code looks like this:**
```
<asp:GridView ID="myGv" runat="server"
Aut... | 2013/07/29 | [
"https://Stackoverflow.com/questions/17926240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1323785/"
] | Seems pretty cut and dry, this is the line causing the issue:
```
e.NewValues.Add("volume", value);
```
You are telling the grid view to add the value just entered by the user into a new value called `volume`, which is a duplicate.
If you want to update the value, then do this:
```
e.NewValues["volume"] = whatever... | [NewValues](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewupdateeventargs.newvalues.aspx) is a dictionary and it can contain only unique keys. So in this case you're adding the same key multiple times that is why you're getting this error. Asp.net manages the keys for predefined columns. You... |
17,926,240 | First of all, I've seen that simliar questions have been asked and believe me, I've read the answers and comments and tried to understand. Otherwise I wouldn't post.
So, the question then:
I have a gridview that I wish to update.
**The ASP code looks like this:**
```
<asp:GridView ID="myGv" runat="server"
Aut... | 2013/07/29 | [
"https://Stackoverflow.com/questions/17926240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1323785/"
] | Seems pretty cut and dry, this is the line causing the issue:
```
e.NewValues.Add("volume", value);
```
You are telling the grid view to add the value just entered by the user into a new value called `volume`, which is a duplicate.
If you want to update the value, then do this:
```
e.NewValues["volume"] = whatever... | Hi looking at you code it seems you are adding new values and elements .
```
e.NewValues.Add("volume", value);
```
adds an element with provided key and value to the system.collections.IDictionary object (As .net says)
So what happened to our old elements and values which are already present in system.collections.... |
17,926,240 | First of all, I've seen that simliar questions have been asked and believe me, I've read the answers and comments and tried to understand. Otherwise I wouldn't post.
So, the question then:
I have a gridview that I wish to update.
**The ASP code looks like this:**
```
<asp:GridView ID="myGv" runat="server"
Aut... | 2013/07/29 | [
"https://Stackoverflow.com/questions/17926240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1323785/"
] | [NewValues](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewupdateeventargs.newvalues.aspx) is a dictionary and it can contain only unique keys. So in this case you're adding the same key multiple times that is why you're getting this error. Asp.net manages the keys for predefined columns. You... | exception message explains it all. ASP.NET automatically populates and uses the value of **textbox** for the volume. if you have to do something different ASP.NET does, for example trim the value, do something like:
```
e.NewValues["volume"] = value.Trim();
``` |
17,926,240 | First of all, I've seen that simliar questions have been asked and believe me, I've read the answers and comments and tried to understand. Otherwise I wouldn't post.
So, the question then:
I have a gridview that I wish to update.
**The ASP code looks like this:**
```
<asp:GridView ID="myGv" runat="server"
Aut... | 2013/07/29 | [
"https://Stackoverflow.com/questions/17926240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1323785/"
] | [NewValues](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewupdateeventargs.newvalues.aspx) is a dictionary and it can contain only unique keys. So in this case you're adding the same key multiple times that is why you're getting this error. Asp.net manages the keys for predefined columns. You... | Hi looking at you code it seems you are adding new values and elements .
```
e.NewValues.Add("volume", value);
```
adds an element with provided key and value to the system.collections.IDictionary object (As .net says)
So what happened to our old elements and values which are already present in system.collections.... |
41,282,145 | I want to print the selected lines using grep pattern matching. I am using following command -
```
cat MyTest.txt | grep -v -E B1 "EEB|SET|PET"
grep: EEB|SET|PET: No such file or directory
```
I am always getting above grep error.
* 1. I want to print the line which matches pattern or patterns I have mentioned i.... | 2016/12/22 | [
"https://Stackoverflow.com/questions/41282145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/408941/"
] | ```
SELECT p.*, p2.*
FROM #Persons p
CROSS APPLY
(SELECT COUNT (DISTINCT p1.Person) as countdistinctpersonincity
FROM
#Persons p1
WHERE
p1.Person <> p.Person
AND p1.City = p.City
AND p1.workingdate = p.workingdate) p2;
```
Test code
```
CR... | One variant:
```
SELECT *
,IIF(ROW_NUMBER() OVER(PARTITION BY City, Person ORDER BY workingdate) = 1, 1, 0)
FROM Persons
```
[](https://i.stack.imgur.com/Qr4bA.png)
---
For SQL Server before 2012, you can use:
```
SELECT P.*
,CASE WHE... |
41,282,145 | I want to print the selected lines using grep pattern matching. I am using following command -
```
cat MyTest.txt | grep -v -E B1 "EEB|SET|PET"
grep: EEB|SET|PET: No such file or directory
```
I am always getting above grep error.
* 1. I want to print the line which matches pattern or patterns I have mentioned i.... | 2016/12/22 | [
"https://Stackoverflow.com/questions/41282145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/408941/"
] | ```
SELECT p.*, p2.*
FROM #Persons p
CROSS APPLY
(SELECT COUNT (DISTINCT p1.Person) as countdistinctpersonincity
FROM
#Persons p1
WHERE
p1.Person <> p.Person
AND p1.City = p.City
AND p1.workingdate = p.workingdate) p2;
```
Test code
```
CR... | I believe this query will give your result. Idea is to check if previous entry sorted by person and date is different so it means we reached new person:
```
select case
when Person != lag(Person, 1, 'XXXXXX') over (order by Person, workingdate) then 1
else 0
end
from table;
```
To see ... |
7,749 | I am trying to capture punctuation marks and I have a number of macros, two of which are shown in the minimal below:
```
\documentclass{article}
\usepackage[english]{babel}
\def\isColon#1{%
\ifx:#1
colon!
\else
Not a colon!
\fi}
\def\isPeriod#1{%
\ifx.#1
Period!
\else
Not a period!
\fi}
\begin{document}... | 2010/12/26 | [
"https://tex.stackexchange.com/questions/7749",
"https://tex.stackexchange.com",
"https://tex.stackexchange.com/users/963/"
] | I'd use `\if`:
```
\documentclass{article}
\usepackage[english]{babel}
\def\isColon#1{%
\if:\noexpand#1%
colon!
\else
Not a colon!
\fi}
\def\isPeriod#1{%
\if.\noexpand#1%
Period!
\else
Not a period!
\fi}
\begin{document}
\isColon:
\isPeriod.
\end{document}
```
Another alternative would be `\pdfstrcmp... | ```
\documentclass{article}
\usepackage[english,french]{babel}
\shorthandon{:}
\def\isColon#1{%
\ifx:#1
colon!
\else
Not a colon!
\fi}%
\def\isPeriod#1{%
\ifx.#1
Period!
\else
Not a period!
\fi}
\begin{document}
\isColon: \isColon;
\isPeriod.
\end{document}
``` |
7,749 | I am trying to capture punctuation marks and I have a number of macros, two of which are shown in the minimal below:
```
\documentclass{article}
\usepackage[english]{babel}
\def\isColon#1{%
\ifx:#1
colon!
\else
Not a colon!
\fi}
\def\isPeriod#1{%
\ifx.#1
Period!
\else
Not a period!
\fi}
\begin{document}... | 2010/12/26 | [
"https://tex.stackexchange.com/questions/7749",
"https://tex.stackexchange.com",
"https://tex.stackexchange.com/users/963/"
] | I'd use `\if`:
```
\documentclass{article}
\usepackage[english]{babel}
\def\isColon#1{%
\if:\noexpand#1%
colon!
\else
Not a colon!
\fi}
\def\isPeriod#1{%
\if.\noexpand#1%
Period!
\else
Not a period!
\fi}
\begin{document}
\isColon:
\isPeriod.
\end{document}
```
Another alternative would be `\pdfstrcmp... | The problem is that outside of the macro, `:` is a macro expanding to `\active@prefix :\normal@char:`, but inside the macro, `:` is just the character `:`. I believe this is because Babel registers the catcode changes with `\AtBeginDocument`; moving the macro definition after `\begin{document}` works just fine. I also ... |
42,777,847 | From [PEP263](https://www.python.org/dev/peps/pep-0263/#defining-the-encoding):
>
> To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file, such as:
>
>
>
```
# coding=<encoding name>
```
>
> or (using formats recognized by popular edit... | 2017/03/14 | [
"https://Stackoverflow.com/questions/42777847",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/610569/"
] | Thanks to CodeGodie help, I've found that the problem is in the IFs blocks located at `sign_up.php` page, removing this the code work as expected and the user is created.
I will manage that using jQuery that is more user friendly too.
Thanks | You have an error in this statement `if($user->is_loggedin()!="")` because `true!=""` was true if the user logged in, then you are redirected to the `home.php`, replace it with this one:
```
if(!$user->is_loggedin())
``` |
22,621,542 | I am pretty new to, well, all web programming and would like to ask... In the following code, how do I align the rotated `<th>` fields so that the table looks proper, the fields are aligned, and not off the screen?
This is the rotation function I am using. (I just posted it to get rid of the errors, you really need to... | 2014/03/24 | [
"https://Stackoverflow.com/questions/22621542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3447270/"
] | Wrap your `th` text in a `span` and try this:
```
.r90 span {
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
font-family:verdana;
display:inline-block;
line-height:80px;
height:80p... | thing is with transform is it doesnt really affect other styling.
if you want to align your table you will have to use javascript(or jQuery) to get the rotated cell's width (the width stays the same even though they are rotated) and adjust the table head row height accordingly |
22,621,542 | I am pretty new to, well, all web programming and would like to ask... In the following code, how do I align the rotated `<th>` fields so that the table looks proper, the fields are aligned, and not off the screen?
This is the rotation function I am using. (I just posted it to get rid of the errors, you really need to... | 2014/03/24 | [
"https://Stackoverflow.com/questions/22621542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3447270/"
] | Wrap your `th` text in a `span` and try this:
```
.r90 span {
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
font-family:verdana;
display:inline-block;
line-height:80px;
height:80p... | can you check the following: [jsFiddle](http://jsfiddle.net/siva_hari/js96c/)
```
.r90 {
height: 100px; width: 100px;
font-size: 16px;
-moz-transform: rotate(90deg);
-webkit-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transfo... |
20,778,222 | I got confused with string initialization.
I believe that the following:
case1:
```
char s1[100] = { "apple" };
```
case2:
```
char s1[100];
s1 = "apple";
```
case1 compiles ok, however, case2 gets error.
Compiler says I am trying to assign char[5] to char[100]...
Could you clarify the difference between two ca... | 2013/12/26 | [
"https://Stackoverflow.com/questions/20778222",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1798211/"
] | The buit-in arrays (so called raw arrays) do not support direct assignment.
Your case 1 is not assignment: it's initialization.
The standard library offers `std::array` which essentially wraps a raw array in a `struct`, and thus is assignable.
However, for the apparent purpose of your code an array would be the wron... | Explanation of current code
---------------------------
**case 1** is a legal way to initialise `s1`, with 'a' going into [0], 'p' into [1] and [2], 'l' into [3], 'e' into [4] and the rest set to 0 (ASCII NUL - see <http://en.wikipedia.org/wiki/ASCII>).
**case 2** attempts to assign one array to another (of a differe... |
45,759 | I'd love your help with finding the following limit:
$$\lim\_{n\to \infty }\cos (\pi\sqrt{n^{2}-n}).$$
I was asked to find this limit, but honestly I believe that it doesn't exist.
According to Heine Theorem of limit of functions, I can choose two sequences:
$x\_{k}=2\pi k$ and $y\_{k}=2\pi k+\pi$ and notice that wh... | 2011/06/16 | [
"https://math.stackexchange.com/questions/45759",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/-1/"
] | We have
\begin{align\*}
\cos (\pi\sqrt{n^2-n})&= (-1)^n\cos(\pi(\sqrt{n^2-n}-n))\\
&= (-1)^n \cos\pi\frac{-n}{\sqrt{n^2-n}+n}\\
&=(-1)^n\cos \pi\frac 1{\sqrt{1-\frac 1n }+1},
\end{align\*}
hence $|\cos(\pi\sqrt{n^2-n})| = \left|\cos \left(\pi\frac 1{\sqrt{1-\frac 1n }+1}\right)\right|$.
Since $\lim \limits\_{n\to +\i... | Since a nice formal argument has been supplied by Davide Giraudo, I will allow myself the luxury of informality.
Let $n$ be a large positive integer.
Complete the square. We have
$$n^2-n=\left(n-\frac{1}{2}\right)^2 -\frac{1}{4}$$
Take the square root. When $n$ is very large, the term $-1/4$ makes a vanishingly smal... |
45,759 | I'd love your help with finding the following limit:
$$\lim\_{n\to \infty }\cos (\pi\sqrt{n^{2}-n}).$$
I was asked to find this limit, but honestly I believe that it doesn't exist.
According to Heine Theorem of limit of functions, I can choose two sequences:
$x\_{k}=2\pi k$ and $y\_{k}=2\pi k+\pi$ and notice that wh... | 2011/06/16 | [
"https://math.stackexchange.com/questions/45759",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/-1/"
] | We have
\begin{align\*}
\cos (\pi\sqrt{n^2-n})&= (-1)^n\cos(\pi(\sqrt{n^2-n}-n))\\
&= (-1)^n \cos\pi\frac{-n}{\sqrt{n^2-n}+n}\\
&=(-1)^n\cos \pi\frac 1{\sqrt{1-\frac 1n }+1},
\end{align\*}
hence $|\cos(\pi\sqrt{n^2-n})| = \left|\cos \left(\pi\frac 1{\sqrt{1-\frac 1n }+1}\right)\right|$.
Since $\lim \limits\_{n\to +\i... | Considering the form $\cos(\pi n \sqrt{1-\frac{1}{n}})$ and using
Taylor's expansion for $\sqrt{1-\frac{1}{x}}$ $\to$ [see here](http://www.wolframalpha.com/input/?i=series%20sqrt%281-1/x%29),
we get that when n is large $\cos (\pi\sqrt{n^{2}-n}) \approx \cos( \pi n -\frac{\pi}{2})$. Therefore, $L=0$.
Q.E.D. |
45,759 | I'd love your help with finding the following limit:
$$\lim\_{n\to \infty }\cos (\pi\sqrt{n^{2}-n}).$$
I was asked to find this limit, but honestly I believe that it doesn't exist.
According to Heine Theorem of limit of functions, I can choose two sequences:
$x\_{k}=2\pi k$ and $y\_{k}=2\pi k+\pi$ and notice that wh... | 2011/06/16 | [
"https://math.stackexchange.com/questions/45759",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/-1/"
] | Since a nice formal argument has been supplied by Davide Giraudo, I will allow myself the luxury of informality.
Let $n$ be a large positive integer.
Complete the square. We have
$$n^2-n=\left(n-\frac{1}{2}\right)^2 -\frac{1}{4}$$
Take the square root. When $n$ is very large, the term $-1/4$ makes a vanishingly smal... | Considering the form $\cos(\pi n \sqrt{1-\frac{1}{n}})$ and using
Taylor's expansion for $\sqrt{1-\frac{1}{x}}$ $\to$ [see here](http://www.wolframalpha.com/input/?i=series%20sqrt%281-1/x%29),
we get that when n is large $\cos (\pi\sqrt{n^{2}-n}) \approx \cos( \pi n -\frac{\pi}{2})$. Therefore, $L=0$.
Q.E.D. |
26,818,467 | Assume the following two classes:
```
struct A {
A() {}
};
struct B {
B(const A& a) {}
};
```
It happened to me multiple times to have a situation where I have to create a temporary instance of a class in order to build an instance of something I need to use. Something like:
```
A a;
// Do very complex co... | 2014/11/08 | [
"https://Stackoverflow.com/questions/26818467",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1356926/"
] | You could assign a default-constructed object to `A`, assuming that `A`'s assignment operator properly frees "resources":
```
A a;
// Do very complex computations using a;
B b(a);
a = {};
// use b, a is not needed anymore.
return make_result(b);
```
You could change `B` to take `A` by value and move the constructed ... | Largely it depends on the classes you have crafted in your program. Both `A` and `B` must be having common protocol (or sub-protocol to other class), and a common storage implying that protocol (e.g. a `vector` of some custom `struct`). If that is the case, the class having the responsibility can have function for *res... |
32,296 | I'm trying to make a DC/DC converter from 12V to 5V using a [MC34063](http://www.onsemi.com/pub_link/Collateral/MC34063A-D.PDF). I found an old cell phone car charger and removed everything and set it up on my breadboard. I'm getting 5V out but only 0.12A. I checked the car charger before I took it out and it was 5V an... | 2012/05/21 | [
"https://electronics.stackexchange.com/questions/32296",
"https://electronics.stackexchange.com",
"https://electronics.stackexchange.com/users/9600/"
] | The capacitor *CT* changes the duty cycle. Parasitic capacitance from the breadboard will increase its value. Play with this capacitor after studying p.4 of [the datasheet](http://www.onsemi.com/pub_link/Collateral/MC34063A-D.PDF). | At a guess, I recon the 0.33 ohm resistor you are using is actually a 3.3 ohm resistor (3rd band gold, should be silver)
Colour code for a 0.33 ohm R should be orange, orange, silver, plus tolerance band gold 5% brown 1% red 2% |
32,296 | I'm trying to make a DC/DC converter from 12V to 5V using a [MC34063](http://www.onsemi.com/pub_link/Collateral/MC34063A-D.PDF). I found an old cell phone car charger and removed everything and set it up on my breadboard. I'm getting 5V out but only 0.12A. I checked the car charger before I took it out and it was 5V an... | 2012/05/21 | [
"https://electronics.stackexchange.com/questions/32296",
"https://electronics.stackexchange.com",
"https://electronics.stackexchange.com/users/9600/"
] | IF it worked before then your loop area is too big in your layout. Keep all wires short as possible in the loop.
Consolidate all your Grounds, Vin ,L ,Co, Zener, Rsc, wires to pin 1,2,7,8, and caps connected to IC within a 1" radius. Even if running 20~50KHz the dV/Dt is high and is affected by stray capacitance.
Th... | At a guess, I recon the 0.33 ohm resistor you are using is actually a 3.3 ohm resistor (3rd band gold, should be silver)
Colour code for a 0.33 ohm R should be orange, orange, silver, plus tolerance band gold 5% brown 1% red 2% |
7,693,273 | It's a populations genetics program handed out by my professors and modified by the students.
Basically it's supposed to simulate the expected number of mutations twenty times with a given sample, population, and mutation rate (u). However, a critical piece is the total branch length (L), which is the sum of the vario... | 2011/10/07 | [
"https://Stackoverflow.com/questions/7693273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/984748/"
] | `L += x` adds x to the existing L, but you haven't initialized L. Presumably, you want `L = 0` somewhere at the top of your file. | You need to define `L = 0` before doing `L += x`.
In general, before modifying you need to define the variable. For assignment, there is no problem because python will infer the type for you.
Some examples:
```
>>> a += 0 #Invalid
Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: na... |
64,838,972 | I have a question about the on\_member\_update function of the discord.py package.
My Issue is that the on\_member\_update function only triggers when the bot itself is updated (like a role update) and not when an other user is updated (how it's supposed to work).
Here is a breakdown of my Code:
```
import discord
fro... | 2020/11/14 | [
"https://Stackoverflow.com/questions/64838972",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14635409/"
] | You're problem is with `addEventListener()`. You are not listening for a state of `window.matchMedia()`. It should work if you use this:
```js
var x = window.matchMedia("(max-width: 600px)")
x.addEventListener("change", () => {
myFunction(x);
});
``` | You should add resize event listener to your window
```
window.addEventListener('resize', ()=>{
var x = window.matchMedia("(max-width: 600px)")
if (x.matches) { // If media query matches
closeNav()
}
});
``` |
46,183,516 | How do I ensure that when someone makes the following call, that the private constructor is executed?
```
var rc = CrmSecureConfiguration.RestCRMClientConfiguration;
```
Here's the implementation:
```
public class CrmSecureConfiguration
{
private CrmSecureConfiguration()
{
var configurationPackage =... | 2017/09/12 | [
"https://Stackoverflow.com/questions/46183516",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117700/"
] | You can't do that without creating an instance. Perhaps you want a static constructor instead?
```
static CrmSecureConfiguration()
{
var configurationPackage = FabricRuntime.GetActivationContext().GetConfigurationPackageObject("Config");
RestCRMClientConfiguration.CRMOrganizationName = configurationPackage.Se... | Singleton pattern:
```
public class CrmSecureConfiguration
{
private static CrmSecureConfigurationinstance;
private CrmSecureConfiguration() {
var configurationPackage = FabricRuntime.GetActivationContext().GetConfigurationPackageObject("Config");
RestCRMClientConfiguration.CRMOrganizationName = co... |
1,388,117 | How do I solve for p in the following equation:
$50,000=\frac{25000p}{100-p}$ ?
Thanks!! | 2015/08/07 | [
"https://math.stackexchange.com/questions/1388117",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/255788/"
] | By cross Multiplication you get
$50,000(100-p)=25,000p$
$50,00000 - 50,000p = 25,000p$
$50,00000 = 75,000p$
$p= 50,00000 / 75,000$
$p=66.66$ Approximately | Notice, $$50000=\frac{25000p}{100-p}$$ $$2=\frac{p}{100-p}$$ $\color{red}{\text{cross multiplication}}$ $$2(100-p)=p$$ $$200-2p=p$$ $$p+2p=200$$ $$3p=200$$ $$\bbox[5px, border:2px solid #C0A000]{\color{red}{p=\frac{200}{3}\approx66.67}}$$ $ |
8,720,910 | I am having problems with the retrieval of data from my database using a where clause with a for loop variable. this codes currently can retrieve the data from the database but however the values retrieved from the database stockpiles. at the number 1 in the for loop its still fine. but when it goes to the next one. th... | 2012/01/04 | [
"https://Stackoverflow.com/questions/8720910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1101743/"
] | You need to wrap your variable in 'x' single quotes in your where clause, otherwise it will think you mean id = true, which is true for all of them =) I had the same problem recently
EDIT: So instead of saying where spending.SectorID = $i, you should have 'somevalue', just make a new variable $example = "'" . $i . "'"... | Move your `$spendingname = array();` and other array definitions inside the loop. |
8,369,029 | Say I have the following class with a method returning a list:
```
class C:
def f(self):
return [1,2,3]
```
If I loop over the list returned fro the method, as follows:
```
c = C()
for i in c.f():
print(i)
```
Inside the `for` loop, will `c.f()` be executed multiple times? If yes, in order to get ... | 2011/12/03 | [
"https://Stackoverflow.com/questions/8369029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1040752/"
] | from the [python docs](http://docs.python.org/reference/compound_stmts.html#for):
>
> The for statement is used to iterate over the elements of a sequence
> (such as a string, tuple or list) or other iterable object:
>
>
>
> ```
> for_stmt ::= "for" target_list "in" expression_list ":" suite
> ["els... | No it is **executed once**.
And your method is not correctly defined. Should have a `self` argument:
```
class C:
def f(self):
return [1,2,3]
``` |
8,369,029 | Say I have the following class with a method returning a list:
```
class C:
def f(self):
return [1,2,3]
```
If I loop over the list returned fro the method, as follows:
```
c = C()
for i in c.f():
print(i)
```
Inside the `for` loop, will `c.f()` be executed multiple times? If yes, in order to get ... | 2011/12/03 | [
"https://Stackoverflow.com/questions/8369029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1040752/"
] | `c.f()` will not get executed multiple times.
You didn't ask, but you might be curious about [generators](http://docs.python.org/tutorial/classes.html#generators).
Your example as a generator would be as follows:
```
class C:
def f():
yield 1
yield 2
yield 3
```
The loop where you itera... | Did you try to test it yourself? The answer to your question is NO.
Here is how you should have tested it. Moreover there were lot of flaws in your code. Check the self commented modified version below
```
>>> class C: #its class not Class and C not C()
def f(self): #You were missing the self argument
pri... |
8,369,029 | Say I have the following class with a method returning a list:
```
class C:
def f(self):
return [1,2,3]
```
If I loop over the list returned fro the method, as follows:
```
c = C()
for i in c.f():
print(i)
```
Inside the `for` loop, will `c.f()` be executed multiple times? If yes, in order to get ... | 2011/12/03 | [
"https://Stackoverflow.com/questions/8369029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1040752/"
] | ```
In [395]: def tester():
...: print "Tester Called!"
...: return [1,2,3]
In [396]: for i in tester():
...: pass
Tester Called!
```
Seems the answer is no. | from the [python docs](http://docs.python.org/reference/compound_stmts.html#for):
>
> The for statement is used to iterate over the elements of a sequence
> (such as a string, tuple or list) or other iterable object:
>
>
>
> ```
> for_stmt ::= "for" target_list "in" expression_list ":" suite
> ["els... |
8,369,029 | Say I have the following class with a method returning a list:
```
class C:
def f(self):
return [1,2,3]
```
If I loop over the list returned fro the method, as follows:
```
c = C()
for i in c.f():
print(i)
```
Inside the `for` loop, will `c.f()` be executed multiple times? If yes, in order to get ... | 2011/12/03 | [
"https://Stackoverflow.com/questions/8369029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1040752/"
] | from the [python docs](http://docs.python.org/reference/compound_stmts.html#for):
>
> The for statement is used to iterate over the elements of a sequence
> (such as a string, tuple or list) or other iterable object:
>
>
>
> ```
> for_stmt ::= "for" target_list "in" expression_list ":" suite
> ["els... | It will be executed only once. But there will be syntax errors in your code:
`class` , not Class
`def f(self)`, not def f() |
8,369,029 | Say I have the following class with a method returning a list:
```
class C:
def f(self):
return [1,2,3]
```
If I loop over the list returned fro the method, as follows:
```
c = C()
for i in c.f():
print(i)
```
Inside the `for` loop, will `c.f()` be executed multiple times? If yes, in order to get ... | 2011/12/03 | [
"https://Stackoverflow.com/questions/8369029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1040752/"
] | It will be executed only once. But there will be syntax errors in your code:
`class` , not Class
`def f(self)`, not def f() | Did you try to test it yourself? The answer to your question is NO.
Here is how you should have tested it. Moreover there were lot of flaws in your code. Check the self commented modified version below
```
>>> class C: #its class not Class and C not C()
def f(self): #You were missing the self argument
pri... |
8,369,029 | Say I have the following class with a method returning a list:
```
class C:
def f(self):
return [1,2,3]
```
If I loop over the list returned fro the method, as follows:
```
c = C()
for i in c.f():
print(i)
```
Inside the `for` loop, will `c.f()` be executed multiple times? If yes, in order to get ... | 2011/12/03 | [
"https://Stackoverflow.com/questions/8369029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1040752/"
] | ```
In [395]: def tester():
...: print "Tester Called!"
...: return [1,2,3]
In [396]: for i in tester():
...: pass
Tester Called!
```
Seems the answer is no. | No it is **executed once**.
And your method is not correctly defined. Should have a `self` argument:
```
class C:
def f(self):
return [1,2,3]
``` |
8,369,029 | Say I have the following class with a method returning a list:
```
class C:
def f(self):
return [1,2,3]
```
If I loop over the list returned fro the method, as follows:
```
c = C()
for i in c.f():
print(i)
```
Inside the `for` loop, will `c.f()` be executed multiple times? If yes, in order to get ... | 2011/12/03 | [
"https://Stackoverflow.com/questions/8369029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1040752/"
] | It will be executed only once. But there will be syntax errors in your code:
`class` , not Class
`def f(self)`, not def f() | No it is **executed once**.
And your method is not correctly defined. Should have a `self` argument:
```
class C:
def f(self):
return [1,2,3]
``` |
8,369,029 | Say I have the following class with a method returning a list:
```
class C:
def f(self):
return [1,2,3]
```
If I loop over the list returned fro the method, as follows:
```
c = C()
for i in c.f():
print(i)
```
Inside the `for` loop, will `c.f()` be executed multiple times? If yes, in order to get ... | 2011/12/03 | [
"https://Stackoverflow.com/questions/8369029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1040752/"
] | ```
In [395]: def tester():
...: print "Tester Called!"
...: return [1,2,3]
In [396]: for i in tester():
...: pass
Tester Called!
```
Seems the answer is no. | Did you try to test it yourself? The answer to your question is NO.
Here is how you should have tested it. Moreover there were lot of flaws in your code. Check the self commented modified version below
```
>>> class C: #its class not Class and C not C()
def f(self): #You were missing the self argument
pri... |
8,369,029 | Say I have the following class with a method returning a list:
```
class C:
def f(self):
return [1,2,3]
```
If I loop over the list returned fro the method, as follows:
```
c = C()
for i in c.f():
print(i)
```
Inside the `for` loop, will `c.f()` be executed multiple times? If yes, in order to get ... | 2011/12/03 | [
"https://Stackoverflow.com/questions/8369029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1040752/"
] | from the [python docs](http://docs.python.org/reference/compound_stmts.html#for):
>
> The for statement is used to iterate over the elements of a sequence
> (such as a string, tuple or list) or other iterable object:
>
>
>
> ```
> for_stmt ::= "for" target_list "in" expression_list ":" suite
> ["els... | Did you try to test it yourself? The answer to your question is NO.
Here is how you should have tested it. Moreover there were lot of flaws in your code. Check the self commented modified version below
```
>>> class C: #its class not Class and C not C()
def f(self): #You were missing the self argument
pri... |
8,369,029 | Say I have the following class with a method returning a list:
```
class C:
def f(self):
return [1,2,3]
```
If I loop over the list returned fro the method, as follows:
```
c = C()
for i in c.f():
print(i)
```
Inside the `for` loop, will `c.f()` be executed multiple times? If yes, in order to get ... | 2011/12/03 | [
"https://Stackoverflow.com/questions/8369029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1040752/"
] | ```
In [395]: def tester():
...: print "Tester Called!"
...: return [1,2,3]
In [396]: for i in tester():
...: pass
Tester Called!
```
Seems the answer is no. | It will be executed only once. But there will be syntax errors in your code:
`class` , not Class
`def f(self)`, not def f() |
67,129,170 | I have a few IEnumerable of nullable Doubles:
```
IEnumerable<Double?> X = new List<Double> { null, 2.2, 4.4, 5.5, 3.2 }
IEnumerable<Double?> Y = new List<Double> { null, null, 4.4, 5.5 }
```
I need to find the maximum index of the first non-null element in both lists, e.g:
```
- Index of First non-null element in... | 2021/04/16 | [
"https://Stackoverflow.com/questions/67129170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/577805/"
] | Well, you could create an extension if you need it often:
```
public static class Extensions
{
public static int FindCommonMinIndexWhere<T>(this IEnumerable<IEnumerable<T>> sequences, Func<T, bool> predicate)
{
int commonMinIndex = -1;
foreach(var seq in sequences)
{
int min... | Well, one way to do this is using Zip:
```
IEnumerable<double?> x = new List<double?> { null, 2.2, 4.4, 5.5, 3.2 };
IEnumerable<double?> y = new List<double?> { null, null, 4.4, 5.5 };
IEnumerable<double?> z = new List<double?> { 1, null, null, 4.4, 5.5 };
var result = x
.Zip(y, (a,b) => new List<double?>{a,b})
... |
67,129,170 | I have a few IEnumerable of nullable Doubles:
```
IEnumerable<Double?> X = new List<Double> { null, 2.2, 4.4, 5.5, 3.2 }
IEnumerable<Double?> Y = new List<Double> { null, null, 4.4, 5.5 }
```
I need to find the maximum index of the first non-null element in both lists, e.g:
```
- Index of First non-null element in... | 2021/04/16 | [
"https://Stackoverflow.com/questions/67129170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/577805/"
] | Well, you could create an extension if you need it often:
```
public static class Extensions
{
public static int FindCommonMinIndexWhere<T>(this IEnumerable<IEnumerable<T>> sequences, Func<T, bool> predicate)
{
int commonMinIndex = -1;
foreach(var seq in sequences)
{
int min... | You can get a count of the initial nulls using [`TakeWhile`](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.takewhile?view=net-5.0). Because of base-zero indexing, the count of initial nulls is equal to the index of the first non-null element.
```
IEnumerable<Double?> X = new List<Double> { null, ... |
108,383 | Alice is teaching a class and one student is clearly not understanding the material very well. Should she approach the student (e.g. ask to meet after class, write an email, or during class itself if it's not a lecture) and offer to help?
The argument for "yes" is that although the student might not ask for help, he o... | 2018/04/20 | [
"https://academia.stackexchange.com/questions/108383",
"https://academia.stackexchange.com",
"https://academia.stackexchange.com/users/84834/"
] | Part of teaching is figuring out if what you want to teach is actually understood. This is something you should be doing continuously. As part of that you automatically find the students that struggle more than others, and that typically offers natural moments in which you can discuss what that student can do to improv... | When I am teaching excel, I often find when walking around that I can see an error in the student's spreadsheet and I just say quietly as I walk by "You should check cell A3".
What happens next is either they sort it themselves or they then ask for help...
As I am available in that workshop, some students will ask be... |
90,414 | Recently a piece of software started showing up in my menubar. I don't remember installing it, I have no idea what it is. The icon is three chevrons and the menu contains three items named: "Software Portal", "Vulnerability Scan" and "Inventory Scan".
.
From [this support page](http://community.landesk.com/support/message/76144#76144):
>
> This starts at startup with the little three-chevron logo in the menu bar
>
>
> | If it is opened on login, check login items, `{~,}/Library/Launch{Daemons,Agents}/`, or [/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist](https://apple.stackexchange.com/questions/86217/disabling-startup-items-that-run-on-their-own/86280#86280).
You could also try running `sudo opensnoop` and clicking... |
4,438,605 | I have to clean up from a list of files the ones that do not exist any more. The ones whose status is indeterminable should be given a warning about but left on the list. Sounds simple enough. However, the c functions I tried to solve this with don't seem to give a reliable answer between whether the file really does n... | 2010/12/14 | [
"https://Stackoverflow.com/questions/4438605",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/264141/"
] | In theory, a Flex 3 SWC should work fine for all Flex 3 point releases. A Flex 4 SWC should work fine with all Flex 4 point releases. I wouldn't expect a Flex 3 SWC to work against Flex 4, but it depends what is in the SWC and what classes are used.
In practice, odd errors sometimes do crop up. I strongly recommend co... | Think of it this way:
Your Flex application starts loading and flashPlayer loads in the UIComponent class. When the classes from your swc are used (and they have a UIComponent compiled-in from Flex 3.2) flashPlayer uses the already-used UIComponent from the swf that was first initializing, not the one that was compile... |
25,215,491 | I have a txt file named sample.txt, and I want to open it via the Windows Powershell in Python. I want the contents of the text file to be opened and displayed within the shell. So I go to the folder that the txt file is located in, and I ran python in the shell. However, I'm not sure where to go from here. When I do
... | 2014/08/09 | [
"https://Stackoverflow.com/questions/25215491",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3924403/"
] | you can animate SKShapeNode's path by supplying a custom strokeShader that outputs based on a few of SKShader's [properties](https://developer.apple.com/reference/spritekit/skshader), `v_path_distance` and `u_path_length`. This hinted at by rickster above, full code to do so follows. Within the shader, `u_current_perce... | Based on Bobjt's [answer](https://stackoverflow.com/a/41624474/129202), my shader which makes use of the glowWidth of SKShapeNode...
So when I use this I can use `shapeNode.glowWidth = 5.0;` etc!
```
void main()
{
vec4 def = SKDefaultShading();
if ( u_path_length == 0.0 ) {
gl_FragColor = vec4( 0xff /... |
32,193,527 | In a fighting program, I have two players in an array:
```
players = [brad, josh]
```
I want to randomly select two distinct players, one of which will attack the other, schematically like this:
```
random_player.attack(other_random_player)
```
I want to make sure that the players never attack themselves. If I do... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32193527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2056180/"
] | You could use `.sample`:
```
match = players.sample(2);
match[0].attack(match[1]);
```
This will randomly pick two players from the array, then you have them fight each other. There is no way the same player will be picked for both.
More cleanly:
```
p1, p2 = players.sample(2)
p1.attack p2
``` | You could do something like this:
```
players.delete_at(rand(players.length)).attack(players.sample)
```
That way it will remove 1 player from the array every time. That will work if you have more than 2 players as well, and want one of the players to attack a random other player.
Or you could just do this if you o... |
32,193,527 | In a fighting program, I have two players in an array:
```
players = [brad, josh]
```
I want to randomly select two distinct players, one of which will attack the other, schematically like this:
```
random_player.attack(other_random_player)
```
I want to make sure that the players never attack themselves. If I do... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32193527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2056180/"
] | You could use `.sample`:
```
match = players.sample(2);
match[0].attack(match[1]);
```
This will randomly pick two players from the array, then you have them fight each other. There is no way the same player will be picked for both.
More cleanly:
```
p1, p2 = players.sample(2)
p1.attack p2
``` | This is a good use case for a [Set](http://ruby-doc.org/stdlib-2.2.3/libdoc/set/rdoc/Set.html) for a few reasons:
1. Players are unique
2. The order of the elements makes no difference
3. You're instantly protected if you mistakenly try to add the same player twice to the Set.
Here's an example:
```
set = Set.new
se... |
32,193,527 | In a fighting program, I have two players in an array:
```
players = [brad, josh]
```
I want to randomly select two distinct players, one of which will attack the other, schematically like this:
```
random_player.attack(other_random_player)
```
I want to make sure that the players never attack themselves. If I do... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32193527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2056180/"
] | You could use `.sample`:
```
match = players.sample(2);
match[0].attack(match[1]);
```
This will randomly pick two players from the array, then you have them fight each other. There is no way the same player will be picked for both.
More cleanly:
```
p1, p2 = players.sample(2)
p1.attack p2
``` | ```
attacker, attackee = players.shuffle
attacker.atack(attackee)
``` |
32,193,527 | In a fighting program, I have two players in an array:
```
players = [brad, josh]
```
I want to randomly select two distinct players, one of which will attack the other, schematically like this:
```
random_player.attack(other_random_player)
```
I want to make sure that the players never attack themselves. If I do... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32193527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2056180/"
] | This is a good use case for a [Set](http://ruby-doc.org/stdlib-2.2.3/libdoc/set/rdoc/Set.html) for a few reasons:
1. Players are unique
2. The order of the elements makes no difference
3. You're instantly protected if you mistakenly try to add the same player twice to the Set.
Here's an example:
```
set = Set.new
se... | You could do something like this:
```
players.delete_at(rand(players.length)).attack(players.sample)
```
That way it will remove 1 player from the array every time. That will work if you have more than 2 players as well, and want one of the players to attack a random other player.
Or you could just do this if you o... |
32,193,527 | In a fighting program, I have two players in an array:
```
players = [brad, josh]
```
I want to randomly select two distinct players, one of which will attack the other, schematically like this:
```
random_player.attack(other_random_player)
```
I want to make sure that the players never attack themselves. If I do... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32193527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2056180/"
] | ```
attacker, attackee = players.shuffle
attacker.atack(attackee)
``` | You could do something like this:
```
players.delete_at(rand(players.length)).attack(players.sample)
```
That way it will remove 1 player from the array every time. That will work if you have more than 2 players as well, and want one of the players to attack a random other player.
Or you could just do this if you o... |
32,193,527 | In a fighting program, I have two players in an array:
```
players = [brad, josh]
```
I want to randomly select two distinct players, one of which will attack the other, schematically like this:
```
random_player.attack(other_random_player)
```
I want to make sure that the players never attack themselves. If I do... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32193527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2056180/"
] | ```
attacker, attackee = players.shuffle
attacker.atack(attackee)
``` | This is a good use case for a [Set](http://ruby-doc.org/stdlib-2.2.3/libdoc/set/rdoc/Set.html) for a few reasons:
1. Players are unique
2. The order of the elements makes no difference
3. You're instantly protected if you mistakenly try to add the same player twice to the Set.
Here's an example:
```
set = Set.new
se... |
3,126,663 | What are best practices and tips to use JavaScript without losing the site's Accessibility, usability and SEO, and site's content if JavaScript is disabled but still keeping site usability for JavaScript enabled users?
In what scenarios we should avoid full dependency on JavaScript? | 2010/06/27 | [
"https://Stackoverflow.com/questions/3126663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/84201/"
] | You should be developing the website using the principles of [progressive enhancement](http://en.wikipedia.org/wiki/Progressive_enhancement).
That is, make it work (and look OK) without CSS and Javascript. Add CSS, then Javascript progressively. The idea is that you can use CSS and Javascript to change the original ma... | If You use MVC, you can easy build 2 controllers for every page, one which produces rich client side application with javascript, etc.; 2nd which produces simple interface only with links and text. |
35,668,939 | Is there a way to get the index of each object in a List that is null?
For example:
```
List<string> list = new List<string>() { "1", null, "2", null, "3" };
```
Is it possible to get the information that list[1] and list[3] is null?
In the best case I would get another list that provides me all the indexes that a... | 2016/02/27 | [
"https://Stackoverflow.com/questions/35668939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3639453/"
] | Yes, the simplest option would probably be:
```
var nullIndexes = list.Select((value, index) => new { value, index })
.Where(pair => pair.value == null)
.Select(pair => pair.index)
.ToList();
``` | Try this.
```
list.Select((item,i) => new { index = i, item=item })
.Where(p=>p.item == null)
.Select(item=>item.index);
```
Working [`Demo`](https://dotnetfiddle.net/IyFVpa) |
15,958,612 | On an Amazon EC2 (`uname -r` gives "3.4.37-40.44.amzn1.x86\_64", which I hear is based on Cent OS) I tried installing:
```
yum install mysql
yum install mysql-devel
```
And even
```
yum install mysql-libs
```
(Due to [this thread](http://opensips-open-sip-server.1449251.n2.nabble.com/libmysqlclient-dev-for-CentOS... | 2013/04/11 | [
"https://Stackoverflow.com/questions/15958612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/111307/"
] | bobobobo! You are so **wrong**.
First of all, you don't need a libmysqlclient.a file, when you have the .so file. [The .a file is for static linking, .so file for dynamic linking.](https://stackoverflow.com/questions/9809213/what-are-a-and-so-files). .so files are decidely better and make you cool.
The problem you ge... | When you use .so, they are linked a run-time. This makes your compiled code smaller. Not usually big deal these days. The really great feature is that when you update your system, and the library gets updated, you will link in the new (and hopefully) better library. The updates often contain bug fixes and security fixe... |
21,521 | Now I have finished [my underwater tunnel](https://gaming.stackexchange.com/questions/21197/how-can-i-build-an-underwater-tunnel) I have built somewhere for my railway to stop at. The cart comes in from the left, hits the booster and then hits the sloped booster track (unpowered). I am supposed to hit the button, power... | 2011/05/03 | [
"https://gaming.stackexchange.com/questions/21521",
"https://gaming.stackexchange.com",
"https://gaming.stackexchange.com/users/6418/"
] | My suggestion would be to change the normal rail at the bottom of the dip into a powered rail. This also removes the need for two pieces of Redstone dust, as one would power the whole section.
You don't need to use Redstone to bypass that on the way in; you could simply build something like this (it might take you a b... | If that's the end of the line, I would suggest this method that is (in terms of gold a lot!) cheaper then Kevin Y's:

When arriving, the booster track will send the cart up the slope and it will stop at the block.
When leaving, approach from behind t... |
21,521 | Now I have finished [my underwater tunnel](https://gaming.stackexchange.com/questions/21197/how-can-i-build-an-underwater-tunnel) I have built somewhere for my railway to stop at. The cart comes in from the left, hits the booster and then hits the sloped booster track (unpowered). I am supposed to hit the button, power... | 2011/05/03 | [
"https://gaming.stackexchange.com/questions/21521",
"https://gaming.stackexchange.com",
"https://gaming.stackexchange.com/users/6418/"
] | My suggestion would be to change the normal rail at the bottom of the dip into a powered rail. This also removes the need for two pieces of Redstone dust, as one would power the whole section.
You don't need to use Redstone to bypass that on the way in; you could simply build something like this (it might take you a b... | If you don't mind using a bit more of resources, you could create a mechanism to stop the train using detector rails and redstone, like this:

provided that the train enters the station already sped up.
Placing the blocks like this
 I have built somewhere for my railway to stop at. The cart comes in from the left, hits the booster and then hits the sloped booster track (unpowered). I am supposed to hit the button, power... | 2011/05/03 | [
"https://gaming.stackexchange.com/questions/21521",
"https://gaming.stackexchange.com",
"https://gaming.stackexchange.com/users/6418/"
] | If that's the end of the line, I would suggest this method that is (in terms of gold a lot!) cheaper then Kevin Y's:

When arriving, the booster track will send the cart up the slope and it will stop at the block.
When leaving, approach from behind t... | If you don't mind using a bit more of resources, you could create a mechanism to stop the train using detector rails and redstone, like this:

provided that the train enters the station already sped up.
Placing the blocks like this
![enter image desc... |
18,936,693 | I have a form field that I'd like to munge a little before the user submits the form.
Specifically, it's a location field, and I need to check whether they've added the state abbreviation. If not, I add it.
I'm watching for blur() so i can see when the user's tabbed or clicked out of the field:
```
$('#views-expose... | 2013/09/21 | [
"https://Stackoverflow.com/questions/18936693",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1705114/"
] | set a `.submit` callback as well/instead, this will be called before the actual form submits and you can cancel the submission if needed
```
$("#myForm").submit(function(e){
//check/do stuff here before submit
//use e.preventDefault() or return false to stop submission if needed.
});
```
[JQuery .submit Doc](h... | ```
$(window).keydown(function(event){
if(event.keyCode == 13) {
$(':focus').trigger('blur');
event.preventDefault();
return false;
}
});
``` |
18,936,693 | I have a form field that I'd like to munge a little before the user submits the form.
Specifically, it's a location field, and I need to check whether they've added the state abbreviation. If not, I add it.
I'm watching for blur() so i can see when the user's tabbed or clicked out of the field:
```
$('#views-expose... | 2013/09/21 | [
"https://Stackoverflow.com/questions/18936693",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1705114/"
] | You can create a `.submit()` that trigger `.blur()` on focused element like that :
```
$('form').submit(function(){
$(':focus').trigger('blur');
})
``` | ```
$(window).keydown(function(event){
if(event.keyCode == 13) {
$(':focus').trigger('blur');
event.preventDefault();
return false;
}
});
``` |
668,412 | I have MineCraft server, and I need run it every time I start Debian.
I solved it, but it always run as root.
I need it run as normal user. | 2013/11/01 | [
"https://superuser.com/questions/668412",
"https://superuser.com",
"https://superuser.com/users/268768/"
] | Try this:
```
function! EnterEnter()
if getline(".") =~ '^\s*\(//\|#\|"\)\s*$'
return "\<C-u>"
else
return "\<CR>"
endif
endfunction
imap <expr> <CR> EnterEnter()
``` | Remove r from 'formatoptions. That's what that option does. Turning it off will mean you never get vim doing that for you which means you will need to add the leading comment markers when you do actually want them but that's the tradeoff. |
668,412 | I have MineCraft server, and I need run it every time I start Debian.
I solved it, but it always run as root.
I need it run as normal user. | 2013/11/01 | [
"https://superuser.com/questions/668412",
"https://superuser.com",
"https://superuser.com/users/268768/"
] | Try this:
```
function! EnterEnter()
if getline(".") =~ '^\s*\(//\|#\|"\)\s*$'
return "\<C-u>"
else
return "\<CR>"
endif
endfunction
imap <expr> <CR> EnterEnter()
``` | I extended @romainl's answer to work with arbitrary languages by generating the regex from Vim's `&commentstring`:
```
function! s:IsOnlyComment(getlineArg)
let commentRegex='^\s*'.substitute(&commentstring,'%s','\\s*','').'$'
return strlen(matchstr(getline(a:getlineArg), commentRegex)) > 0
endfunction
function! ... |
36,438,540 | I've created a fileStream and a streamwriter to write to this. Problem is my file is not showing up with any text. The objects have instantiated correctly and the path and everything is write, just can't see anything writing. Maybe a problem with the streamwriter?
```
public class Logger {
StreamWriter sw;
... | 2016/04/05 | [
"https://Stackoverflow.com/questions/36438540",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3519261/"
] | The writes are being buffered in memory, try calling `logFileStream.Flush();` at the end of each Log function.
You really shouldn't be keeping the file handle open between calls though, if I were you I would open and close it in each function. If you're doing a lot of logging then buffer it yourself in memory and dump... | This is the correct version of your example
* use autoflush = true in stream writer
* open/close stream in every request - if it is correctly implemented, autoflush is unnecessary (flush will be done after dispose StreamWriter)
* use FileMode.Append
```
public class Logger
{
public enum LogLevel
... |
51,268,089 | I am playing with a little jQuery snippet that changes the position of a fixed element by manipulating the "top" value based on the offset of the element from the window.
I have created this jsFiddle to better illustrate what I mean:
[jsFiddle](http://jsfiddle.net/r0632ve8/7/)
Here is the simple jQuery code:
```
... | 2018/07/10 | [
"https://Stackoverflow.com/questions/51268089",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1517585/"
] | You need to change top with transfrom AND remove `100px` which is the default top value added in the CSS:
```js
function switchIt () {
$('.text-two').each(function() {
$(this).css('transform','translateY('+(
$('.text-one').offset().top - $(this).closest('.content').offset().top-100)+'px)'
);
})... | just assign the transform property of the style property for the element
```js
//using jquery
$('#one').css({transform:"translateY(100px)"});
//using vanilla JavaScript
document.getElementById('two').style.transform = "translateY(100px)";
```
```css
#one, #two{
width:100px;
height:100px;
display:inline-block;
... |
8,245,702 | In [VB.NET](http://en.wikipedia.org/wiki/Visual_Basic_.NET) I can do
>
>
> ```
> private sub button_click(sender, e) handles Button1.Click, Button2.Click etc...
> do something...
> end sub
>
> ```
>
>
Is there a method for this in C# .NET? I have roughly 16 buttons that all call the same function, just passing t... | 2011/11/23 | [
"https://Stackoverflow.com/questions/8245702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/456638/"
] | ```
Button1.Click += button_click;
Button2.Click += button_click;
``` | Try this:
```
button1.Click += button_click;
button2.Click += button_click;
``` |
8,245,702 | In [VB.NET](http://en.wikipedia.org/wiki/Visual_Basic_.NET) I can do
>
>
> ```
> private sub button_click(sender, e) handles Button1.Click, Button2.Click etc...
> do something...
> end sub
>
> ```
>
>
Is there a method for this in C# .NET? I have roughly 16 buttons that all call the same function, just passing t... | 2011/11/23 | [
"https://Stackoverflow.com/questions/8245702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/456638/"
] | ```
Button1.Click += button_click;
Button2.Click += button_click;
``` | C# does not have the `Handles` keyword.
Instead, you need to add the handlers explicitly:
```
something.Click += button_click;
somethingElse.Click += button_click;
``` |
8,245,702 | In [VB.NET](http://en.wikipedia.org/wiki/Visual_Basic_.NET) I can do
>
>
> ```
> private sub button_click(sender, e) handles Button1.Click, Button2.Click etc...
> do something...
> end sub
>
> ```
>
>
Is there a method for this in C# .NET? I have roughly 16 buttons that all call the same function, just passing t... | 2011/11/23 | [
"https://Stackoverflow.com/questions/8245702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/456638/"
] | Manually, you can do this:
```
button1.Click += button_Click;
button2.Click += button_Click;
...
```
In the Designer, the Click event property is actually a drop-down menu where you can choose among existing methods that have the appropriate signature. | Try this:
```
button1.Click += button_click;
button2.Click += button_click;
``` |
8,245,702 | In [VB.NET](http://en.wikipedia.org/wiki/Visual_Basic_.NET) I can do
>
>
> ```
> private sub button_click(sender, e) handles Button1.Click, Button2.Click etc...
> do something...
> end sub
>
> ```
>
>
Is there a method for this in C# .NET? I have roughly 16 buttons that all call the same function, just passing t... | 2011/11/23 | [
"https://Stackoverflow.com/questions/8245702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/456638/"
] | ```
Button1.Click += button_click;
Button2.Click += button_click;
``` | If you want to keep it maintainable, I would go with something like this:
```
//btnArray can also be populated by traversing relevant Controls collection(s)
Button[] btnArray = new Button[] {button1, button2};
foreach(Button btn in btnArray) {
btn.Click += button_Click;
}
```
Any refactoring to this code is done v... |
8,245,702 | In [VB.NET](http://en.wikipedia.org/wiki/Visual_Basic_.NET) I can do
>
>
> ```
> private sub button_click(sender, e) handles Button1.Click, Button2.Click etc...
> do something...
> end sub
>
> ```
>
>
Is there a method for this in C# .NET? I have roughly 16 buttons that all call the same function, just passing t... | 2011/11/23 | [
"https://Stackoverflow.com/questions/8245702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/456638/"
] | Manually, you can do this:
```
button1.Click += button_Click;
button2.Click += button_Click;
...
```
In the Designer, the Click event property is actually a drop-down menu where you can choose among existing methods that have the appropriate signature. | ```
btn1.Click += button_click;
btn2.Click += button_click;
```
is the answer |
8,245,702 | In [VB.NET](http://en.wikipedia.org/wiki/Visual_Basic_.NET) I can do
>
>
> ```
> private sub button_click(sender, e) handles Button1.Click, Button2.Click etc...
> do something...
> end sub
>
> ```
>
>
Is there a method for this in C# .NET? I have roughly 16 buttons that all call the same function, just passing t... | 2011/11/23 | [
"https://Stackoverflow.com/questions/8245702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/456638/"
] | C# does not have the `Handles` keyword.
Instead, you need to add the handlers explicitly:
```
something.Click += button_click;
somethingElse.Click += button_click;
``` | If you want to keep it maintainable, I would go with something like this:
```
//btnArray can also be populated by traversing relevant Controls collection(s)
Button[] btnArray = new Button[] {button1, button2};
foreach(Button btn in btnArray) {
btn.Click += button_Click;
}
```
Any refactoring to this code is done v... |
8,245,702 | In [VB.NET](http://en.wikipedia.org/wiki/Visual_Basic_.NET) I can do
>
>
> ```
> private sub button_click(sender, e) handles Button1.Click, Button2.Click etc...
> do something...
> end sub
>
> ```
>
>
Is there a method for this in C# .NET? I have roughly 16 buttons that all call the same function, just passing t... | 2011/11/23 | [
"https://Stackoverflow.com/questions/8245702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/456638/"
] | C# does not have the `Handles` keyword.
Instead, you need to add the handlers explicitly:
```
something.Click += button_click;
somethingElse.Click += button_click;
``` | ```
btn1.Click += button_click;
btn2.Click += button_click;
```
is the answer |
8,245,702 | In [VB.NET](http://en.wikipedia.org/wiki/Visual_Basic_.NET) I can do
>
>
> ```
> private sub button_click(sender, e) handles Button1.Click, Button2.Click etc...
> do something...
> end sub
>
> ```
>
>
Is there a method for this in C# .NET? I have roughly 16 buttons that all call the same function, just passing t... | 2011/11/23 | [
"https://Stackoverflow.com/questions/8245702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/456638/"
] | C# does not have the `Handles` keyword.
Instead, you need to add the handlers explicitly:
```
something.Click += button_click;
somethingElse.Click += button_click;
``` | Try this:
```
button1.Click += button_click;
button2.Click += button_click;
``` |
8,245,702 | In [VB.NET](http://en.wikipedia.org/wiki/Visual_Basic_.NET) I can do
>
>
> ```
> private sub button_click(sender, e) handles Button1.Click, Button2.Click etc...
> do something...
> end sub
>
> ```
>
>
Is there a method for this in C# .NET? I have roughly 16 buttons that all call the same function, just passing t... | 2011/11/23 | [
"https://Stackoverflow.com/questions/8245702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/456638/"
] | ```
Button1.Click += button_click;
Button2.Click += button_click;
``` | Manually, you can do this:
```
button1.Click += button_Click;
button2.Click += button_Click;
...
```
In the Designer, the Click event property is actually a drop-down menu where you can choose among existing methods that have the appropriate signature. |
8,245,702 | In [VB.NET](http://en.wikipedia.org/wiki/Visual_Basic_.NET) I can do
>
>
> ```
> private sub button_click(sender, e) handles Button1.Click, Button2.Click etc...
> do something...
> end sub
>
> ```
>
>
Is there a method for this in C# .NET? I have roughly 16 buttons that all call the same function, just passing t... | 2011/11/23 | [
"https://Stackoverflow.com/questions/8245702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/456638/"
] | If you want to keep it maintainable, I would go with something like this:
```
//btnArray can also be populated by traversing relevant Controls collection(s)
Button[] btnArray = new Button[] {button1, button2};
foreach(Button btn in btnArray) {
btn.Click += button_Click;
}
```
Any refactoring to this code is done v... | ```
btn1.Click += button_click;
btn2.Click += button_click;
```
is the answer |
25,510,802 | I am creating a new website and have been working with ASP.NET using VB.
My website is for Car Racers (speedway). Id like to provide a list of drivers for the fans in the format like this
<http://www.nba.com/lakers/roster?cid=nav_team_expanded>
I have all the info in a dataset from my SQL Server Database, but im havi... | 2014/08/26 | [
"https://Stackoverflow.com/questions/25510802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3979549/"
] | You could use `JSON.parse` to revert the string to an array, so:
```
$('#dropdown').selectpicker('val', JSON.parse(strWard));
```
Edit, with single quotes fixed:
```
var wards = dsFilterOptions.Wards.split(",");
var strWard = '[';
for (i = 0; i < wards.length; i++) {
strWard += '"' + wards[i] + '",';
}
strWard ... | `response.user_accounts` is an array, but it just shows the first value as a dropdown selection, not all values of the array. Please suggest
```js
if (response.user_accounts) {
$('#account').selectpicker('val', response.user_accounts.account_id);
}
``` |
29,833,485 | When I open the ODBC Data Source Administrator (32-bit) to configure it for DB2 connections, I try to add a System DSN, and then add a DB2 database alias. The issue is that when adding the alias, the CLI/ODBC Settings don't show a TCP/IP tab so that I can enter in my db connection info. The only tabs listed are Data So... | 2015/04/23 | [
"https://Stackoverflow.com/questions/29833485",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4825958/"
] | You should be able to set those properties in the Advanced settings:
Add entries for the properties `Hostname` (use the ip address or hostname), `Port` (usually its 50000 for DB2) and that should be enough. Maybe you also need to set Property `Protocol`.
Note: I have never seen a tab to configure the TCP-IP Settings ... | I had a similar issue (not seeing the "TCP/IP" tab) while adding a DSN for the DB2 instance (v10.5) on our server. I added the following properties in the "Advanced Settings" tab, as suggested ;
Hostname: [ip address or hostname of the server]
Port: 50000
Database: [DB2 database I need to connect to]
After specifyi... |
23,063,918 | I'm trying to write a script to check if the remote workstations have 64bit or 32bit operating system. The script simple should check if the directory "Program Files (x86)" exists and then echo the results to the output.txt file. For some reason or another the script doesn't even create the output.txt file. Any suggest... | 2014/04/14 | [
"https://Stackoverflow.com/questions/23063918",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3532327/"
] | There are a couple of things wrong with your code.
1. When assigning your %directory% variable you use `\\%1%\c$\Program Files (x86)`. Here `%1%` should be `%1`
2. You are using the `c$` share, which is mostly not available anymore (or at least not without administative privilidges)
It could work like this:
```
@ech... | ```
IF pingtest==true (
```
will never be true because the string `pingtest` and `true` are not the same.
You need
```
IF %pingtest%==true (
```
Even when you've fixed that, there's a further gotcha:
Within a block statement `(a parenthesised series of statements)`, the **entire** block is parsed and **then** e... |
51,889,950 | My program should accept file input of any data type and display it. However after reading the 7th element, I get the error "NoSuchElementException"
This is my code:
[](https://i.stack.imgur.com/7rxRC.png) | 2018/08/17 | [
"https://Stackoverflow.com/questions/51889950",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8945543/"
] | In the while loop you are doing two "in.next()" in a row without checking "in.hasNext()"
You should store the in.next() in a variable and then add that variable to ArrayType and LinkType.
```
while(in.hasNext()) {
Object o = in.next();
ArrayType.add(o);
LinkType.add(o);
}
```
Based on your comment, if y... | I think you are trying to do this:
```
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(new FileReader("input.text"));
List<String> arrayType = new ArrayList<>(100);
List<String> linkedType = new LinkedList<>();
while (in.hasNext()){
String line = i... |
47,301,463 | I am reading the data From text file and Printing in HTML file using java and Html code, But junk characters printing in HTML file
```java
report.reportGenerator("result.txt", reportHTMLFile, testCaseSheetMasterMap, environmentUrl, "01/01/01", "02/02/02");
StringBuilder htmlStringBuilder = new StringBuilder();
... | 2017/11/15 | [
"https://Stackoverflow.com/questions/47301463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8655529/"
] | Short:
```
<meta charset="utf-8" />
```
Long:
```
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
``` | Include inside your `<head>` tags an encoding tag
Try as follows,
```
<meta charset="utf-8">
```
or
```
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
``` |
47,301,463 | I am reading the data From text file and Printing in HTML file using java and Html code, But junk characters printing in HTML file
```java
report.reportGenerator("result.txt", reportHTMLFile, testCaseSheetMasterMap, environmentUrl, "01/01/01", "02/02/02");
StringBuilder htmlStringBuilder = new StringBuilder();
... | 2017/11/15 | [
"https://Stackoverflow.com/questions/47301463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8655529/"
] | Short:
```
<meta charset="utf-8" />
```
Long:
```
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
``` | This will need to go in the < head > section of your web page.
`<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />`
The server should be sending a response header like this:
```
Content-Type: text/html; charset=UTF-8
```
If the "charset=UTF-8" bit is missing from the Content-Type response head... |
24,909,197 | im trying to make a thread that will run a While-loop and inside the while-loop actions that will change the UI should take place :
```
public void GameHandler()
{
layout = (RelativeLayout) findViewById(R.id.MyLayout);
params=new RelativeLayout.LayoutParams(30,40);
btn1 = (Button) findViewById(R.id.MovingO... | 2014/07/23 | [
"https://Stackoverflow.com/questions/24909197",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2183659/"
] | First off, I recommend reading [this article](https://stackoverflow.com/questions/5837910/systemclock-sleep-vs-thread-sleep-while-waiting-for-a-semaphore-loop), as the current construction you're using is kind of .. dirty ..
Anyway, in order to respond to the actual error you're receiving, it's obvious that you can't ... | "I have heard..." is not a particularly credible source of information. Using background threads is absolutely fine in Android. Spawning undying threads every second does lead to an app crash, just like making an infinite loop will - and with the same comments from fellow devs.
Your "problem" is self-explanatory - as... |
36,732,925 | ```
import re
details = '(2,5 cr / K / M)'
m = re.match(r'\((.*?)\w+cr\w/\w(.)\w/\w(.)\)', details)
credit = m.group(0)
state = m.group(1)
grade = m.group(2)
course = {'credit': credit, 'state': state, 'grade': grade}
print course
```
As this snippet shows, I want to get (`? cr / ? / ?`), but it doesn't work. | 2016/04/20 | [
"https://Stackoverflow.com/questions/36732925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4501163/"
] | Change:
```
m = re.match(r'\((.*?)\w+cr\w/\w(.)\w/\w(.)\)', details)
```
To:
```
m = re.match(r'\((\S+)\s+cr\s+/\s+(\S)\s+/\s+(\S)\)', details)
```
Where `\s` is "whitespace" and `\S` is "anything-but-whitespace". | You can use `\w[^\s)]*` and then remove any unwanted value:
```
>>> s = '(2,5 cr / K / M)'
>>> re.findall(r'\w[^\s)]*', s)
['2,5', 'cr', 'K', 'M']
```
Then you just need assign values discarding `cr` at index 1.
```
>>> s = '(2,5 cr / K / M)'
>>> out = re.findall(r'\w[^\s)]*', s)
>>> credit = out[0]
>>> state = ... |
36,732,925 | ```
import re
details = '(2,5 cr / K / M)'
m = re.match(r'\((.*?)\w+cr\w/\w(.)\w/\w(.)\)', details)
credit = m.group(0)
state = m.group(1)
grade = m.group(2)
course = {'credit': credit, 'state': state, 'grade': grade}
print course
```
As this snippet shows, I want to get (`? cr / ? / ?`), but it doesn't work. | 2016/04/20 | [
"https://Stackoverflow.com/questions/36732925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4501163/"
] | Looks ilke you just confused w and s.. May not fit all edge cases:
```
import re
details = '(2,5 cr / K / M)'
pattern = re.compile(r'^\(([0-9],[0-9]).*/\s([A-Z])\s/\s([A-Z])\)')
m = pattern.match(details)
credit = m.group(1)
state = m.group(2)
grade = m.group(3)
course = {'credit': credit, 'state': state, 'grade':... | You can use `\w[^\s)]*` and then remove any unwanted value:
```
>>> s = '(2,5 cr / K / M)'
>>> re.findall(r'\w[^\s)]*', s)
['2,5', 'cr', 'K', 'M']
```
Then you just need assign values discarding `cr` at index 1.
```
>>> s = '(2,5 cr / K / M)'
>>> out = re.findall(r'\w[^\s)]*', s)
>>> credit = out[0]
>>> state = ... |
38,557,911 | I was looking at an answer to ["Pointers in C: when to use the ampersand and the asterisk"](https://stackoverflow.com/questions/2094666/pointers-in-c-when-to-use-the-ampersand-and-the-asterisk) and am confused about the example `int *p2 = &i;` (from Dan Olson's answer)
The address of `i` is not an int, it's something ... | 2016/07/24 | [
"https://Stackoverflow.com/questions/38557911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6542449/"
] | >
> The address of i is not an int, it's something like 0x02304 say, right?
>
>
>
Pointers are variables that hold memory addresses. An address, just like the address of your house, is an integer assigned to the location of a byte of memory.
>
> How can a C pointer of type int hold a memory address
>
>
>
In ... | Pointers are *abstractions* of memory addresses, with some associated type semantics.
`p2` has type `int *`, or "pointer to `int`". It stores the location of an integer object (in this case, the location of the object `i`). The type of the *expression* `*p2` is `int`:
```
p2 == &i; // both expressions have type int... |
38,557,911 | I was looking at an answer to ["Pointers in C: when to use the ampersand and the asterisk"](https://stackoverflow.com/questions/2094666/pointers-in-c-when-to-use-the-ampersand-and-the-asterisk) and am confused about the example `int *p2 = &i;` (from Dan Olson's answer)
The address of `i` is not an int, it's something ... | 2016/07/24 | [
"https://Stackoverflow.com/questions/38557911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6542449/"
] | I think the reason `int *p2 = &i;` is confusing is the combined effect of the simultaneous declaration and instantiation, and the spacing. I'll explain.
Typically, for a pointer-to-integer `p2` and an integer `i`, writing "`*p2`" dereferences `p2` and gives the `int` living at the address `&i`.
So the code "`int *p2 ... | >
> The address of i is not an int, it's something like 0x02304 say, right?
>
>
>
Pointers are variables that hold memory addresses. An address, just like the address of your house, is an integer assigned to the location of a byte of memory.
>
> How can a C pointer of type int hold a memory address
>
>
>
In ... |
38,557,911 | I was looking at an answer to ["Pointers in C: when to use the ampersand and the asterisk"](https://stackoverflow.com/questions/2094666/pointers-in-c-when-to-use-the-ampersand-and-the-asterisk) and am confused about the example `int *p2 = &i;` (from Dan Olson's answer)
The address of `i` is not an int, it's something ... | 2016/07/24 | [
"https://Stackoverflow.com/questions/38557911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6542449/"
] | >
> The address of i is not an int, it's something like 0x02304 say, right?
>
>
>
Pointers are variables that hold memory addresses. An address, just like the address of your house, is an integer assigned to the location of a byte of memory.
>
> How can a C pointer of type int hold a memory address
>
>
>
In ... | A pointer is its own type.
If it were used with a different syntax it could be written like this:
```
Pointer x = new Pointer(int, address);
``` |
38,557,911 | I was looking at an answer to ["Pointers in C: when to use the ampersand and the asterisk"](https://stackoverflow.com/questions/2094666/pointers-in-c-when-to-use-the-ampersand-and-the-asterisk) and am confused about the example `int *p2 = &i;` (from Dan Olson's answer)
The address of `i` is not an int, it's something ... | 2016/07/24 | [
"https://Stackoverflow.com/questions/38557911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6542449/"
] | `p2` is not an `int`, it is a pointer to `int`. As such, it can hold the address of an `int` variable.
The syntax `int *p2;` defines a pointer to `int`.
Initializing `p2` with `&i` stores the address of variable `i` into `p2`. Modifying the value pointed to by `p2` will modify the value of `i`.
The following alterna... | Pointers are *abstractions* of memory addresses, with some associated type semantics.
`p2` has type `int *`, or "pointer to `int`". It stores the location of an integer object (in this case, the location of the object `i`). The type of the *expression* `*p2` is `int`:
```
p2 == &i; // both expressions have type int... |
38,557,911 | I was looking at an answer to ["Pointers in C: when to use the ampersand and the asterisk"](https://stackoverflow.com/questions/2094666/pointers-in-c-when-to-use-the-ampersand-and-the-asterisk) and am confused about the example `int *p2 = &i;` (from Dan Olson's answer)
The address of `i` is not an int, it's something ... | 2016/07/24 | [
"https://Stackoverflow.com/questions/38557911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6542449/"
] | I think the reason `int *p2 = &i;` is confusing is the combined effect of the simultaneous declaration and instantiation, and the spacing. I'll explain.
Typically, for a pointer-to-integer `p2` and an integer `i`, writing "`*p2`" dereferences `p2` and gives the `int` living at the address `&i`.
So the code "`int *p2 ... | `p2` is not an `int`, it is a pointer to `int`. As such, it can hold the address of an `int` variable.
The syntax `int *p2;` defines a pointer to `int`.
Initializing `p2` with `&i` stores the address of variable `i` into `p2`. Modifying the value pointed to by `p2` will modify the value of `i`.
The following alterna... |
38,557,911 | I was looking at an answer to ["Pointers in C: when to use the ampersand and the asterisk"](https://stackoverflow.com/questions/2094666/pointers-in-c-when-to-use-the-ampersand-and-the-asterisk) and am confused about the example `int *p2 = &i;` (from Dan Olson's answer)
The address of `i` is not an int, it's something ... | 2016/07/24 | [
"https://Stackoverflow.com/questions/38557911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6542449/"
] | `p2` is not an `int`, it is a pointer to `int`. As such, it can hold the address of an `int` variable.
The syntax `int *p2;` defines a pointer to `int`.
Initializing `p2` with `&i` stores the address of variable `i` into `p2`. Modifying the value pointed to by `p2` will modify the value of `i`.
The following alterna... | A pointer is its own type.
If it were used with a different syntax it could be written like this:
```
Pointer x = new Pointer(int, address);
``` |
38,557,911 | I was looking at an answer to ["Pointers in C: when to use the ampersand and the asterisk"](https://stackoverflow.com/questions/2094666/pointers-in-c-when-to-use-the-ampersand-and-the-asterisk) and am confused about the example `int *p2 = &i;` (from Dan Olson's answer)
The address of `i` is not an int, it's something ... | 2016/07/24 | [
"https://Stackoverflow.com/questions/38557911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6542449/"
] | I think the reason `int *p2 = &i;` is confusing is the combined effect of the simultaneous declaration and instantiation, and the spacing. I'll explain.
Typically, for a pointer-to-integer `p2` and an integer `i`, writing "`*p2`" dereferences `p2` and gives the `int` living at the address `&i`.
So the code "`int *p2 ... | Pointers are *abstractions* of memory addresses, with some associated type semantics.
`p2` has type `int *`, or "pointer to `int`". It stores the location of an integer object (in this case, the location of the object `i`). The type of the *expression* `*p2` is `int`:
```
p2 == &i; // both expressions have type int... |
38,557,911 | I was looking at an answer to ["Pointers in C: when to use the ampersand and the asterisk"](https://stackoverflow.com/questions/2094666/pointers-in-c-when-to-use-the-ampersand-and-the-asterisk) and am confused about the example `int *p2 = &i;` (from Dan Olson's answer)
The address of `i` is not an int, it's something ... | 2016/07/24 | [
"https://Stackoverflow.com/questions/38557911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6542449/"
] | I think the reason `int *p2 = &i;` is confusing is the combined effect of the simultaneous declaration and instantiation, and the spacing. I'll explain.
Typically, for a pointer-to-integer `p2` and an integer `i`, writing "`*p2`" dereferences `p2` and gives the `int` living at the address `&i`.
So the code "`int *p2 ... | A pointer is its own type.
If it were used with a different syntax it could be written like this:
```
Pointer x = new Pointer(int, address);
``` |
9,893,488 | I need to download one file from an url that i give from an xml after connect to other url. My problem is that i need the same user agent and ip to do both actions.
To obtain the xml, i use a PHP code that is hosted on my server and i send it the user agent of my app:
```
String ua=new WebView(ct).getSettings().getUs... | 2012/03/27 | [
"https://Stackoverflow.com/questions/9893488",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1201577/"
] | Finally i did this to resolve:
```
Bitmap bmImg;
try {
URL url = new URL(addres);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.addRequestProperty("User-Agent", ua);
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmImg = BitmapFac... | You can use AndroidHttpClient.newInstance(useragent).
See an example here [AndroidHttpClient can not getEntity().getContent() after closed](https://stackoverflow.com/questions/9393426/androidhttpclient-can-not-getentity-getcontent-after-closed) |
56,957,211 | I Wonder if this sql query is secured from sql-injection, and if it is ok, or i should modify something.
I tried to bind the id from the GET and than if everything is ok, i use that actual query with that id.
```
if(isset($_GET['id']) && $_GET['id'] != null) {
$id = $_GET['id'];
$stmt = $mysqli->prepare('SELECT ... | 2019/07/09 | [
"https://Stackoverflow.com/questions/56957211",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10531001/"
] | General rule of thumb: If your query has variable interpolation, like it does with `$secid`, then *probably no*.
Use prepared statements with placeholder values to be sure you don't have injection problems. Anything else is something you'll need to investigate and verify manually. **Carefully and thoroughly**.
Since ... | This is a better solution right?
```
if(isset($_GET['id']) && $_GET['id'] != null) {
$id = $_GET['id'];
$stmt = $mysqli->prepare("SELECT
maps.id,
maps.name,
maps.description,
maps.date,
maps.mcversion,
maps.mapid,
maps.category,
maps.format,
maps.userid,
users.username,
users.rank,
users.... |
3,283,460 | I want to parse some emails from a user 's inbox but when I do:
```
typ, msg_data = imap_conn.fetch(uid, '(RFC822)')
```
It marks the email as SEEN or read. This is not the desired functionality. Do you know how can I keep the email at its previous stare either SEEN or NOT SEEN? | 2010/07/19 | [
"https://Stackoverflow.com/questions/3283460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1438479/"
] | The following should work:
```
typ, msg_data = imap_conn.fetch(uid, '(BODY.PEEK[HEADER])')
```
or `BODY.PEEK[TEXT]`, etc. | You can use `(RFC822.PEEK)` as the "message-parts" argument, according to [RFC 1730](https://www.rfc-editor.org/rfc/rfc1730.html#section-6.4.5) (I have not verified which servers actually implement that correctly, but it doesn't seem hard for them to). |
3,283,460 | I want to parse some emails from a user 's inbox but when I do:
```
typ, msg_data = imap_conn.fetch(uid, '(RFC822)')
```
It marks the email as SEEN or read. This is not the desired functionality. Do you know how can I keep the email at its previous stare either SEEN or NOT SEEN? | 2010/07/19 | [
"https://Stackoverflow.com/questions/3283460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1438479/"
] | You might also set `read_only` to true when selecting the folder:
```
imap_conn.select('Inbox', readonly=True)
``` | You can use `(RFC822.PEEK)` as the "message-parts" argument, according to [RFC 1730](https://www.rfc-editor.org/rfc/rfc1730.html#section-6.4.5) (I have not verified which servers actually implement that correctly, but it doesn't seem hard for them to). |
3,283,460 | I want to parse some emails from a user 's inbox but when I do:
```
typ, msg_data = imap_conn.fetch(uid, '(RFC822)')
```
It marks the email as SEEN or read. This is not the desired functionality. Do you know how can I keep the email at its previous stare either SEEN or NOT SEEN? | 2010/07/19 | [
"https://Stackoverflow.com/questions/3283460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1438479/"
] | You can use `(RFC822.PEEK)` as the "message-parts" argument, according to [RFC 1730](https://www.rfc-editor.org/rfc/rfc1730.html#section-6.4.5) (I have not verified which servers actually implement that correctly, but it doesn't seem hard for them to). | You may use imap\_tools package:
<https://pypi.org/project/imap-tools/>
```
from imap_tools import MailBox, Q
# get list of email subjects from INBOX folder
with MailBox('imap.mail.com').login('test@mail.com', 'password') as mailbox:
# mark_seen=False - not mark emails as seen on fetch
subjects = [msg.subjec... |
3,283,460 | I want to parse some emails from a user 's inbox but when I do:
```
typ, msg_data = imap_conn.fetch(uid, '(RFC822)')
```
It marks the email as SEEN or read. This is not the desired functionality. Do you know how can I keep the email at its previous stare either SEEN or NOT SEEN? | 2010/07/19 | [
"https://Stackoverflow.com/questions/3283460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1438479/"
] | You might also set `read_only` to true when selecting the folder:
```
imap_conn.select('Inbox', readonly=True)
``` | The following should work:
```
typ, msg_data = imap_conn.fetch(uid, '(BODY.PEEK[HEADER])')
```
or `BODY.PEEK[TEXT]`, etc. |
3,283,460 | I want to parse some emails from a user 's inbox but when I do:
```
typ, msg_data = imap_conn.fetch(uid, '(RFC822)')
```
It marks the email as SEEN or read. This is not the desired functionality. Do you know how can I keep the email at its previous stare either SEEN or NOT SEEN? | 2010/07/19 | [
"https://Stackoverflow.com/questions/3283460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1438479/"
] | The following should work:
```
typ, msg_data = imap_conn.fetch(uid, '(BODY.PEEK[HEADER])')
```
or `BODY.PEEK[TEXT]`, etc. | You may use imap\_tools package:
<https://pypi.org/project/imap-tools/>
```
from imap_tools import MailBox, Q
# get list of email subjects from INBOX folder
with MailBox('imap.mail.com').login('test@mail.com', 'password') as mailbox:
# mark_seen=False - not mark emails as seen on fetch
subjects = [msg.subjec... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.