qid
int64 1
74.7M
| question
stringlengths 0
58.3k
| date
stringlengths 10
10
| metadata
sequence | response_j
stringlengths 2
48.3k
| response_k
stringlengths 2
40.5k
|
---|---|---|---|---|---|
35,739,371 | If multi thread concurrently query the following SQL to a database(postgresql):
```
UPDATE mytable SET n=n+1 WHERE n=0;
```
Whether or not 'n' will finally greater than 1 | 2016/03/02 | [
"https://Stackoverflow.com/questions/35739371",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1044094/"
] | Update will take write lock, so no concurrent operation will actually happen on the table.
```
n will not be greater than 1.
``` | >
> `update mytable set n=n+1 where n=0;`
>
>
> Whether or not 'n' will finally greater than 1
>
>
>
No it will not be "*greater than 1*" because adding `1` to `0` yields `1`.
So `n` will be **equal** to `1`, not "*greater than 1*".
And yes, it is *guaranteed* that all values that were previously 0 (zero) are 1 (one) after the update has finished without an error. |
58,211,116 | I am having an issue where in a website i am working on a form will not run the code when the button is pressed, this litterally worked and i have no idea what changed that broke it.
```
<form action="{{action('Admin\AdminResponsibleController@assign')}}" method="post" id="assignParty">
@csrf
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
email: <input type="text" name="email"><br>
@if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
@endif
@if ($message = Session::get('message'))
<div class="alert alert-warning alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
@endif
<input type="radio" name="party_type" value="responsible" checked>Responsible Party<br>
<input type="radio" name="party_type" value="responsibleTwo"> Second Responsible Party<br>
<input type="radio" name="party_type" value="witness"> Witness <br>
<input type="checkbox" name="remove" value="remove"> Remove Selected Assignment <br>
<input type="hidden" id="userId" name="userId" value="<?php echo $user->id; ?>">
</form>
<button type="submit" form="assignParty" value="Submit">Submit</button>
```
route
```
Route::post('admin/viewPatient/assign', 'Admin\AdminResponsibleController@assign');
```
code that i am trying to run, the dd is for testing, it never even gets there
```
public function assign(Request $request)
{
dd('hit');
if($request->input('userId') != null){
$patient = intval($request->input('userId'));
$patient = User::where('id', $patient)->first();
} /**/
$party = User::where('email', $request->input('email'))
// We want to be sure that Admins and Patients can't be responsible parts, if they need to be we can create another account for them
// Having patients be able to be repsonsible parties would confuse the patient and could lead to buggy code
->first();
if($party != null){
if($party->user_type == 'Admin' || $party->user_type == 'Patient'){
return redirect()->back()->with(['message', 'Can not assign this user']);
}
}
// setup remove user variable as false
$removeUser = false;
// if the email is null, remove user is true
if($request->input('remove') != null){
$removeUser = true;
} else if($request->input('email') == null){
return redirect()->back()->with(['message', 'Please include an email']);
}
// switch case to switch to different statements based on the input of party_type
switch ($request->input('party_type')) {
case 'responsible':
$this->check($request, $party, 'responsible_party', 'Responsible Party', $removeUser, $patient);
break;
case 'responsibleTwo':
$this->check($request, $party, 'responsible_party_two', 'Second Responsible Party', $removeUser, $patient);
break;
case 'financial':
$this->check($request, $party, 'financial', 'Financially Responsible Party', $removeUser, $patient);
break;
case 'legal':
$this->check($request, $party, 'legal', 'Legal Rep', $removeUser, $patient);
break;
case 'witness':
$this->check($request, $party, 'witness', 'Witness', $removeUser, $patient);
break;
default:
// in future versions please include a link to dispatch a support request
// this really shouldn't happen, but a default case should be included in case something somehow goes wrong
throw new \Exception('You must provide a party type.');
break;
}
// return to the view with a message that the party has been assigned
return redirect()->back()->with(['success', 'Party Updated sucessfully']);
}
```
I just updated this post with changes i made to the code | 2019/10/03 | [
"https://Stackoverflow.com/questions/58211116",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11506451/"
] | A solution that worked for me:
**If you are using PHP,** add this line to the beginning
```
header('Set-Cookie: cross-site-cookie=name; SameSite=None; Secure');
```
---
**Update**
Here is a useful resource including examples in JavaScript, Node.js, PHP, and Python
<https://github.com/GoogleChromeLabs/samesite-examples> | Does your .htaccess file contain a header unset cookie code? and you use cdn and its cache like cloudflare.
If so, just delete the code in the htaccess |
58,211,116 | I am having an issue where in a website i am working on a form will not run the code when the button is pressed, this litterally worked and i have no idea what changed that broke it.
```
<form action="{{action('Admin\AdminResponsibleController@assign')}}" method="post" id="assignParty">
@csrf
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
email: <input type="text" name="email"><br>
@if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
@endif
@if ($message = Session::get('message'))
<div class="alert alert-warning alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
@endif
<input type="radio" name="party_type" value="responsible" checked>Responsible Party<br>
<input type="radio" name="party_type" value="responsibleTwo"> Second Responsible Party<br>
<input type="radio" name="party_type" value="witness"> Witness <br>
<input type="checkbox" name="remove" value="remove"> Remove Selected Assignment <br>
<input type="hidden" id="userId" name="userId" value="<?php echo $user->id; ?>">
</form>
<button type="submit" form="assignParty" value="Submit">Submit</button>
```
route
```
Route::post('admin/viewPatient/assign', 'Admin\AdminResponsibleController@assign');
```
code that i am trying to run, the dd is for testing, it never even gets there
```
public function assign(Request $request)
{
dd('hit');
if($request->input('userId') != null){
$patient = intval($request->input('userId'));
$patient = User::where('id', $patient)->first();
} /**/
$party = User::where('email', $request->input('email'))
// We want to be sure that Admins and Patients can't be responsible parts, if they need to be we can create another account for them
// Having patients be able to be repsonsible parties would confuse the patient and could lead to buggy code
->first();
if($party != null){
if($party->user_type == 'Admin' || $party->user_type == 'Patient'){
return redirect()->back()->with(['message', 'Can not assign this user']);
}
}
// setup remove user variable as false
$removeUser = false;
// if the email is null, remove user is true
if($request->input('remove') != null){
$removeUser = true;
} else if($request->input('email') == null){
return redirect()->back()->with(['message', 'Please include an email']);
}
// switch case to switch to different statements based on the input of party_type
switch ($request->input('party_type')) {
case 'responsible':
$this->check($request, $party, 'responsible_party', 'Responsible Party', $removeUser, $patient);
break;
case 'responsibleTwo':
$this->check($request, $party, 'responsible_party_two', 'Second Responsible Party', $removeUser, $patient);
break;
case 'financial':
$this->check($request, $party, 'financial', 'Financially Responsible Party', $removeUser, $patient);
break;
case 'legal':
$this->check($request, $party, 'legal', 'Legal Rep', $removeUser, $patient);
break;
case 'witness':
$this->check($request, $party, 'witness', 'Witness', $removeUser, $patient);
break;
default:
// in future versions please include a link to dispatch a support request
// this really shouldn't happen, but a default case should be included in case something somehow goes wrong
throw new \Exception('You must provide a party type.');
break;
}
// return to the view with a message that the party has been assigned
return redirect()->back()->with(['success', 'Party Updated sucessfully']);
}
```
I just updated this post with changes i made to the code | 2019/10/03 | [
"https://Stackoverflow.com/questions/58211116",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11506451/"
] | There's nothing you can do until Google's developers/admins (and developers/admins of other external resources) modify their scripts/servers to include the necessary cookies settings to the cookies they generate when your website includes them. See here more more info:
<https://github.com/GoogleChromeLabs/samesite-examples/issues/4#issuecomment-548598318>
If you are debugging your website, you can temporarily ignore those entries in Chrome's developer tools console by adding this filter to the filter box:
`-SameSite=None`
For example:
[](https://i.stack.imgur.com/2Ythl.png) | Does your .htaccess file contain a header unset cookie code? and you use cdn and its cache like cloudflare.
If so, just delete the code in the htaccess |
58,211,116 | I am having an issue where in a website i am working on a form will not run the code when the button is pressed, this litterally worked and i have no idea what changed that broke it.
```
<form action="{{action('Admin\AdminResponsibleController@assign')}}" method="post" id="assignParty">
@csrf
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
email: <input type="text" name="email"><br>
@if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
@endif
@if ($message = Session::get('message'))
<div class="alert alert-warning alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
@endif
<input type="radio" name="party_type" value="responsible" checked>Responsible Party<br>
<input type="radio" name="party_type" value="responsibleTwo"> Second Responsible Party<br>
<input type="radio" name="party_type" value="witness"> Witness <br>
<input type="checkbox" name="remove" value="remove"> Remove Selected Assignment <br>
<input type="hidden" id="userId" name="userId" value="<?php echo $user->id; ?>">
</form>
<button type="submit" form="assignParty" value="Submit">Submit</button>
```
route
```
Route::post('admin/viewPatient/assign', 'Admin\AdminResponsibleController@assign');
```
code that i am trying to run, the dd is for testing, it never even gets there
```
public function assign(Request $request)
{
dd('hit');
if($request->input('userId') != null){
$patient = intval($request->input('userId'));
$patient = User::where('id', $patient)->first();
} /**/
$party = User::where('email', $request->input('email'))
// We want to be sure that Admins and Patients can't be responsible parts, if they need to be we can create another account for them
// Having patients be able to be repsonsible parties would confuse the patient and could lead to buggy code
->first();
if($party != null){
if($party->user_type == 'Admin' || $party->user_type == 'Patient'){
return redirect()->back()->with(['message', 'Can not assign this user']);
}
}
// setup remove user variable as false
$removeUser = false;
// if the email is null, remove user is true
if($request->input('remove') != null){
$removeUser = true;
} else if($request->input('email') == null){
return redirect()->back()->with(['message', 'Please include an email']);
}
// switch case to switch to different statements based on the input of party_type
switch ($request->input('party_type')) {
case 'responsible':
$this->check($request, $party, 'responsible_party', 'Responsible Party', $removeUser, $patient);
break;
case 'responsibleTwo':
$this->check($request, $party, 'responsible_party_two', 'Second Responsible Party', $removeUser, $patient);
break;
case 'financial':
$this->check($request, $party, 'financial', 'Financially Responsible Party', $removeUser, $patient);
break;
case 'legal':
$this->check($request, $party, 'legal', 'Legal Rep', $removeUser, $patient);
break;
case 'witness':
$this->check($request, $party, 'witness', 'Witness', $removeUser, $patient);
break;
default:
// in future versions please include a link to dispatch a support request
// this really shouldn't happen, but a default case should be included in case something somehow goes wrong
throw new \Exception('You must provide a party type.');
break;
}
// return to the view with a message that the party has been assigned
return redirect()->back()->with(['success', 'Party Updated sucessfully']);
}
```
I just updated this post with changes i made to the code | 2019/10/03 | [
"https://Stackoverflow.com/questions/58211116",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11506451/"
] | A solution that worked for me:
**If you are using PHP,** add this line to the beginning
```
header('Set-Cookie: cross-site-cookie=name; SameSite=None; Secure');
```
---
**Update**
Here is a useful resource including examples in JavaScript, Node.js, PHP, and Python
<https://github.com/GoogleChromeLabs/samesite-examples> | There's nothing you can do until Google's developers/admins (and developers/admins of other external resources) modify their scripts/servers to include the necessary cookies settings to the cookies they generate when your website includes them. See here more more info:
<https://github.com/GoogleChromeLabs/samesite-examples/issues/4#issuecomment-548598318>
If you are debugging your website, you can temporarily ignore those entries in Chrome's developer tools console by adding this filter to the filter box:
`-SameSite=None`
For example:
[](https://i.stack.imgur.com/2Ythl.png) |
36,973 | I was trying to look up some locked posts to check on because of the recent feature requests, and saw that there was no **islocked:1** option.
This would help complete the set of advanced search options. | 2010/01/25 | [
"https://meta.stackexchange.com/questions/36973",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/13295/"
] | In case that isn't implemented, for whatever reason, you can find out if a post has ever been locked by [using the following Google Search](http://www.google.com/search?hl=en&q=site%3Astackoverflow.com+%22Post+locked+by%22&aq=f&aql=&aqi=&oq=&cad=h):
```
site:stackoverflow.com "Post locked by" -migrated
```
Type that into Google. The `-migrated` allows you to omit posts with the word 'migrated' in them (for those posts that are locked due to migration).
You can also try "`Locked By Jeff Atwood`" (or any of the moderator Names) to see ones that may slip through, but this should catch most of them. | This got implemented a while back when we switched over to using Elasticsearch.
To search for locked posts, use `locked:1`. |
225 | In particular, I don't mean mere alternate spellings like *colour*, *honour*, but words that are entirely different: using *lift* instead of *elevator*, *fridge* instead of *refrigerator* etc.
What is the common outlook on using them in plain informal speech in the US? What are the chances they won't be recognized at all? Will they be seen as pretentious? Weird? Unwelcome? | 2013/01/24 | [
"https://ell.stackexchange.com/questions/225",
"https://ell.stackexchange.com",
"https://ell.stackexchange.com/users/30/"
] | AFAIK *most* Americans know the British equivalents for their words, and vice versa.
Some people even use them (some Britons use the American words). It wouldn't be considered weird - an American would just assume you were British, or learnt British English. It wouldn't be considered unwelcome either, by the vast majority of Americans. | I think there is a chance that some of the less common words would not be recognised at all between the AmE and BritE, but it does depend on what sphere the words are from.
The common ones are fairly well known, others not so:
From cars:
Trunk, boot. Hood, bonnet. Rocker panel, sill etc
From culinary:
Bitter sweet chocolate, plain chocolate. Tomato sauce, crushed tomatoes. Tomato paste, tomato puree. Cilantro, coriander.
And so on. |
225 | In particular, I don't mean mere alternate spellings like *colour*, *honour*, but words that are entirely different: using *lift* instead of *elevator*, *fridge* instead of *refrigerator* etc.
What is the common outlook on using them in plain informal speech in the US? What are the chances they won't be recognized at all? Will they be seen as pretentious? Weird? Unwelcome? | 2013/01/24 | [
"https://ell.stackexchange.com/questions/225",
"https://ell.stackexchange.com",
"https://ell.stackexchange.com/users/30/"
] | AFAIK *most* Americans know the British equivalents for their words, and vice versa.
Some people even use them (some Britons use the American words). It wouldn't be considered weird - an American would just assume you were British, or learnt British English. It wouldn't be considered unwelcome either, by the vast majority of Americans. | In general, I would say no, but there are some exceptions. The first time I encountered a sign in a public place saying "toilet," I felt it was quite crude. Americans would only use that word for the actual fixture, preferring restroom for such contexts. |
225 | In particular, I don't mean mere alternate spellings like *colour*, *honour*, but words that are entirely different: using *lift* instead of *elevator*, *fridge* instead of *refrigerator* etc.
What is the common outlook on using them in plain informal speech in the US? What are the chances they won't be recognized at all? Will they be seen as pretentious? Weird? Unwelcome? | 2013/01/24 | [
"https://ell.stackexchange.com/questions/225",
"https://ell.stackexchange.com",
"https://ell.stackexchange.com/users/30/"
] | I think there is a chance that some of the less common words would not be recognised at all between the AmE and BritE, but it does depend on what sphere the words are from.
The common ones are fairly well known, others not so:
From cars:
Trunk, boot. Hood, bonnet. Rocker panel, sill etc
From culinary:
Bitter sweet chocolate, plain chocolate. Tomato sauce, crushed tomatoes. Tomato paste, tomato puree. Cilantro, coriander.
And so on. | In general, I would say no, but there are some exceptions. The first time I encountered a sign in a public place saying "toilet," I felt it was quite crude. Americans would only use that word for the actual fixture, preferring restroom for such contexts. |
57,778,576 | ```
this.setState({
object1: { ...object2 },
});
```
I know it does something to the state. but I'm not able to understand what it means? Is this a technique in JS/React? | 2019/09/03 | [
"https://Stackoverflow.com/questions/57778576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12016641/"
] | You are essentially setting `object1` to be the same as `object2` via [spread syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#Syntax). For example:
```
this.state = { object1: { hello: 'world' } };
const object2 = { foo: 'bar' };
this.setState({ object1: { ...object2 } });
```
this would result in the state to be:
```
{ object1: { foo: 'bar' };
``` | This is spread operator and you can read more about it here
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#Spread_in_object_literals>[enter link description here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#Spread_in_object_literals)
The setState in your code is updating the current state variable object1 with the values from object2 |
53,577,333 | ```
<html>
<body>
<div class = "container">
<audio id="music" src="/music/orgmusic.mp3"type="audio/mpeg"></audio>
<img id="titleimg"src = "images/titleimage.png">
<div class = "gameContainer">
</div>
<div id ="play">Press Spacebar To Return To Main Menu!</div>
</div>
<link rel="stylesheet" type="text/css" href="/css/setup.css">
<link rel="stylesheet" type="text/css" href="/css/global.css">
<script src="/JS/setup.js" type="text/javascript"></script>
<script src="/JS/global.js" type="text/javascript"></script>
</body>
</html>
```
JS FILE:
```
document.getElementById("gameContainer").innerHTML = "hi this is words";
```
As you can see i have the in-line script set to insert text into my div called "gameContainer" but for some reason it doesn't work.
I know I can just type it in, but I wan't to get it to work through my JS file.
Any ideas on why the text won't insert? | 2018/12/02 | [
"https://Stackoverflow.com/questions/53577333",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10411317/"
] | You are do stuff based on Id and you set class in HTML.
```
<div class = "gameContainer"> // Hear you used class
</div>
```
In Js you used `document.getElementById("gameContainer").innerHTML`
```
<div id="gameContainer"> // Hear you have to used id instead of class
</div>
``` | ```js
document.getElementById("gameContainer").innerHTML = "hi this is words";
```
```html
<html>
<body>
<div class = "container">
<audio id="music" src="/music/orgmusic.mp3"type="audio/mpeg"></audio>
<img id="titleimg"src = "images/titleimage.png">
<div id = "gameContainer"class = "gameContainer">
</div>
<div id ="play">Press Spacebar To Return To Main Menu!</div>
</div>
<link rel="stylesheet" type="text/css" href="/css/setup.css">
<link rel="stylesheet" type="text/css" href="/css/global.css">
<script src="/JS/setup.js" type="text/javascript"></script>
<script src="/JS/global.js" type="text/javascript"></script>
</body>
</html>
``` |
547,765 | Let us assume that we have constructed a $G$-principal bundle $P$ over the manifold $M$ (for a curved space-time this is a $GL$-bundle, for a gauge theory I take $U(1)$ = electrodynamics) and the corresponding associated bundle $P\_F$ with a typical fibre $F$ being a vector space.
1) At first, I am confused about the meaning of a local section $\sigma: U \rightarrow P$ on the principal bundle, where $U \subset M$. I understand it as assigning some "point of reference" with respect to $G$ to the corresponding point in $M$. This can be seen by the induced local trivialization which sets $\sigma(x) = (x, e)$ so that the section always corresponds to a neutral element of $G$. The associated bundle $P\_F$ is constructed as the set of equivalence classes of $P \times F$ with respect to the equivalence relation $(p, f) \sim (pg, g^{-1}f)$, which means that the simultaneous transformation of the basis and the components does not change the vector. Then the section $\sigma$ fixes a representative in each equivalence class in $P \times F$, and this is interpreted as fixing the frame/gauge, is this correct?
2) If so, how does a section on the associated bundle $\psi: U \rightarrow P\_F$, which is some matter field for the gauge $U(1)$-bundle $P$, look like? If I assume that $\sigma$ picks up different elements of $U(1)$, does it mean that $\psi (x)$ has different phases when I go through $U$ so that I have something like $\psi(x) e^{i \theta(x)}$? For me this sounds like a mistake because this is already a gauge transformation since the phase $\theta$ depends on the point on the manifold.
3) The connection form $\omega$ acts on the tangent to $G$ components of a tangent vector $X\_p$ on the principle bundle. What is the intuition behind tangent vectors in $P$?
4) Furthermore, the connection form gives a separation of tangent spaces in $P$ into the vertical and horizontal spaces, which I see intuitively as "parallel" to $G$ and $M$, correspondingly. Since I lack intuition for this choice and its relation to the local sections on $P$ I would like to consider the following example. Let us consider a flat 2-dimensional manifold with a unique chart with polar coordinates which correspond (?) to some section $\sigma$ in $P = LM$. Will it be correct to say that taking horizontal spaces $H\_p P$ in such a way that tangent vectors to $\sigma(x)$ always lie in $H\_p P$ means that the parallel transport of the vectors will consist in projecting the vectors to the coordinate lines during the transport, so that the corresponding connection coefficients are zero? | 2020/04/29 | [
"https://physics.stackexchange.com/questions/547765",
"https://physics.stackexchange.com",
"https://physics.stackexchange.com/users/235936/"
] | There are too many questions to answer in one go. I'll address the questions of sections of associated bundles and gauge choices.
Let's work in a local patch in $P$ with coordinates $(x,g)$ such that $\pi:P\to M$ is $\pi(x,g)=x$.
We want a section of an associated bundle $P\_V= P\times \_G V$ where $V$ is a representation of $G$ under which a vector with components $\varphi\_i$ transforms as $g: \varphi\_i \mapsto D\_{ij}(g) \varphi\_j$.
I like to think of such a section as a $V$ valued function $\varphi\_i(x,g)$ on the total space $P$ that obeys
$$
\varphi\_i(x,gh)= D\_{ij}(h^{-1})\varphi\_j(x,g).
$$
This defines the section in *all gauges at once*. A gauge choice is given by selecting a $g(x)$ for each point $x$ in the base space so that
$$
\varphi\_i(x,g(x)\equiv \varphi\_i(x)
$$
is the usual (gauge chosen) matter field.
Note that we have to have an $h^{-1}$ for consistency
$$
\varphi\_i(x,gh\_1h\_2)=D\_{ij}(h\_2^{-1})\varphi\_j(x,gh\_1)\\ =D\_{ij}(h\_2^{-1})D\_{jk}(h\_1^{-1})\varphi\_k(x,g)\\
= D\_{ik}(h\_2^{-1}h\_1^{-1})\varphi\_k(x,g)\\
= D\_{ik}((h\_1h\_2)^{-1})\varphi\_k(x,g).
$$
Covariant derivatives $\nabla\_\mu$ are now directional derivatives on the total space $P$ that lie in the horizontal subspace at each $(x,g)$ and project down to $\partial\_\mu$ on the basespace $M$. | >
> Then the section $\sigma$ fixes a representative in each equivalence class in $P\times F$, and this is interpreted as fixing the frame/gauge, is this correct?
>
>
>
Yes. You can also think of $P$ as a collection of all (abstract) reference frames of a given type over all spacetime points. A local section of $P$ is a choice of reference frames over the region it is defined on.
Here reference frame is meant in the abstract sense, since 1) for any associated vector bundle it serves as the vector bundle's own local frame field, 2) it provides a "local frame" for nonlinear associated bundles as well, yet the usual concept of local frame fields is meaningful only for vector bundles.
>
> If so, how does a section on the associated bundle look like?
>
>
>
The thing is, it does not look like at all. A local section $\psi:U\rightarrow P\_F$ associates to an $x\in M$ an element of $P\_F=P\times\_GF$ at the fibre above $x$.
The fibre $(P\_F)\_x$ consists of equivalence classes $[(p\_x,v)]$, where $p\_x\in P\_x$ is a "frame" at $x$, and $v\in F$ is a vector in the typical fibre, with pairs $(p\_x,v)$ and $(p^\prime\_x,v^\prime)$ being equivalent if $p^\prime\_x=p\_xg$ and $v^\prime=g^{-1}v$.
So the value $\psi(x)$ at $x$ not really an object in the usual sense, but an entire equivalence class.
If you have a local section $\sigma$ defined in a neighborhood of $U$, then $\sigma$ identifies $P\_x$ with $G$ by writing $p\_x=\sigma(x)g$, and then $p\_x\sim g$, and it identifies the fibre $(P\_F)\_x$ with $F$ by mapping the class $[(p\_x,v)]=[(\sigma(x)g,v)]=[(\sigma(x),gv)]$ to the element $gv\in F$.
This allows us to construct a map $\bar\psi:U\rightarrow F$ by mapping $x$ to $gv$, which is the local representative of $\psi$, one that takes values in "concrete" objects, rather than abstract equivalence classes.
There is a more intuitive way to look at this however. It is known (see Kobayashi/Nomizu for more details, by the notation I assume OP is reading Bleecker, and he doesn't go into this a lot) that the set of all sections of $P\_F$ is in one-to-one correspondance with maps $P\rightarrow F$ that are equivariant, i.e. $f(pg)=g^{-1}f(p)$.
Suppose that $f\_\psi$ is this map corresponding to your section $\psi$. The correspondance is that (above $x\in M$ for simplicity) $\psi(x)=[(p\_x,f\_\psi(p\_x))]$. Then if $\sigma$ is a local section of $P$, then simply $$ \bar\psi(x)=f\_\psi(\sigma(x)). $$
>
> What is the intuition behind tangent vectors in $P$?
>
>
>
This question is rather ambigous, but here is what can be said. We have for any $p\in P$ the vertical space $V\_pP<T\_pP$. An important property of principal bundles is that $V\_pP\cong \mathfrak g$ for all $p\in P$. The connection form is a vertical projection, i.e. it projects a tangent vector on $P$ at $p\in P$ into $V\_pP$, but then it also identifies it with an element of $\mathfrak g$ via this isomorphism.
>
> Will it be correct to say that...
>
>
>
If I understand what is written correctly, then yes. If a local section $\sigma:U\rightarrow P$ exists so that $T\_x\sigma(T\_xM)\le H\_{\sigma(x)}P$, then the pullback of the conenction form along $\sigma$ (which is the local representative of the connection form on the base space) vanishes, and the connection is flat.
The curvature can be seen as the obstruction to the Frobenius integrability of the horizontal tangent distribution, and these "horizontal sections" $\sigma$ essentially exist locally if and only if the horizontal distribution is Frobenius integrable and thus the curvature vanishes. |
1,638,552 | There are three events: $A$ and $B$ and $C$. We know $P(A|B) = P(B|C) = 0.5$. Then
$P(A|C)$ should be?
Is it $0.5\cdot0.5=0.25$?
The question only provide the above information and the question provide the following choices.
$a. 0.25$
$b. 0.5$
$c. 1$
$d. 0$
$e.$ None of the above is correct | 2016/02/03 | [
"https://math.stackexchange.com/questions/1638552",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/109403/"
] | Why should you be able to tell? You only know how $A$ behaves in the presence of $B$, and how $B$ behaves in the presence of $C$. How could you possibly deduce how $A$ behaves in the presence of $C$, regardless of the presence or absence of $B$?
Examples to show that you can't:
If the events are all independent, then $\mathbb{P}(A \vert C) = \mathbb{P}(A) = \frac{1}{2}$.
If the event $C$ is independent of the others, then $\mathbb{P}(A \vert B) = \mathbb{P}(B) = \frac{1}{2}$, but $\mathbb{P}(A \vert C) = \mathbb{P}(A)$ need not be $\frac{1}{2}$: let $B$ be the event "I get heads on the first of two coins" and $A$ be the event "I get heads on both of the two coins". | You should know at least the probability of the single events to tell. If you'd know you could apply the *Bayes* theorem and solve. |
70,930,865 | I need to transform the following input table to the output table where output table will have ranges instead of per day data.
Input:
```
Asin day is_instock
--------------------
A1 1 0
A1 2 0
A1 3 1
A1 4 1
A1 5 0
A2 3 0
A2 4 0
```
Output:
```
asin start_day end_day is_instock
---------------------------------
A1 1 2 0
A1 3 4 1
A1 5 5 0
A2 3 4 0
``` | 2022/01/31 | [
"https://Stackoverflow.com/questions/70930865",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8538910/"
] | This is what is referred to as the "gaps and islands" problem. There's a fair amount of articles and references you can find if you use that search term.
Solution below:
```
/*Data setup*/
DROP TABLE IF EXISTS #Stock
CREATE TABLE #Stock ([Asin] Char(2),[day] int,is_instock bit)
INSERT INTO #Stock
VALUES
('A1',1,0)
,('A1',2,0)
,('A1',3,1)
,('A1',4,1)
,('A1',5,0)
,('A2',3,0)
,('A2',4,0);
/*Solution*/
WITH cte_Prev AS (
SELECT *
/*Compare previous day's stock status with current row's status. Every time it changes, return 1*/
,StockStatusChange = CASE WHEN is_instock = LAG(is_instock) OVER (PARTITION BY [Asin] ORDER BY [day]) THEN 0 ELSE 1 END
FROM #Stock
)
,cte_Groups AS (
/*Cumulative sum so everytime stock status changes, add 1 from StockStatusChange to begin the next group*/
SELECT GroupID = SUM(StockStatusChange) OVER (PARTITION BY [Asin] ORDER BY [day])
,*
FROM cte_Prev
)
SELECT [Asin]
,start_day = MIN([day])
,end_day = MAX([day])
,is_instock
FROM cte_Groups
GROUP BY [Asin],GroupID,is_instock
``` | You are looking for an operator described in the temporal data literature, and "best known" as PACK.
This operator was not made part of the SQL standard (SQL:2011) that introduced the temporal features of the literature into the language, so there's extremely little chance you're going to find anything to support you in any SQL product/dialect.
Boils down to : you'll have to write out the algorithm to do the PACKing yourself. |
1,551,746 | I'm having some trouble with a problem in linear algebra:
Let $A$ be a matrix with dimensions $m \times n$ and $B$ also a matrix but with dimensions $n \times m$ which is **not** a null matrix. (That's all that's written - I assume A may or may not be a null matrix).
Given that $AB=0$:
1. Prove there is a non-trivial solution to the system of equations $Ax=0$
2. Assume $A\neq0$ . Does the system $Bx=0$ also have a non-trivial solution? If so, prove the argument. If not, provide a contradictory example.
There's a third part to the question but I managed to solve it and its content isn't really relevant here because it provided us a defined $A$ of real numbers, but I'm pretty lost with the first two arguments - I'm having trouble putting what I think into words. Can anyone help with this? Thanks!
EDIT:
Okay so I think I'm supposed to deal with the different cases of $m$ and $n$:
If $n > m$ obviously the system $Ax=0$ has infinite solutions because we'll have more variables than equations.
What I haven't quite figured out is how to prove that:
If $AB=0$ and $m=n$ or $m > n$, then it immediately follows that $Rank(A) < n$ .
Any help with this would be greatly appreciated. | 2015/11/29 | [
"https://math.stackexchange.com/questions/1551746",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/281986/"
] | Solved it.
1. If $AB=0$ that means that matrix $A$ multiplied by any column vector $b$ in $B$ will be equal to the zero vector. Since we know that $B\neq 0$, there must be at least one column vector $b$ in $B$ that **isn't** the zero vector. So to summarize, since $A$ multiplied by any column vector in $B$ returns 0 and we know there is a non-zero column vector in $B$, the system of equations $Ax=0$ has at least one non-trivial solution, where $x$ can be the zero vector or a non-zero vector from $B$.
2. I have found a contradictory example. Basically to disprove the argument I need to find matrices $A,B$ that meet the following criteria:
* $A\_{m\times n}, B\_{n\times m}$
* $A,B\neq0$
* $Bx=0$ **only** has a trivial solution
Here they are:
$$
A=\begin{bmatrix}
0&0&0&1\\
0&0&0&0\\
0&0&0&0
\end{bmatrix}\_{3\times 4}\ ,\
B=
\begin{bmatrix}
1&0&0\\
0&1&0\\
0&0&1\\
0&0&0
\end{bmatrix}
\\
$$
$$
A\_{m\times n}, B\_{n\times m}\ \ \checkmark
\\
A,B\neq 0\ \ \checkmark
\\
AB=0\ \ \checkmark
\\
Bx=0\rightarrow\ one\ solution\ \ \checkmark
$$
And there's a perfect contradictory example to the argument. | 1. A has to be linearly dependent, since it is the case that $AB = 0$. If B is not the zero matrix, then it has to be the case that there is some row of $A$ in Reduce Row Echelon Form that is a zero row. Because of this, it is linearly dependent. It therefore does not matter if $A$ is the zero matrix or not, since the result is the same. By definition, a linearly dependent matrix has non-trivial solutions to $Ax=0$ (since its nullspace is not $\{0\})$. |
13,927,782 | I have a gridview. its data source is a datatable that is loaded from the database. In this gridview, i have a template column.
```
<asp:TemplateField HeaderText="Product Type" SortExpression="ProductID">
<ItemStyle CssClass="MP-table-tb-display-item" />
<ItemTemplate>
<div class="MP-table-tb-display-main">
<asp:LinkButton ID="lnkview" CommandArgument='<%# Eval("ProductID") %>' CommandName="Viewproduct"
runat="server" CausesValidation="False" OnClick="lnkview_Click"><h4>
<%# Eval("Name") %>
</h4>
</asp:LinkButton>
</div>
<br />
<div class="MP-table-tb-display">
<p>
<span>KEY</span><%# Eval("[product_type_key]") %></p>
<br />
<a target="_blank" href='<%# Eval("SourceURL") %>'>Source</a>
</div>
</ItemTemplate>
</asp:TemplateField>
```
In this I want Source hyperlink only show when data available into `<%# Eval("SourceURL") %>`. If I am not able to get the SourceURL value into `RowDatabound Event` . Please Guide me.
I plan for this too but this is not working properly.
```
<a target="_blank" href=' <%= Eval("SourceURL")!=null ? Eval("SourceURL") : "style='display: none'" %> />'> Source</a>
``` | 2012/12/18 | [
"https://Stackoverflow.com/questions/13927782",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/869233/"
] | use this instead
```
<asp:hyperlink Target="_blank" NavigateUrl='<%# Eval("SourceURL") %>' Visible = '<%# Eval("SourceURL") == null ? false : true %>' >
```
Similarly you could use the `<a>` tag to control its visiblity. The if condition would go in Style attribue and not in href attribute. Something like this
```
Style=display:Eval('some_val') == null ? none : block
``` | Try this :
```
<a target="_blank" href='<%#(String.IsNullOrEmpty(Eval("SourceURL").ToString()) ? "" : Eval("SourceURL"))'%> style='display: none'>Source</a>
```
Thanks |
44,660,534 | I have data in this form
```
V1 V2
1 6 1
2 6 5
3 1 0
4 1 6
5 1 385
6 5 4
7 5 6
8 5 98
9 0 1
10 0 2
```
and I want to convert it into
```
V1 V2 V3 V4
1 6 1 5
2 1 0 6 385
3 5 4 6 98
4 0 1 2
```
any suggestions to do it into r | 2017/06/20 | [
"https://Stackoverflow.com/questions/44660534",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8190198/"
] | There are a couple of ways of answering this.
We say that a pointer value is the address of a memory location. But different computers have used different addressing schemes for memory. C is a higher-level language, portable across many kinds of computers. C does not mandate a particular memory architecture. As far as the C programming language is concerned, memory addresses could literally be things like "123 Fourth Ave.", and it's hard to imagine converting back and forth between an integer and an address like that.
Now, for any machine you're likely to use, memory is actually linearly addressed in a reasonably straightforward and unsurprising way. If your program has 1,000 bytes of memory available to it, the addresses of those bytes might range from 0 up to 999. So if you say
```
char *cp = (char *)10;
```
you're just setting up a pointer to the byte located at address 10 (or, that is, the 11th byte in your program's address space).
Now, in C, a pointer is not just the raw address of some location in memory. In C, a pointer is also declared to specify what type of data it points to. So if we say
```
int *ip = (int *)10;
```
we're setting up a pointer to one int's worth of data located at address 10. It's the same point in memory as `cp` pointed to, but since it's an int pointer, it's going to access an int's worth of bytes, not one byte like `cp` did. If we're on an old 16-bit machine, and int is two bytes, we could think of `ip` as pointing at the fifth int in our address space.
A cast in C can actually do two things: (1) convert a value ("change the bits"), or (2) change the interpretation of a value. If we say `float f = (float)3;`, we're converting between the integer representation of 3 and a floating-point representation of 3, which is likely to be quite different. If we go in the other direction, with something like `int i = (int)3.14;`, we're also throwing away the fractional part, so there's even more conversion going on. But if we say `int *ip = (int *)10;`, we're not really doing anything with the value 10, we're just reinterpreting it as a pointer. And if we say `char *cp = (char *)ip`, we're again not changing anything, we're just reinterpreting to a different kind of pointer.
I hasten to add, though, that everything I've said here about pointer conversions is (a) very low-level and machine-dependent, and (b) not the sort of thing that ordinary C programmers are supposed to have to think about during ordinary programming tasks, and (c) not guaranteed by the C language.
In particular, even when programming for a computer with a conventional, linearly-addressed memory model, it's likely that your program doesn't have access to address 10, so these pointers (`cp` and `ip`) might be pretty useless, might generate exceptions if you try to use them. (Also, when we have a pointer like `ip` that points at more than 1 byte, there's the question of which bytes it points to. If `ip` is 10, it probably points at bytes 10 and 11 on a 16-bit, byte-addressed machine, but which of those two bytes is the low-order half of the int and which is the high-order half? It depends on whether it's a "big endian" or "little endian" machine.)
But then we come to null pointers. When you use a constant "0" as a pointer value, things are a little different. If you say
```
void *p = (void *)0;
```
you are not, strictly speaking, saying "make `p` point to address `0`". Instead, you are saying "make `p` be a null pointer". But it turns out this has nothing to do with the cast, it's because of a special case in the language: in a pointer context, the constant 0 represents a *null pointer constant*.
A null pointer is a special pointer value that's defined to point nowhere. It might be represented internally as a pointer to address 0, or it might be represented some other way. (If it is in fact represented as a pointer to address 0, your compiler will be careful to arrange that there's never any actual data at address 0, so that it's still true that the pointer "points nowhere" even though it points to address 0. This is sort of confusing, sorry about that.)
Although pointers to raw addresses like `10` are low-level and dangerous and machine-dependent, null pointers are well-defined and perfectly fine. For example, when you call `malloc` and it can't give you the memory you asked for, it returns a null pointer to tell you so. When you test `malloc`'s return value to see if it succeeded or failed, you just check to see if it gave you a null pointer or not, and there's nothing low-level or nonportable or discouraged about doing so.
See <http://c-faq.com/null/index.html> for much more on all this. | A pointer is a short arrangement of bytes. Via a cast, C allows to pretend these bytes represent an integer.
```
Type* p = ...;
intptr_t i = (intptr_t)p;
```
This is occasionally (but rarely) useful when you need to pass a pointer to an interface expecting an integer. To recover the pointer, one just reverses the cast.
```
Type* recovered_p = (Type*)i;
```
This does not allocate any memory. You can only deference `recovered_p` if `i` contain bytes that, if treated as a `Type*`, references a previously allocated `Type` value. This means that the following doesn't produce a usable pointer:
```
int *p = (int*)10;
```
---
An example that uses an integer to store a pointer.
```
typedef void (*Visitor)(intptr_t, ListNode*);
void List_visit(List* list, Visitor visitor, intptr_t arg) {
for (ListNode* node = list->head; node; node=node->next) {
visitor(arg, node);
}
}
void printer(intptr_t arg, ListNode* node) {
State* state = (intptr_t)arg;
printf("%*s%s\n", ( state->count++ )*2, "", node->value);
}
int main(void) {
List* list = ...;
State* state = ...;
List_visit(list, printer, (intptr_t)state);
List_free(list);
State_free(state);
return 0;
}
``` |
16,881,529 | ```
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style>
.square
{
width: 200px;
height:200px;
background-color:#F99;
}
#myimage {
position: absolute;
top: 0;
left: 0;
z-index: 10;
}
.table
{
position:relative;
margin-top:80px;
}
</style>
<script>
cc=1;
function changeimage()
{
if (cc==0)
{
cc=1;
document.getElementById('myimage').src="images/white_contact.png";
}
else if (cc==1)
{
cc=2;
document.getElementById('myimage').src="images/yellow_contact.png";
}
else if (cc==2)
{
cc=3;
document.getElementById('myimage').src="images/red_contact.png";
}
else
{
cc=0;
document.getElementById('myimage').src="images/green_contact.png";
}
}
</script>
</head>
<body>
<div class = "square">
<table border="0" class = "table" ><tr>
<td width="51">Name:</td>
<td width="141"><input type="text" size="10"></td>
</tr>
<tr>
<td>Title:</td>
<td><input type="text" size="10"></td>
</tr>
<tr>
<td>Contact:</td>
<td><input type="text" size="10"></td>
</tr>
</table>
</div>
<img id="myimage" onclick="changeimage()" border="0" src="images/white_contact.png" width="70" />
<p>Click to turn on/off the light</p>
</body>
</html>
```
This is my code, I want to position my Table on the BOTTOM of my pink box, so that it would not be block by the image, no matter how hard I try to adjust my CSS, it seem to be at the bottom
What should I do? Help me. | 2013/06/02 | [
"https://Stackoverflow.com/questions/16881529",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2399158/"
] | I have a solution for your problem. You can use
```
android:layout_centerInParent="true".
```
But it will make your "Total Amount" TextView in center. But you want You last character touch the center point. So you can make another "Blank TextView" and place it on center using centerInparent and then put your "TotalAmount" textview to its left.
```
<TextView
android:id="@+id/blank_centered_text"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView
android:id="@+id/textViewTotalAmtVal"
style="@style/ButtonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
**android:layout_toLeftOf="@+id/blank_centered_text"**
android:text="Total Amount: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#2E2E2E"
android:textStyle="bold" />
``` | You can do it use `LinearLayout` in `RelativeLayout` and then each of your Element (ie. `Button`& `TextView`) can use `layout_weight` property.
```
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Tour_Expense_List_Detail_Tbl">
<LinearLayout
android:id="@+id/Row1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/saveButton"
style="@style/ButtonText"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:background="@drawable/color_button"
android:onClick="SaveData"
android:text="Save"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewTotalAmtVal"
style="@style/ButtonText"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_weight="1"
android:text="Total Amount: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#2E2E2E"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
``` |
1,105,132 | I have a list of check boxes. For the check boxes that are selected, I change it's name before submitting. In FF the function works. In IE I get:
>
> A script on this page is causing Internet Explorer to run slowly. If it
> continues to run, your computer may
> become unresponsive.
>
>
> Do you want to abort the script? YES/NO
>
>
>
Not sure why this loop is causing problems in IE and not FF?
```
function sub()
{
var x=document.getElementsByName("user");
for (i = 0; i < x.length; i++) //for all check boxes
{
if (x[i].checked == true)
{
x[i].name="id"; //change name of data so we know it is for an id
//By renaming the first element of the list, we have reduced the length of the list by one
//and deleted the first element. This is why we need to keep i at it's current position after a name change.
i=i-1;
}
}//end for
document.checks.submit();
}
``` | 2009/07/09 | [
"https://Stackoverflow.com/questions/1105132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/52256/"
] | Internet Explorer is buggy. It doesn't return a live nodelist but just a snapshot.
Using a framework such as jQuery is your best bet in achieving full compatibility. | Edit: This is wrong, Nick is right. Although I'd look extra hard to make sure IE actually implements the NodeList correctly, since it still sounds like what you're running into is an infinite loop in IE.
Thanks for the heads up, Nick, I learned something new today. Javascript never ceases to surprise me :)
---
Just renaming an element in the array would not remove it from the array -- getElementsByName is not run constantly, just the initial time that it is called. So IE is stuck in an infinite loop where it keeps checking the same checked element over and over. I'm honestly not sure why Firefox doesn't also get stuck in the same infinite loop.
As far as I understand, the `i=i-1` line is entirely unnecessary. |
1,105,132 | I have a list of check boxes. For the check boxes that are selected, I change it's name before submitting. In FF the function works. In IE I get:
>
> A script on this page is causing Internet Explorer to run slowly. If it
> continues to run, your computer may
> become unresponsive.
>
>
> Do you want to abort the script? YES/NO
>
>
>
Not sure why this loop is causing problems in IE and not FF?
```
function sub()
{
var x=document.getElementsByName("user");
for (i = 0; i < x.length; i++) //for all check boxes
{
if (x[i].checked == true)
{
x[i].name="id"; //change name of data so we know it is for an id
//By renaming the first element of the list, we have reduced the length of the list by one
//and deleted the first element. This is why we need to keep i at it's current position after a name change.
i=i-1;
}
}//end for
document.checks.submit();
}
``` | 2009/07/09 | [
"https://Stackoverflow.com/questions/1105132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/52256/"
] | I would avoid writing a script like that - it is like having an for/i++ loop calling a function that changes the index as a side effect - unpredictable. You run an iterator through NodeList while modifying the list from inside the loop. You cannot be sure it works until you happen to know exactly the way NodeList is implemented.
It's unpleasant, but I would first copy the list into "real" array, and then do the renaming. | Edit: This is wrong, Nick is right. Although I'd look extra hard to make sure IE actually implements the NodeList correctly, since it still sounds like what you're running into is an infinite loop in IE.
Thanks for the heads up, Nick, I learned something new today. Javascript never ceases to surprise me :)
---
Just renaming an element in the array would not remove it from the array -- getElementsByName is not run constantly, just the initial time that it is called. So IE is stuck in an infinite loop where it keeps checking the same checked element over and over. I'm honestly not sure why Firefox doesn't also get stuck in the same infinite loop.
As far as I understand, the `i=i-1` line is entirely unnecessary. |
1,105,132 | I have a list of check boxes. For the check boxes that are selected, I change it's name before submitting. In FF the function works. In IE I get:
>
> A script on this page is causing Internet Explorer to run slowly. If it
> continues to run, your computer may
> become unresponsive.
>
>
> Do you want to abort the script? YES/NO
>
>
>
Not sure why this loop is causing problems in IE and not FF?
```
function sub()
{
var x=document.getElementsByName("user");
for (i = 0; i < x.length; i++) //for all check boxes
{
if (x[i].checked == true)
{
x[i].name="id"; //change name of data so we know it is for an id
//By renaming the first element of the list, we have reduced the length of the list by one
//and deleted the first element. This is why we need to keep i at it's current position after a name change.
i=i-1;
}
}//end for
document.checks.submit();
}
``` | 2009/07/09 | [
"https://Stackoverflow.com/questions/1105132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/52256/"
] | This should work with a both a live and a non-live list.
Personally, though, I'd try to find some way to output the original page so that the server can figure out which elements to use, instead of relying on javascript to do it.
```
function sub()
{
var x=document.getElementsByName("user");
var nodesToChangeIndex=0;
var nodesToChange=new Array();
for (i = 0; i < x.length; i++) //for all check boxes
{
if (x[i].checked == true)
{
nodesToChange[nodesToChangeIndex++] = x[i];
}
}//end for
for(i=0; i < nodesToChangeIndex; i++)
{
nodesToChange[i].name="id";
}
document.checks.submit();
}
``` | Edit: This is wrong, Nick is right. Although I'd look extra hard to make sure IE actually implements the NodeList correctly, since it still sounds like what you're running into is an infinite loop in IE.
Thanks for the heads up, Nick, I learned something new today. Javascript never ceases to surprise me :)
---
Just renaming an element in the array would not remove it from the array -- getElementsByName is not run constantly, just the initial time that it is called. So IE is stuck in an infinite loop where it keeps checking the same checked element over and over. I'm honestly not sure why Firefox doesn't also get stuck in the same infinite loop.
As far as I understand, the `i=i-1` line is entirely unnecessary. |
1,105,132 | I have a list of check boxes. For the check boxes that are selected, I change it's name before submitting. In FF the function works. In IE I get:
>
> A script on this page is causing Internet Explorer to run slowly. If it
> continues to run, your computer may
> become unresponsive.
>
>
> Do you want to abort the script? YES/NO
>
>
>
Not sure why this loop is causing problems in IE and not FF?
```
function sub()
{
var x=document.getElementsByName("user");
for (i = 0; i < x.length; i++) //for all check boxes
{
if (x[i].checked == true)
{
x[i].name="id"; //change name of data so we know it is for an id
//By renaming the first element of the list, we have reduced the length of the list by one
//and deleted the first element. This is why we need to keep i at it's current position after a name change.
i=i-1;
}
}//end for
document.checks.submit();
}
``` | 2009/07/09 | [
"https://Stackoverflow.com/questions/1105132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/52256/"
] | I would avoid writing a script like that - it is like having an for/i++ loop calling a function that changes the index as a side effect - unpredictable. You run an iterator through NodeList while modifying the list from inside the loop. You cannot be sure it works until you happen to know exactly the way NodeList is implemented.
It's unpleasant, but I would first copy the list into "real" array, and then do the renaming. | Internet Explorer is buggy. It doesn't return a live nodelist but just a snapshot.
Using a framework such as jQuery is your best bet in achieving full compatibility. |
1,105,132 | I have a list of check boxes. For the check boxes that are selected, I change it's name before submitting. In FF the function works. In IE I get:
>
> A script on this page is causing Internet Explorer to run slowly. If it
> continues to run, your computer may
> become unresponsive.
>
>
> Do you want to abort the script? YES/NO
>
>
>
Not sure why this loop is causing problems in IE and not FF?
```
function sub()
{
var x=document.getElementsByName("user");
for (i = 0; i < x.length; i++) //for all check boxes
{
if (x[i].checked == true)
{
x[i].name="id"; //change name of data so we know it is for an id
//By renaming the first element of the list, we have reduced the length of the list by one
//and deleted the first element. This is why we need to keep i at it's current position after a name change.
i=i-1;
}
}//end for
document.checks.submit();
}
``` | 2009/07/09 | [
"https://Stackoverflow.com/questions/1105132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/52256/"
] | This should work with a both a live and a non-live list.
Personally, though, I'd try to find some way to output the original page so that the server can figure out which elements to use, instead of relying on javascript to do it.
```
function sub()
{
var x=document.getElementsByName("user");
var nodesToChangeIndex=0;
var nodesToChange=new Array();
for (i = 0; i < x.length; i++) //for all check boxes
{
if (x[i].checked == true)
{
nodesToChange[nodesToChangeIndex++] = x[i];
}
}//end for
for(i=0; i < nodesToChangeIndex; i++)
{
nodesToChange[i].name="id";
}
document.checks.submit();
}
``` | Internet Explorer is buggy. It doesn't return a live nodelist but just a snapshot.
Using a framework such as jQuery is your best bet in achieving full compatibility. |
7,023,857 | I have simple controller:
```
public class TestController : Controller
{
public ActionResult Test(string r)
{
return View();
}
}
```
I have simple View Test.cshtml:
```
<h2>@ViewContext.RouteData.Values["r"]</h2>
@using (Html.BeginForm("Test", "Test"))
{
<input type="text" name="r" />
<button>Submit</button>
}
```
I have route rule in Global.asax:
```
routes.MapRoute(
null,
"Test/{r}",
new { action = "Test", controller = "Test",
r = UrlParameter.Optional }
);
```
I want to make such thing: user types route value in input, press submit and controller redirects him to page Test/value. But controller show just page with name Test everytime. ViewContext.RouteData.Values["r"] is empty too. I check in debug, Test action recieves user value of r correctly.
How can I realize my idea?
Thanks. | 2011/08/11 | [
"https://Stackoverflow.com/questions/7023857",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/190646/"
] | You cannot do this without javascript. There are two types of methods that exist when submitting a `<form>`: GET and POST. When you use POST (which is the default), the form is POSTed to the url but all data entered in input fields is part of the POST body, so it is not part of the url. When you use GET, the input fields data is part of the query string but of the form `/Test?r=somevalue`.
I wouldn't recommend you trying to send user input as part of the path but if you decide to go that route you could subscribe to the submit event of the form and rewrite the url:
```
$('form').submit(function() {
var data = $('input[name="r"]', this).val();
window.location.href = this.action + '/' + encodeURIComponent(data);
return false;
});
``` | As far as you are saying to post the form to `Html.BeginForm("Test", "Test")` you will be always posted back to the same page.
A solution could be to use an explicit Redirect to the action using 'RedirectToAction' (in view) or you can use javascript to change the form's action:
```
<input type="text" name="r" onchange="this.parent.action = '\/Test\/'+this.value"/>
``` |
7,023,857 | I have simple controller:
```
public class TestController : Controller
{
public ActionResult Test(string r)
{
return View();
}
}
```
I have simple View Test.cshtml:
```
<h2>@ViewContext.RouteData.Values["r"]</h2>
@using (Html.BeginForm("Test", "Test"))
{
<input type="text" name="r" />
<button>Submit</button>
}
```
I have route rule in Global.asax:
```
routes.MapRoute(
null,
"Test/{r}",
new { action = "Test", controller = "Test",
r = UrlParameter.Optional }
);
```
I want to make such thing: user types route value in input, press submit and controller redirects him to page Test/value. But controller show just page with name Test everytime. ViewContext.RouteData.Values["r"] is empty too. I check in debug, Test action recieves user value of r correctly.
How can I realize my idea?
Thanks. | 2011/08/11 | [
"https://Stackoverflow.com/questions/7023857",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/190646/"
] | I'm super late to the party, but just wanted to post a solution for reference. Let's assume that this form has more than just a strong as it's input. Assuming there are other inputs, we can wrap up the inputs of the form into a class in our model, called `TestModel` whose properties maps to the id's of the form's inputs.
In our post, we redirect to the get, passing in the route values we need in the URL. Any other data can then be shuttled to the get using a TempData.
```
public class TestController : Controller
{
[HttpGet]
public ActionResult Test(string r)
{
TestModel model = TempData["TestModel"] as TestModel;
return View(model);
}
[HttpPost]
public ActionResult Test(string r,TestModel model) //some strongly typed class to contain form inputs
{
TempData["TestModel"] = model; //pass any other form inputs to the other action
return RedirectToAction("Test", new{r = r}); //preserve route value
}
}
``` | As far as you are saying to post the form to `Html.BeginForm("Test", "Test")` you will be always posted back to the same page.
A solution could be to use an explicit Redirect to the action using 'RedirectToAction' (in view) or you can use javascript to change the form's action:
```
<input type="text" name="r" onchange="this.parent.action = '\/Test\/'+this.value"/>
``` |
12,598,156 | I'm writing C++ code for a graphics program and in it I have to collect all coordinates to later parse them.I'm trying to use vectors for the same but the following error is returned:
>
> Debug Assertion failed
>
> Program:....
>
> File:....
>
> Line 932
>
> Expression:Vector subscript out of range
>
>
>
Here's part of my code:
```
std::vector<float> coordinates;
//random code
if(dnew >= 0)
{
x = x + 1.0;
glPointSize(1.5f);
glColor3f(0.0,1.0,1.0);
glBegin(GL_POINTS);
glVertex2f(x, y);
glEnd();
dnew = dnew + a;
if(t == 1)
{
coordinates.push_back (x);
}
}
cout <<coordinates[1];
```
When I press retry it takes me to stdthrow.cpp and points to the following line:
```
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Debug_message(const wchar_t *message, const wchar_t *file, unsigned int line)
{
// report error and die
if(::_CrtDbgReportW(_CRT_ASSERT, file, line, NULL, message)==1)
{
::_CrtDbgBreak();
}
}
``` | 2012/09/26 | [
"https://Stackoverflow.com/questions/12598156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1699477/"
] | This error can be caused if `coordinates.size()<= i`, the exception is raised which gives you information that you tried to access element out of bounds of vector | You only push one element into coordinates, so the only valid index is `0`. `coordinates[1]` is thus one past the end of the vector.
Further there are two conditions that could prevent the one `push_back` that is there at all from happening, so it might very well be, that your vector is empty. But you access the second element of the vector unconditionally. |
10,192,672 | I am new to Java language and cannot understand the behavior of finally block in this program. This program should exit after printing BC whereas it is printing BCD. Please help.
```
class Main
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() throws Exception
{
throw new Exception(); /* Line 22 */
}
}
``` | 2012/04/17 | [
"https://Stackoverflow.com/questions/10192672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1151746/"
] | There is nothing to cause the program to exit.
The whole point of a `catch` block is to *catch* the exception and prevent it from propagating further.
After catching an exception, execution continues. | Finally is called at the end of a try/catch block. It gets called even if the try fails and the catch is executed. The `Finally`block itself is only not executed if the program is killed somehow (JVM dies, forced to close, etc.)
In your example D is executing because it is outside of the try/catch/finally{} blocks.
There is a nice blog post on catching exceptions and the try/catch/finally behaviour [here](http://tutorials.jenkov.com/java-exception-handling/basic-try-catch-finally.html). |
10,192,672 | I am new to Java language and cannot understand the behavior of finally block in this program. This program should exit after printing BC whereas it is printing BCD. Please help.
```
class Main
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() throws Exception
{
throw new Exception(); /* Line 22 */
}
}
``` | 2012/04/17 | [
"https://Stackoverflow.com/questions/10192672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1151746/"
] | You're catching the exception (in the catch block) and not rethrowing it - so you're effectively *handling* the exception, and execution then proceeds as if it weren't thrown. The program only exits because it reaches the end of the `main` method - it's not like it's terminated abruptly.
If you change your code to *either* rethrow the exception from the catch block *or* just don't catch it in the first place (both of which will require you to declare that `main` throws `Exception`, of course) then it won't print `D`. | There is nothing to cause the program to exit.
The whole point of a `catch` block is to *catch* the exception and prevent it from propagating further.
After catching an exception, execution continues. |
10,192,672 | I am new to Java language and cannot understand the behavior of finally block in this program. This program should exit after printing BC whereas it is printing BCD. Please help.
```
class Main
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() throws Exception
{
throw new Exception(); /* Line 22 */
}
}
``` | 2012/04/17 | [
"https://Stackoverflow.com/questions/10192672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1151746/"
] | The `finally` block doesn't finalize the program, it just ensure to execute every time the try catch block runs whereas there is an exception or not.. | Finally is the must executable block of java program.
It allows all the allocated resources of the currently running program to get free and make it available for the other applications if required.
This is mainly used when we share the common resources like Database or the devices. |
10,192,672 | I am new to Java language and cannot understand the behavior of finally block in this program. This program should exit after printing BC whereas it is printing BCD. Please help.
```
class Main
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() throws Exception
{
throw new Exception(); /* Line 22 */
}
}
``` | 2012/04/17 | [
"https://Stackoverflow.com/questions/10192672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1151746/"
] | The `finally` block doesn't finalize the program, it just ensure to execute every time the try catch block runs whereas there is an exception or not.. | It would print `BC` if you re-throw the exception in `catch` block.
```
catch (Exception ex)
{
System.out.print("B");
throw ex;
}
```
Then you'll have to declare your main as
```
public static void main(String [] args) throws Exception
``` |
10,192,672 | I am new to Java language and cannot understand the behavior of finally block in this program. This program should exit after printing BC whereas it is printing BCD. Please help.
```
class Main
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() throws Exception
{
throw new Exception(); /* Line 22 */
}
}
``` | 2012/04/17 | [
"https://Stackoverflow.com/questions/10192672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1151746/"
] | You're catching the exception (in the catch block) and not rethrowing it - so you're effectively *handling* the exception, and execution then proceeds as if it weren't thrown. The program only exits because it reaches the end of the `main` method - it's not like it's terminated abruptly.
If you change your code to *either* rethrow the exception from the catch block *or* just don't catch it in the first place (both of which will require you to declare that `main` throws `Exception`, of course) then it won't print `D`. | Which is correct. The above code will.
1. Try to execute `badMethod` and will fail
2. Execute the code in `catch`
3. Execute the code in `finally`
4. Continue in execution - print out the D |
10,192,672 | I am new to Java language and cannot understand the behavior of finally block in this program. This program should exit after printing BC whereas it is printing BCD. Please help.
```
class Main
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() throws Exception
{
throw new Exception(); /* Line 22 */
}
}
``` | 2012/04/17 | [
"https://Stackoverflow.com/questions/10192672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1151746/"
] | The `finally` block doesn't finalize the program, it just ensure to execute every time the try catch block runs whereas there is an exception or not.. | The `finally` block is processed after the `try` or `catch` block runs (depending on whether an exception was thrown/caught or not). If the exceptions were all caught properly and handles by the `catch`, it will run `finally` and then continue running the rest of the method. |
10,192,672 | I am new to Java language and cannot understand the behavior of finally block in this program. This program should exit after printing BC whereas it is printing BCD. Please help.
```
class Main
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() throws Exception
{
throw new Exception(); /* Line 22 */
}
}
``` | 2012/04/17 | [
"https://Stackoverflow.com/questions/10192672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1151746/"
] | There is nothing to cause the program to exit.
The whole point of a `catch` block is to *catch* the exception and prevent it from propagating further.
After catching an exception, execution continues. | Finally is the must executable block of java program.
It allows all the allocated resources of the currently running program to get free and make it available for the other applications if required.
This is mainly used when we share the common resources like Database or the devices. |
10,192,672 | I am new to Java language and cannot understand the behavior of finally block in this program. This program should exit after printing BC whereas it is printing BCD. Please help.
```
class Main
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() throws Exception
{
throw new Exception(); /* Line 22 */
}
}
``` | 2012/04/17 | [
"https://Stackoverflow.com/questions/10192672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1151746/"
] | The `finally` block doesn't finalize the program, it just ensure to execute every time the try catch block runs whereas there is an exception or not.. | Which is correct. The above code will.
1. Try to execute `badMethod` and will fail
2. Execute the code in `catch`
3. Execute the code in `finally`
4. Continue in execution - print out the D |
10,192,672 | I am new to Java language and cannot understand the behavior of finally block in this program. This program should exit after printing BC whereas it is printing BCD. Please help.
```
class Main
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() throws Exception
{
throw new Exception(); /* Line 22 */
}
}
``` | 2012/04/17 | [
"https://Stackoverflow.com/questions/10192672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1151746/"
] | You're catching the exception (in the catch block) and not rethrowing it - so you're effectively *handling* the exception, and execution then proceeds as if it weren't thrown. The program only exits because it reaches the end of the `main` method - it's not like it's terminated abruptly.
If you change your code to *either* rethrow the exception from the catch block *or* just don't catch it in the first place (both of which will require you to declare that `main` throws `Exception`, of course) then it won't print `D`. | Think of the finally block as an independent block of code(s) you'll still expect your method to continue executing irrespective of whether an exception occurs or not.
And so in your case, `badMethod` throws an exception which is consequently caught by the catch block, your main then continue by executing the finally block independently.
In other words, if `badMethod` decides not to throw an exception, your finally block would still continue execute before reaching the end of the method.
Therefore with finally been an independent block it is then possible to also do something like this in your main code if prefered.
```
try
{
fooA();
}
finally
{
fooB();
}
``` |
10,192,672 | I am new to Java language and cannot understand the behavior of finally block in this program. This program should exit after printing BC whereas it is printing BCD. Please help.
```
class Main
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() throws Exception
{
throw new Exception(); /* Line 22 */
}
}
``` | 2012/04/17 | [
"https://Stackoverflow.com/questions/10192672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1151746/"
] | There is nothing to cause the program to exit.
The whole point of a `catch` block is to *catch* the exception and prevent it from propagating further.
After catching an exception, execution continues. | Think of the finally block as an independent block of code(s) you'll still expect your method to continue executing irrespective of whether an exception occurs or not.
And so in your case, `badMethod` throws an exception which is consequently caught by the catch block, your main then continue by executing the finally block independently.
In other words, if `badMethod` decides not to throw an exception, your finally block would still continue execute before reaching the end of the method.
Therefore with finally been an independent block it is then possible to also do something like this in your main code if prefered.
```
try
{
fooA();
}
finally
{
fooB();
}
``` |
28,924,130 | In other words, is it possible to create a Google Chrome app and package it as an .exe or .app so that users won't need Chrome to be installed to run it?
I'm working with NWJS at this time (previously known as Node-Webkit) but I'm interested in the bluetooth/usb APIs from Chrome. | 2015/03/08 | [
"https://Stackoverflow.com/questions/28924130",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/816478/"
] | The editor [Atom](https://atom.io/) uses this approach. It is distributed as a binary on many platforms, but underneath is using Chromium and io.js.
The cross-platform desktop application shell portion of atom has been broken into its own project: [atom-shell](https://github.com/atom/atom-shell).
In essence, you are distributing a customized version of the Chromium browser with you app. | Generally, you cannot distribute Chrome Apps the way you are asking, no. Sorry. |
19,559,241 | Hi I just tried testing if the error function would return an alert but it didn't fire. I altered the url link hoping that it would generate an alert since it won't be able to find or get json data. All I am getting is "Uncaught TypeError: Cannot read property 'length' of undefined jquery-1.9.1.min.js:3"
```
$(document).on('pagebeforeshow', '#blogposts', function () {
//$.mobile.showPageLoadingMsg();
$.ajax({
url: "http://howtodeployit.com/api/get_recent_po",
dataType: "json",
jsonpCallback: 'successCallback',
async: true,
beforeSend: function () {
$.mobile.showPageLoadingMsg(true);
},
complete: function () {
$.mobile.hidePageLoadingMsg();
},
success: function (data) {
$.each(data.posts, function (key, val) {
console.log(data.posts);
var result = $('<li/>').append([$("<h3>", {
html: val.title
}), $("<p>", {
html: val.excerpt
})]).wrapInner('<a href="#devotionpost" onclick="showPost(' + val.id + ')"></a>');
$('#postlist').append(result).trigger('create');
return (key !== 4);
});
$("#postlist").listview();
},
error: function (data) {
alert("Data not found");
}
});
});
``` | 2013/10/24 | [
"https://Stackoverflow.com/questions/19559241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2826276/"
] | I think the problem is that, when you make the AJAX request your code is executing the `success` callback, not the `error` callback. Thus when you execute:
`$.each(data.posts, function(key, val) {`
The `$.each` function is trying to get the length of `data` which is NULL.
It doesn't look right that you have defined a jsonp callback function and yet your still using the `success` and `error` callbacks. This SO question might help a bit :
[Use of success / jsonpCallback with ajax request](https://stackoverflow.com/questions/7167488/use-of-success-jsonpcallback-with-ajax-request) | Maybe here `$.each(data.posts,` data.posts is undefined and that's why you get an error. Log `data` in success callback and see what it contains. |
19,559,241 | Hi I just tried testing if the error function would return an alert but it didn't fire. I altered the url link hoping that it would generate an alert since it won't be able to find or get json data. All I am getting is "Uncaught TypeError: Cannot read property 'length' of undefined jquery-1.9.1.min.js:3"
```
$(document).on('pagebeforeshow', '#blogposts', function () {
//$.mobile.showPageLoadingMsg();
$.ajax({
url: "http://howtodeployit.com/api/get_recent_po",
dataType: "json",
jsonpCallback: 'successCallback',
async: true,
beforeSend: function () {
$.mobile.showPageLoadingMsg(true);
},
complete: function () {
$.mobile.hidePageLoadingMsg();
},
success: function (data) {
$.each(data.posts, function (key, val) {
console.log(data.posts);
var result = $('<li/>').append([$("<h3>", {
html: val.title
}), $("<p>", {
html: val.excerpt
})]).wrapInner('<a href="#devotionpost" onclick="showPost(' + val.id + ')"></a>');
$('#postlist').append(result).trigger('create');
return (key !== 4);
});
$("#postlist").listview();
},
error: function (data) {
alert("Data not found");
}
});
});
``` | 2013/10/24 | [
"https://Stackoverflow.com/questions/19559241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2826276/"
] | I think the problem is that, when you make the AJAX request your code is executing the `success` callback, not the `error` callback. Thus when you execute:
`$.each(data.posts, function(key, val) {`
The `$.each` function is trying to get the length of `data` which is NULL.
It doesn't look right that you have defined a jsonp callback function and yet your still using the `success` and `error` callbacks. This SO question might help a bit :
[Use of success / jsonpCallback with ajax request](https://stackoverflow.com/questions/7167488/use-of-success-jsonpcallback-with-ajax-request) | I created [a clean Fiddle](http://jsfiddle.net/GcXTA/). Opening the given URL gives a 301 redirect followed by a 200 JSON response. The HTTP status code says that everything is fine, so jQuery doesn't know there was an error.
You mixed up two different concepts here: jQuery's error callback is for network errors and all these things. If you transport error states inside your JSON with HTTP status code 200 you have to deal with it on your own inside the success callback.
Sorry, SO doesn't allow JS-Fiddle links without code:
```
beforeSend: function() { console.log('beforeSend'); },
complete: function() { console.log('complete'); },
success:function (data) { console.log('success') },
error: function(data) { console.log('error') }
``` |
19,559,241 | Hi I just tried testing if the error function would return an alert but it didn't fire. I altered the url link hoping that it would generate an alert since it won't be able to find or get json data. All I am getting is "Uncaught TypeError: Cannot read property 'length' of undefined jquery-1.9.1.min.js:3"
```
$(document).on('pagebeforeshow', '#blogposts', function () {
//$.mobile.showPageLoadingMsg();
$.ajax({
url: "http://howtodeployit.com/api/get_recent_po",
dataType: "json",
jsonpCallback: 'successCallback',
async: true,
beforeSend: function () {
$.mobile.showPageLoadingMsg(true);
},
complete: function () {
$.mobile.hidePageLoadingMsg();
},
success: function (data) {
$.each(data.posts, function (key, val) {
console.log(data.posts);
var result = $('<li/>').append([$("<h3>", {
html: val.title
}), $("<p>", {
html: val.excerpt
})]).wrapInner('<a href="#devotionpost" onclick="showPost(' + val.id + ')"></a>');
$('#postlist').append(result).trigger('create');
return (key !== 4);
});
$("#postlist").listview();
},
error: function (data) {
alert("Data not found");
}
});
});
``` | 2013/10/24 | [
"https://Stackoverflow.com/questions/19559241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2826276/"
] | I think the problem is that, when you make the AJAX request your code is executing the `success` callback, not the `error` callback. Thus when you execute:
`$.each(data.posts, function(key, val) {`
The `$.each` function is trying to get the length of `data` which is NULL.
It doesn't look right that you have defined a jsonp callback function and yet your still using the `success` and `error` callbacks. This SO question might help a bit :
[Use of success / jsonpCallback with ajax request](https://stackoverflow.com/questions/7167488/use-of-success-jsonpcallback-with-ajax-request) | Thanks everyone for your input. I did take on-board all suggestions. Recommendation from Jason seems to had made more sense so while investigating his suggestion I came to this [site](http://api.jquery.com/jQuery.ajax/) to read up more about jasonCallback. removing the jasonCallback option though did not fix the issue but strangely this issue seems to do with the url I was using for my json caalback.
What I then did was to change the url from "<http://howtodeployit.com/api/get_recent_po>" to "<http://howtodeployit.com/category/daily-devotion/feed/?json=recentstories>" and it worked. Even though both returned error in the console but the second was the one that triggered the error function. Why I am looking into it. |
8,774,314 | Alright, so here is the property I have
```
public List<String> names{
get{
lock(_names)
return _names;
}
set{
lock(_names)
_names = value
}
}
private List<String> _names;
```
and now say I do a foreach on names like this
```
foreach(String s in names)
{
Console.WriteLine(s);
}
```
My question is, is `names` locked through the whole `foreach`, or does it only `lock` each time `s` is set, then unlocks inside the `foreach`.
If that's confusing, say I try to do this
```
foreach(String s in names)
{
lock(names)
Console.WriteLine(s);
}
```
Will I end up in a deadlock? | 2012/01/08 | [
"https://Stackoverflow.com/questions/8774314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/222054/"
] | The `get_Names` method will only get called once, and the lock will be over (there will be **no** lock) during the iteration of the items. This is probably not what you intend and you should probably go for a much granular lock, such as:
```
lock (someLockObject)
{
foreach(String s in names)
{
Console.WriteLine(s);
}
}
```
When you lock inside the loop, you will take many locks one after the other, which is almost certainly not what you want, since operating the foreach loop will not be atomic anymore. | It's not locked inside the `foreach`. It's locked once, to `get` a reference, then iterated. (Also, your `lock` statements inside the property are currently unnecessary; those operations are atomic.)
Most likely, you should be locking outside the body of the loop, and where the collection is modified.
---
In response to your edit, no. That's not a parallel `foreach` so it's impossible for the loop to get stuck just by itself, let alone deadlock. Once again, that would just be wasted processing power. |
8,774,314 | Alright, so here is the property I have
```
public List<String> names{
get{
lock(_names)
return _names;
}
set{
lock(_names)
_names = value
}
}
private List<String> _names;
```
and now say I do a foreach on names like this
```
foreach(String s in names)
{
Console.WriteLine(s);
}
```
My question is, is `names` locked through the whole `foreach`, or does it only `lock` each time `s` is set, then unlocks inside the `foreach`.
If that's confusing, say I try to do this
```
foreach(String s in names)
{
lock(names)
Console.WriteLine(s);
}
```
Will I end up in a deadlock? | 2012/01/08 | [
"https://Stackoverflow.com/questions/8774314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/222054/"
] | The `get_Names` method will only get called once, and the lock will be over (there will be **no** lock) during the iteration of the items. This is probably not what you intend and you should probably go for a much granular lock, such as:
```
lock (someLockObject)
{
foreach(String s in names)
{
Console.WriteLine(s);
}
}
```
When you lock inside the loop, you will take many locks one after the other, which is almost certainly not what you want, since operating the foreach loop will not be atomic anymore. | ```
lock(_names) return _names;
```
is short for:
```
try
{
Monitor.Enter(_names);
return _names;
}
finally
{
Monitor.Exit(_names);
}
```
which is the equivalent of:
```
Monitor.Enter(_names);
Monitor.Exit(_names);
return _names;
```
seeing it that way should make it more clear that the lock is not necessary.
You might be interested in using one of the [thread-safe collections](https://stackoverflow.com/questions/2980283/thread-safe-collections-in-net) |
8,774,314 | Alright, so here is the property I have
```
public List<String> names{
get{
lock(_names)
return _names;
}
set{
lock(_names)
_names = value
}
}
private List<String> _names;
```
and now say I do a foreach on names like this
```
foreach(String s in names)
{
Console.WriteLine(s);
}
```
My question is, is `names` locked through the whole `foreach`, or does it only `lock` each time `s` is set, then unlocks inside the `foreach`.
If that's confusing, say I try to do this
```
foreach(String s in names)
{
lock(names)
Console.WriteLine(s);
}
```
Will I end up in a deadlock? | 2012/01/08 | [
"https://Stackoverflow.com/questions/8774314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/222054/"
] | The `get_Names` method will only get called once, and the lock will be over (there will be **no** lock) during the iteration of the items. This is probably not what you intend and you should probably go for a much granular lock, such as:
```
lock (someLockObject)
{
foreach(String s in names)
{
Console.WriteLine(s);
}
}
```
When you lock inside the loop, you will take many locks one after the other, which is almost certainly not what you want, since operating the foreach loop will not be atomic anymore. | The foreach loop locks \_names briefly to get the List<>, but unlocks before it starts the actual loop.
Locking on \_names may not be exactly good form, I'd introduce another object to lock on that isn't changed by the actual set operation that's supposedly locked. |
8,774,314 | Alright, so here is the property I have
```
public List<String> names{
get{
lock(_names)
return _names;
}
set{
lock(_names)
_names = value
}
}
private List<String> _names;
```
and now say I do a foreach on names like this
```
foreach(String s in names)
{
Console.WriteLine(s);
}
```
My question is, is `names` locked through the whole `foreach`, or does it only `lock` each time `s` is set, then unlocks inside the `foreach`.
If that's confusing, say I try to do this
```
foreach(String s in names)
{
lock(names)
Console.WriteLine(s);
}
```
Will I end up in a deadlock? | 2012/01/08 | [
"https://Stackoverflow.com/questions/8774314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/222054/"
] | The `get_Names` method will only get called once, and the lock will be over (there will be **no** lock) during the iteration of the items. This is probably not what you intend and you should probably go for a much granular lock, such as:
```
lock (someLockObject)
{
foreach(String s in names)
{
Console.WriteLine(s);
}
}
```
When you lock inside the loop, you will take many locks one after the other, which is almost certainly not what you want, since operating the foreach loop will not be atomic anymore. | In this scenario your lock is effectively doing nothing. The getter roughly expands into the following
```
public List<string> names {
get {
Monitor.Enter(_names);
try {
return _names;
} finally {
Monitor.Exit(_names);
}
}
}
```
This means access to the resource is synchronized only for the time it takes to read the reference. It will do nothing to protect the integrity of the `List<string>`.
The `names` reference is only read once in the `foreach` so it won't be locked during the body . It won't lead to any deadlocks but it won't do much for protection either |
8,774,314 | Alright, so here is the property I have
```
public List<String> names{
get{
lock(_names)
return _names;
}
set{
lock(_names)
_names = value
}
}
private List<String> _names;
```
and now say I do a foreach on names like this
```
foreach(String s in names)
{
Console.WriteLine(s);
}
```
My question is, is `names` locked through the whole `foreach`, or does it only `lock` each time `s` is set, then unlocks inside the `foreach`.
If that's confusing, say I try to do this
```
foreach(String s in names)
{
lock(names)
Console.WriteLine(s);
}
```
Will I end up in a deadlock? | 2012/01/08 | [
"https://Stackoverflow.com/questions/8774314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/222054/"
] | The `get_Names` method will only get called once, and the lock will be over (there will be **no** lock) during the iteration of the items. This is probably not what you intend and you should probably go for a much granular lock, such as:
```
lock (someLockObject)
{
foreach(String s in names)
{
Console.WriteLine(s);
}
}
```
When you lock inside the loop, you will take many locks one after the other, which is almost certainly not what you want, since operating the foreach loop will not be atomic anymore. | It's locked only one inside `_get` method of the property:
```
void Main()
{
Test test = new Test();
test.CallMe();
}
public class Test {
List<string> _names= new List<string>();
public List<string> Names {
get {
Console.WriteLine("Lock");
lock(_names) {
Console.WriteLine("Exit");
return _names;
}
}
}
public void CallMe()
{
foreach(String s in Names)
{
Console.WriteLine(s);
}
}
}
```
An output if this is
```
Lock
Exit
```
IL Code clearly shows that lock happens inside `_get` method of the property :
```
IL_0000: newobj UserQuery+Test..ctor
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: callvirt UserQuery+Test.CallMe
Test.get_Names: //GET METHOD OF THE PROPERTY
IL_0000: ldstr "Lock"
IL_0005: call System.Console.WriteLine
IL_000A: ldc.i4.0
IL_000B: stloc.0
IL_000C: ldarg.0
IL_000D: ldfld UserQuery+Test._names
IL_0012: dup
IL_0013: stloc.2
IL_0014: ldloca.s 00
IL_0016: call System.Threading.Monitor.Enter //LOCK
IL_001B: ldstr "Exit"
IL_0020: call System.Console.WriteLine
IL_0025: ldarg.0
IL_0026: ldfld UserQuery+Test._names
IL_002B: stloc.1
IL_002C: leave.s IL_0038
IL_002E: ldloc.0
IL_002F: brfalse.s IL_0037
IL_0031: ldloc.2
IL_0032: call System.Threading.Monitor.Exit //UNLOCK
IL_0037: endfinally
IL_0038: ldloc.1
IL_0039: ret
Test.CallMe: // CALLME METHOD CODE
IL_0000: ldarg.0
IL_0001: call UserQuery+Test.get_Names //ONCE !!
IL_0006: callvirt System.Collections.Generic.List<System.String>.GetEnumerator
IL_000B: stloc.1
IL_000C: br.s IL_001C
IL_000E: ldloca.s 01
IL_0010: call System.Collections.Generic.List<System.String>.get_Current
IL_0015: stloc.0
IL_0016: ldloc.0
IL_0017: call System.Console.WriteLine
IL_001C: ldloca.s 01
IL_001E: call System.Collections.Generic.List<System.String>.MoveNext
IL_0023: brtrue.s IL_000E
IL_0025: leave.s IL_0035
IL_0027: ldloca.s 01
IL_0029: constrained. System.Collections.Generic.List<>.Enumerator
IL_002F: callvirt System.IDisposable.Dispose
IL_0034: endfinally
IL_0035: ret
Test..ctor:
IL_0000: ldarg.0
IL_0001: newobj System.Collections.Generic.List<System.String>..ctor
IL_0006: stfld UserQuery+Test._names
IL_000B: ldarg.0
IL_000C: call System.Object..ctor
IL_0011: ret
``` |
249,357 | I am currently working on my first website. I have no idea where to start on the CSS page, or if there are any standards that I should be following.
I would appreciate any links or first-hand advise. | 2008/10/30 | [
"https://Stackoverflow.com/questions/249357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2598/"
] | Have a look at
[CSS Systems for writing maintainable CSS](http://natbat.net/2008/Sep/28/css-systems/) by Natalie Downe of [ClearLeft](http://clearleft.com/). There are a lot of great concepts in her presentation (I recommend downloading the PDF because her notes are pretty detailed).
I think her presentation is aimed at full time CSS devs more so than beginners, but even beginners could take a lot away from it. | I have been building websites for 5 years now and still learn a lot by reading this every so often: <http://code.google.com/speed/page-speed/docs/rendering.html>
Also check out <http://www.zeldman.com> blog on CSS. This guy is a legend in the web world. |
249,357 | I am currently working on my first website. I have no idea where to start on the CSS page, or if there are any standards that I should be following.
I would appreciate any links or first-hand advise. | 2008/10/30 | [
"https://Stackoverflow.com/questions/249357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2598/"
] | You can save yourself a lot of headache by **understanding specificity**. When you set a rule for something, if there is a conflicting rule, **specificity decides which rule wins**.
A quick (incomplete) rundown:
An element-wide rule (like `p {color:green;}`) will be trumped by:
A class-specific rule (like `p.sidenote {color: blue;}`), which will be trumped by:
An id-specific rule (like `p#final {color: red;}`), which will be trumped by:
An inline declaration (like `<p style="color: orange;">`), which will be trumped by:
An important rule (like `p#final {color: inherit !important;}`)
...all of which can be trumped by the user's rules.
The interactions can be complex, but there are mathematic rules underlying them. For a more complete treatment, see Chapter 3 of Eric Meyer's "CSS: The Definitive Guide."
To recap: **if you set a rule and it doesn't seem to affect anything, you've probably got a conflicting rule.** To understand why one rule beats the other, learn about specificity. | I have been building websites for 5 years now and still learn a lot by reading this every so often: <http://code.google.com/speed/page-speed/docs/rendering.html>
Also check out <http://www.zeldman.com> blog on CSS. This guy is a legend in the web world. |
249,357 | I am currently working on my first website. I have no idea where to start on the CSS page, or if there are any standards that I should be following.
I would appreciate any links or first-hand advise. | 2008/10/30 | [
"https://Stackoverflow.com/questions/249357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2598/"
] | You can save yourself a lot of headache by **understanding specificity**. When you set a rule for something, if there is a conflicting rule, **specificity decides which rule wins**.
A quick (incomplete) rundown:
An element-wide rule (like `p {color:green;}`) will be trumped by:
A class-specific rule (like `p.sidenote {color: blue;}`), which will be trumped by:
An id-specific rule (like `p#final {color: red;}`), which will be trumped by:
An inline declaration (like `<p style="color: orange;">`), which will be trumped by:
An important rule (like `p#final {color: inherit !important;}`)
...all of which can be trumped by the user's rules.
The interactions can be complex, but there are mathematic rules underlying them. For a more complete treatment, see Chapter 3 of Eric Meyer's "CSS: The Definitive Guide."
To recap: **if you set a rule and it doesn't seem to affect anything, you've probably got a conflicting rule.** To understand why one rule beats the other, learn about specificity. | i learned what i need to know from Mc Farland's Missing Manual (Oreilly book), and by staring at a [sample rails' app's](http://oreilly.com/catalog/9780596527440/index.html) stylesheet. That works pretty well, google "example / sample projects / app / repositories" for PHP, ASP.net, whatever you're using. |
249,357 | I am currently working on my first website. I have no idea where to start on the CSS page, or if there are any standards that I should be following.
I would appreciate any links or first-hand advise. | 2008/10/30 | [
"https://Stackoverflow.com/questions/249357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2598/"
] | Not exactly beginner material, but [A List Apart](http://www.alistapart.com/) is a very interesting blog about CSS and its intricacies.
I find the W3 School's [pages on CSS](http://www.w3schools.com/css/) great for reference. | If you use a reset script - it'll iron out some of the quirks between different browsers. Doing so has made my life easier.
I've seen some people swear by simply using
```
* { padding: 0; margin: 0; }
```
But you can also use more thorough implementations - like the one in the YUI library... <http://developer.yahoo.com/yui/reset/>
When it comes to testing your site renders - browsershots.org is pretty useful.
The webdev firefox plugin is brilliant - CTRL+SHIFT+E allows you to edit css, and see changes on the fly. If you CTRL+F, you can also hover yr mouse over an element to find out what it is.
To add to the sites other people have mentioned - I've found <http://css-discuss.incutio.com> useful. Freenode #css is handy too. |
249,357 | I am currently working on my first website. I have no idea where to start on the CSS page, or if there are any standards that I should be following.
I would appreciate any links or first-hand advise. | 2008/10/30 | [
"https://Stackoverflow.com/questions/249357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2598/"
] | Resist the urge to over-specify class or id names. Use contextual or descendent selectors. This let's you easily define styles for areas of your page, but save on the sanity of having to manage and remember tons of names. For example:
```
<ul id="nav">
<li class="navItem"><span class="itemText">Nav Item</span></li>
<li class="navItem"><span class="itemText">Nav Item</span></li>
</ul>
#nav { }
#nav .navItem { }
#nav .itemText { }
```
This is needlessly complex, and you'll find yourself quickly running out of good semantic descriptions. You'd be better off with something like:
```
<ul id="nav">
<li><span>Nav Item</span></li>
<li><span>Nav Item</span></li>
</ul>
#nav {}
#nav li {}
#nav li span {}
``` | Not exactly beginner material, but [A List Apart](http://www.alistapart.com/) is a very interesting blog about CSS and its intricacies.
I find the W3 School's [pages on CSS](http://www.w3schools.com/css/) great for reference. |
249,357 | I am currently working on my first website. I have no idea where to start on the CSS page, or if there are any standards that I should be following.
I would appreciate any links or first-hand advise. | 2008/10/30 | [
"https://Stackoverflow.com/questions/249357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2598/"
] | Aside from the great resources pointed in the other answers, here are some tips to structure the way you work on the CSS:
Do the work in the following order...
1. Lay out the semantic structure of your page in HTML. Make sure it's right without any CSS.
* Create the basic layout of the page in a CSS - columns, headers, floating boxes.
* Add typography - fonts, sizes and colors.
* Add the graphical elements - background pictures, logos and so on
Put a link on your page to the [W3C CSS validator](http://jigsaw.w3.org/css-validator/check/referer) (if your site is visible from the internet) and keep hitting it every so often.
Keep all your styles outside of the HTML.
It's good to have IE6/7/8, FF2/3 and Chrome/Safari. Opera would be nice too. Keep changing the browser you open your page in while working (unless you're digging into a particular browser issue :-)).
Add comments what each rule does and why. Keep the dev version of the CSS checked in and once you're done, then remove comments and whitespaces and compress multiple rules into one for production.
**Update**: As Bobby Jack mentioned, I missed to mention the debugging tools. You can use [IE Developer Toolbar](http://www.microsoft.com/downloads/details.aspx?FamilyId=E59C3964-672D-4511-BB3E-2D5E1DB91038&displaylang=en) (for IE) or [Firebug](http://getfirebug.com/) (for FF) or the integrated Inspection tools in Chrome to inspect which rules are applied to particular element, or modify the style of an element on the fly. | The [Complete CSS Guide on westciv.com](http://www.westciv.com/style_master/academy/css_tutorial/index.html) has an exhaustive amount of information on CSS. It's a great place to start diving in. |
249,357 | I am currently working on my first website. I have no idea where to start on the CSS page, or if there are any standards that I should be following.
I would appreciate any links or first-hand advise. | 2008/10/30 | [
"https://Stackoverflow.com/questions/249357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2598/"
] | Resist the urge to over-specify class or id names. Use contextual or descendent selectors. This let's you easily define styles for areas of your page, but save on the sanity of having to manage and remember tons of names. For example:
```
<ul id="nav">
<li class="navItem"><span class="itemText">Nav Item</span></li>
<li class="navItem"><span class="itemText">Nav Item</span></li>
</ul>
#nav { }
#nav .navItem { }
#nav .itemText { }
```
This is needlessly complex, and you'll find yourself quickly running out of good semantic descriptions. You'd be better off with something like:
```
<ul id="nav">
<li><span>Nav Item</span></li>
<li><span>Nav Item</span></li>
</ul>
#nav {}
#nav li {}
#nav li span {}
``` | My first tip would be to always use only external style sheets - try to avoid inline or header styles.
Use classes and ids as much as possible.
I second the suggestion for [A List Apart](http://www.alistapart.com/)
Although not very pretty, and sometimes a little old, [HTML Help by WDG](http://htmlhelp.com/reference/css/style-html.html) has some good references.
[Quirksmode.org](http://www.quirksmode.org/css/contents.html) has a great css compatibility table. |
249,357 | I am currently working on my first website. I have no idea where to start on the CSS page, or if there are any standards that I should be following.
I would appreciate any links or first-hand advise. | 2008/10/30 | [
"https://Stackoverflow.com/questions/249357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2598/"
] | An error that beginners make quite often:
CSS is semantic as well. Try to express concepts, not formats. Contrived example:
### Wrong:
```
div.red
{
color: red;
}
```
as opposed to:
### Good:
```
div.error
{
color: red;
}
```
CSS should be the formatting companion for the concepts you use on your web site, so they should be reflected in it. You will be much more flexible this way. | Have a look at
[CSS Systems for writing maintainable CSS](http://natbat.net/2008/Sep/28/css-systems/) by Natalie Downe of [ClearLeft](http://clearleft.com/). There are a lot of great concepts in her presentation (I recommend downloading the PDF because her notes are pretty detailed).
I think her presentation is aimed at full time CSS devs more so than beginners, but even beginners could take a lot away from it. |
249,357 | I am currently working on my first website. I have no idea where to start on the CSS page, or if there are any standards that I should be following.
I would appreciate any links or first-hand advise. | 2008/10/30 | [
"https://Stackoverflow.com/questions/249357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2598/"
] | You've already gotten a good set of answers regarding your question put here is a point you may find usefull.
Use Firefox with Firebug extension. If you don't have firefox I recommend you install it even if it's just for this. Firebug allows you to select element from the page and shows you th applied css. Then you can edit this css with the fire bug without any page reloads. Once you're happy with a style you can easily copy the definitions from firbug to your css editor.
At least for me firebug is an absolute necessity when working with styles.
Couple of tips for the css itself. When defining your styles use id's only when the element in question is unique. That way your styles are reusable. Use hierarchical definitions eg.
`#header .navigationElement a{color:red;}` and `#footer .navigationElement a{color:black;}` That way you can move youre html code around and the correct style is applied automaticly. | i learned what i need to know from Mc Farland's Missing Manual (Oreilly book), and by staring at a [sample rails' app's](http://oreilly.com/catalog/9780596527440/index.html) stylesheet. That works pretty well, google "example / sample projects / app / repositories" for PHP, ASP.net, whatever you're using. |
249,357 | I am currently working on my first website. I have no idea where to start on the CSS page, or if there are any standards that I should be following.
I would appreciate any links or first-hand advise. | 2008/10/30 | [
"https://Stackoverflow.com/questions/249357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2598/"
] | This is a decent overview:
<http://www.onlinetools.org/articles/cssguides.html> | I have been building websites for 5 years now and still learn a lot by reading this every so often: <http://code.google.com/speed/page-speed/docs/rendering.html>
Also check out <http://www.zeldman.com> blog on CSS. This guy is a legend in the web world. |
256,551 | I'm using this code:
```
numbzip=`ls *.plt.zip | wc -l` &>/dev/null
```
and trying to get rid of the output in the command window.
No files ending on .plt.zip exist so it comes back with:
```
ls: cannot access *.plt.zip: No such file or directory
```
whatever I try it always writes this line in the command window.
I tried:
```
numbzip=`ls *.plt.zip | wc -l` >/dev/null 2>/dev/null
numbzip=`ls *.plt.zip | wc -l` >/dev/null >>/dev/null 2>/dev/null
```
Regards, Wilco. | 2016/01/20 | [
"https://unix.stackexchange.com/questions/256551",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/152384/"
] | If your xargs implementation support `-0` option:
```
tr '\n' '\0' <file | xargs -0 -l1 mkdir
```
POSIXly:
```
while IFS= read -r file; do
mkdir -p -- "$file"
done <file
```
[(Note that using `while` loop to process text considered bad practice in shell script)](https://unix.stackexchange.com/q/169716/38906) | Make the names null terminated and split there:
```
cat file | tr '\n' '\0' | xargs -l1 -0 mkdir
```
`tr` will replace the newline that `cat` output with `\0`, and the `-0` flags in `xargs` is telling it to split arguments on the `\0`. |
256,551 | I'm using this code:
```
numbzip=`ls *.plt.zip | wc -l` &>/dev/null
```
and trying to get rid of the output in the command window.
No files ending on .plt.zip exist so it comes back with:
```
ls: cannot access *.plt.zip: No such file or directory
```
whatever I try it always writes this line in the command window.
I tried:
```
numbzip=`ls *.plt.zip | wc -l` >/dev/null 2>/dev/null
numbzip=`ls *.plt.zip | wc -l` >/dev/null >>/dev/null 2>/dev/null
```
Regards, Wilco. | 2016/01/20 | [
"https://unix.stackexchange.com/questions/256551",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/152384/"
] | Use **`-d '\n'`** with your `xargs` command:
```
cat file | xargs -d '\n' -l1 mkdir
```
From manpage:
```
-d delim
Input items are terminated by the specified character. Quotes and backslash are not special; every
character in the input is taken literally. Disables the end-of-file string, which is treated like any
other argument. This can be used when the input consists of simply newline-separated items, although
it is almost always better to design your program to use --null where this is possible. The specified
delimiter may be a single character, a C-style character escape such as \n, or an octal or hexadecimal
escape code. Octal and hexadecimal escape codes are understood as for the printf command. Multibyte
characters are not supported.
```
---
Example output:
```
$ ls
file
$ cat file
Long Name One (001)
Long Name Two (201)
Long Name Three (123)
$ cat file | xargs -d '\n' -l1 mkdir
$ ls -1
file
Long Name One (001)
Long Name Three (123)
Long Name Two (201)
``` | If your xargs implementation support `-0` option:
```
tr '\n' '\0' <file | xargs -0 -l1 mkdir
```
POSIXly:
```
while IFS= read -r file; do
mkdir -p -- "$file"
done <file
```
[(Note that using `while` loop to process text considered bad practice in shell script)](https://unix.stackexchange.com/q/169716/38906) |
256,551 | I'm using this code:
```
numbzip=`ls *.plt.zip | wc -l` &>/dev/null
```
and trying to get rid of the output in the command window.
No files ending on .plt.zip exist so it comes back with:
```
ls: cannot access *.plt.zip: No such file or directory
```
whatever I try it always writes this line in the command window.
I tried:
```
numbzip=`ls *.plt.zip | wc -l` >/dev/null 2>/dev/null
numbzip=`ls *.plt.zip | wc -l` >/dev/null >>/dev/null 2>/dev/null
```
Regards, Wilco. | 2016/01/20 | [
"https://unix.stackexchange.com/questions/256551",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/152384/"
] | If your xargs implementation support `-0` option:
```
tr '\n' '\0' <file | xargs -0 -l1 mkdir
```
POSIXly:
```
while IFS= read -r file; do
mkdir -p -- "$file"
done <file
```
[(Note that using `while` loop to process text considered bad practice in shell script)](https://unix.stackexchange.com/q/169716/38906) | You can do this POSIXLY with the `-I` option:
```
xargs -I % mkdir % < file
```
<http://pubs.opengroup.org/onlinepubs/9699919799/utilities/xargs.html> |
256,551 | I'm using this code:
```
numbzip=`ls *.plt.zip | wc -l` &>/dev/null
```
and trying to get rid of the output in the command window.
No files ending on .plt.zip exist so it comes back with:
```
ls: cannot access *.plt.zip: No such file or directory
```
whatever I try it always writes this line in the command window.
I tried:
```
numbzip=`ls *.plt.zip | wc -l` >/dev/null 2>/dev/null
numbzip=`ls *.plt.zip | wc -l` >/dev/null >>/dev/null 2>/dev/null
```
Regards, Wilco. | 2016/01/20 | [
"https://unix.stackexchange.com/questions/256551",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/152384/"
] | If your xargs implementation support `-0` option:
```
tr '\n' '\0' <file | xargs -0 -l1 mkdir
```
POSIXly:
```
while IFS= read -r file; do
mkdir -p -- "$file"
done <file
```
[(Note that using `while` loop to process text considered bad practice in shell script)](https://unix.stackexchange.com/q/169716/38906) | `xargs` expects a very special input format where arguments are delimited by blanks or newlines (sometimes other forms of vertical whitespace, sometimes dependant on the current locale), and where single quote, double quotes and backslash can be used to escape them (but in a different way from shell quotes).
`-l1` is not to pass one line of input as one single argument to `mkdir`, but to call one `mkdir` invocation for each single line of input but with words on that line still separated out as different arguments to `mkdir`.
The GNU implementation of `xargs` added a `-0` option decades ago to accept NUL-delimited input. That's the most obvious way to separate words that are going to end up being arguments to a command because the NUL character happens to be the only character that cannot occur in a command argument or file name (your chosen list format which puts one file per line can't represent all possible file names as it doesn't allow a newline in a file name).
That `-0` has been copied by several other `xargs` implementations but not all.
With those you can do:
```
<file tr '\n' '\0' | xargs -0 mkdir -p --
```
That will call `mkdir` as few times as possible with as many arguments as possible.
But note that if `file` is empty, `mkdir` will still be run and you'll get a syntax error by `mkdir` because of the missing argument. GNU `xargs` added a `-r` option for that which has been copied by a few other implementations.
GNU `xargs` also added (later) a `-d` option to be able to specify arbitrary delimiters, but I don't think any other implementation copied it. With GNU `xargs`, the best way is with:
```
xargs -rd '\n' -a file mkdir -p --
```
By passing the file with `-a` (also a GNU extension) instead of stdin, that means `mkdir`'s stdin is preserved.
POSIXly, you'd need to post-process the input to put it in the format expected by `xargs`. You could do it for instance with:
```
<file sed 's/"/"\\""/g; s/^/"/; s/$/"/' | xargs mkdir -p --
```
Where we enclose each line inside double quotes and escape each `"` as `"\""` before feeding to xargs.
But beware of possible limitations:
* the error when the file is empty already mentioned above
* it may fail with some implementations (including of `sed`) if the content of `file` is not valid text in the current locale. If `file` contains file names encoding in more than one different charset, or a charset different from the the locale's one, you can fix the locale to C which should help.
* some `xargs` implementations have ridiculously low limits on the maximum length of an argument (can be as low as 255 bytes).
To work around the *syntax error upon empty input* error, you can write:
```
<file sed 's/"/"\\""/g; s/^/"/; s/$/"/' |
xargs sh -c '[ "$#" -eq 0 ] || exec mkdir -p -- "$@"' sh
``` |
256,551 | I'm using this code:
```
numbzip=`ls *.plt.zip | wc -l` &>/dev/null
```
and trying to get rid of the output in the command window.
No files ending on .plt.zip exist so it comes back with:
```
ls: cannot access *.plt.zip: No such file or directory
```
whatever I try it always writes this line in the command window.
I tried:
```
numbzip=`ls *.plt.zip | wc -l` >/dev/null 2>/dev/null
numbzip=`ls *.plt.zip | wc -l` >/dev/null >>/dev/null 2>/dev/null
```
Regards, Wilco. | 2016/01/20 | [
"https://unix.stackexchange.com/questions/256551",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/152384/"
] | Use **`-d '\n'`** with your `xargs` command:
```
cat file | xargs -d '\n' -l1 mkdir
```
From manpage:
```
-d delim
Input items are terminated by the specified character. Quotes and backslash are not special; every
character in the input is taken literally. Disables the end-of-file string, which is treated like any
other argument. This can be used when the input consists of simply newline-separated items, although
it is almost always better to design your program to use --null where this is possible. The specified
delimiter may be a single character, a C-style character escape such as \n, or an octal or hexadecimal
escape code. Octal and hexadecimal escape codes are understood as for the printf command. Multibyte
characters are not supported.
```
---
Example output:
```
$ ls
file
$ cat file
Long Name One (001)
Long Name Two (201)
Long Name Three (123)
$ cat file | xargs -d '\n' -l1 mkdir
$ ls -1
file
Long Name One (001)
Long Name Three (123)
Long Name Two (201)
``` | Make the names null terminated and split there:
```
cat file | tr '\n' '\0' | xargs -l1 -0 mkdir
```
`tr` will replace the newline that `cat` output with `\0`, and the `-0` flags in `xargs` is telling it to split arguments on the `\0`. |
256,551 | I'm using this code:
```
numbzip=`ls *.plt.zip | wc -l` &>/dev/null
```
and trying to get rid of the output in the command window.
No files ending on .plt.zip exist so it comes back with:
```
ls: cannot access *.plt.zip: No such file or directory
```
whatever I try it always writes this line in the command window.
I tried:
```
numbzip=`ls *.plt.zip | wc -l` >/dev/null 2>/dev/null
numbzip=`ls *.plt.zip | wc -l` >/dev/null >>/dev/null 2>/dev/null
```
Regards, Wilco. | 2016/01/20 | [
"https://unix.stackexchange.com/questions/256551",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/152384/"
] | Make the names null terminated and split there:
```
cat file | tr '\n' '\0' | xargs -l1 -0 mkdir
```
`tr` will replace the newline that `cat` output with `\0`, and the `-0` flags in `xargs` is telling it to split arguments on the `\0`. | You can do this POSIXLY with the `-I` option:
```
xargs -I % mkdir % < file
```
<http://pubs.opengroup.org/onlinepubs/9699919799/utilities/xargs.html> |
256,551 | I'm using this code:
```
numbzip=`ls *.plt.zip | wc -l` &>/dev/null
```
and trying to get rid of the output in the command window.
No files ending on .plt.zip exist so it comes back with:
```
ls: cannot access *.plt.zip: No such file or directory
```
whatever I try it always writes this line in the command window.
I tried:
```
numbzip=`ls *.plt.zip | wc -l` >/dev/null 2>/dev/null
numbzip=`ls *.plt.zip | wc -l` >/dev/null >>/dev/null 2>/dev/null
```
Regards, Wilco. | 2016/01/20 | [
"https://unix.stackexchange.com/questions/256551",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/152384/"
] | Use **`-d '\n'`** with your `xargs` command:
```
cat file | xargs -d '\n' -l1 mkdir
```
From manpage:
```
-d delim
Input items are terminated by the specified character. Quotes and backslash are not special; every
character in the input is taken literally. Disables the end-of-file string, which is treated like any
other argument. This can be used when the input consists of simply newline-separated items, although
it is almost always better to design your program to use --null where this is possible. The specified
delimiter may be a single character, a C-style character escape such as \n, or an octal or hexadecimal
escape code. Octal and hexadecimal escape codes are understood as for the printf command. Multibyte
characters are not supported.
```
---
Example output:
```
$ ls
file
$ cat file
Long Name One (001)
Long Name Two (201)
Long Name Three (123)
$ cat file | xargs -d '\n' -l1 mkdir
$ ls -1
file
Long Name One (001)
Long Name Three (123)
Long Name Two (201)
``` | You can do this POSIXLY with the `-I` option:
```
xargs -I % mkdir % < file
```
<http://pubs.opengroup.org/onlinepubs/9699919799/utilities/xargs.html> |
256,551 | I'm using this code:
```
numbzip=`ls *.plt.zip | wc -l` &>/dev/null
```
and trying to get rid of the output in the command window.
No files ending on .plt.zip exist so it comes back with:
```
ls: cannot access *.plt.zip: No such file or directory
```
whatever I try it always writes this line in the command window.
I tried:
```
numbzip=`ls *.plt.zip | wc -l` >/dev/null 2>/dev/null
numbzip=`ls *.plt.zip | wc -l` >/dev/null >>/dev/null 2>/dev/null
```
Regards, Wilco. | 2016/01/20 | [
"https://unix.stackexchange.com/questions/256551",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/152384/"
] | Use **`-d '\n'`** with your `xargs` command:
```
cat file | xargs -d '\n' -l1 mkdir
```
From manpage:
```
-d delim
Input items are terminated by the specified character. Quotes and backslash are not special; every
character in the input is taken literally. Disables the end-of-file string, which is treated like any
other argument. This can be used when the input consists of simply newline-separated items, although
it is almost always better to design your program to use --null where this is possible. The specified
delimiter may be a single character, a C-style character escape such as \n, or an octal or hexadecimal
escape code. Octal and hexadecimal escape codes are understood as for the printf command. Multibyte
characters are not supported.
```
---
Example output:
```
$ ls
file
$ cat file
Long Name One (001)
Long Name Two (201)
Long Name Three (123)
$ cat file | xargs -d '\n' -l1 mkdir
$ ls -1
file
Long Name One (001)
Long Name Three (123)
Long Name Two (201)
``` | `xargs` expects a very special input format where arguments are delimited by blanks or newlines (sometimes other forms of vertical whitespace, sometimes dependant on the current locale), and where single quote, double quotes and backslash can be used to escape them (but in a different way from shell quotes).
`-l1` is not to pass one line of input as one single argument to `mkdir`, but to call one `mkdir` invocation for each single line of input but with words on that line still separated out as different arguments to `mkdir`.
The GNU implementation of `xargs` added a `-0` option decades ago to accept NUL-delimited input. That's the most obvious way to separate words that are going to end up being arguments to a command because the NUL character happens to be the only character that cannot occur in a command argument or file name (your chosen list format which puts one file per line can't represent all possible file names as it doesn't allow a newline in a file name).
That `-0` has been copied by several other `xargs` implementations but not all.
With those you can do:
```
<file tr '\n' '\0' | xargs -0 mkdir -p --
```
That will call `mkdir` as few times as possible with as many arguments as possible.
But note that if `file` is empty, `mkdir` will still be run and you'll get a syntax error by `mkdir` because of the missing argument. GNU `xargs` added a `-r` option for that which has been copied by a few other implementations.
GNU `xargs` also added (later) a `-d` option to be able to specify arbitrary delimiters, but I don't think any other implementation copied it. With GNU `xargs`, the best way is with:
```
xargs -rd '\n' -a file mkdir -p --
```
By passing the file with `-a` (also a GNU extension) instead of stdin, that means `mkdir`'s stdin is preserved.
POSIXly, you'd need to post-process the input to put it in the format expected by `xargs`. You could do it for instance with:
```
<file sed 's/"/"\\""/g; s/^/"/; s/$/"/' | xargs mkdir -p --
```
Where we enclose each line inside double quotes and escape each `"` as `"\""` before feeding to xargs.
But beware of possible limitations:
* the error when the file is empty already mentioned above
* it may fail with some implementations (including of `sed`) if the content of `file` is not valid text in the current locale. If `file` contains file names encoding in more than one different charset, or a charset different from the the locale's one, you can fix the locale to C which should help.
* some `xargs` implementations have ridiculously low limits on the maximum length of an argument (can be as low as 255 bytes).
To work around the *syntax error upon empty input* error, you can write:
```
<file sed 's/"/"\\""/g; s/^/"/; s/$/"/' |
xargs sh -c '[ "$#" -eq 0 ] || exec mkdir -p -- "$@"' sh
``` |
256,551 | I'm using this code:
```
numbzip=`ls *.plt.zip | wc -l` &>/dev/null
```
and trying to get rid of the output in the command window.
No files ending on .plt.zip exist so it comes back with:
```
ls: cannot access *.plt.zip: No such file or directory
```
whatever I try it always writes this line in the command window.
I tried:
```
numbzip=`ls *.plt.zip | wc -l` >/dev/null 2>/dev/null
numbzip=`ls *.plt.zip | wc -l` >/dev/null >>/dev/null 2>/dev/null
```
Regards, Wilco. | 2016/01/20 | [
"https://unix.stackexchange.com/questions/256551",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/152384/"
] | `xargs` expects a very special input format where arguments are delimited by blanks or newlines (sometimes other forms of vertical whitespace, sometimes dependant on the current locale), and where single quote, double quotes and backslash can be used to escape them (but in a different way from shell quotes).
`-l1` is not to pass one line of input as one single argument to `mkdir`, but to call one `mkdir` invocation for each single line of input but with words on that line still separated out as different arguments to `mkdir`.
The GNU implementation of `xargs` added a `-0` option decades ago to accept NUL-delimited input. That's the most obvious way to separate words that are going to end up being arguments to a command because the NUL character happens to be the only character that cannot occur in a command argument or file name (your chosen list format which puts one file per line can't represent all possible file names as it doesn't allow a newline in a file name).
That `-0` has been copied by several other `xargs` implementations but not all.
With those you can do:
```
<file tr '\n' '\0' | xargs -0 mkdir -p --
```
That will call `mkdir` as few times as possible with as many arguments as possible.
But note that if `file` is empty, `mkdir` will still be run and you'll get a syntax error by `mkdir` because of the missing argument. GNU `xargs` added a `-r` option for that which has been copied by a few other implementations.
GNU `xargs` also added (later) a `-d` option to be able to specify arbitrary delimiters, but I don't think any other implementation copied it. With GNU `xargs`, the best way is with:
```
xargs -rd '\n' -a file mkdir -p --
```
By passing the file with `-a` (also a GNU extension) instead of stdin, that means `mkdir`'s stdin is preserved.
POSIXly, you'd need to post-process the input to put it in the format expected by `xargs`. You could do it for instance with:
```
<file sed 's/"/"\\""/g; s/^/"/; s/$/"/' | xargs mkdir -p --
```
Where we enclose each line inside double quotes and escape each `"` as `"\""` before feeding to xargs.
But beware of possible limitations:
* the error when the file is empty already mentioned above
* it may fail with some implementations (including of `sed`) if the content of `file` is not valid text in the current locale. If `file` contains file names encoding in more than one different charset, or a charset different from the the locale's one, you can fix the locale to C which should help.
* some `xargs` implementations have ridiculously low limits on the maximum length of an argument (can be as low as 255 bytes).
To work around the *syntax error upon empty input* error, you can write:
```
<file sed 's/"/"\\""/g; s/^/"/; s/$/"/' |
xargs sh -c '[ "$#" -eq 0 ] || exec mkdir -p -- "$@"' sh
``` | You can do this POSIXLY with the `-I` option:
```
xargs -I % mkdir % < file
```
<http://pubs.opengroup.org/onlinepubs/9699919799/utilities/xargs.html> |
38,194,057 | How do I declare, versus define a struct, such as for data shared between multiple files. I understand the idea when defining primitives. So, for example, I might have:
```
extern int myvalue; /* in shared header file */
```
and
```
int myvalue = 5; /* in data.c file */
```
But, how do I do the same thing for structs. For example, if I have the following type:
```
typedef struct {
size_t size;
char * strings[];
} STRLIST;
```
If I then use the statement:
```
STRLIST list;
```
This is both a declaration and definition. So, how do apply the same principle of using an extern? | 2016/07/05 | [
"https://Stackoverflow.com/questions/38194057",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1655700/"
] | To declare an *instance of* a struct (or a pointer to one):
```
extern STRLIST* ptrList;
extern STRLIST list;
```
To define it:
```
STRLIST* ptrList;
STRLIST list;
```
To declare a *struct type*:
```
typedef struct STRLIST;
```
To define it:
```
typedef struct {
size_t size;
char * strings[];
} STRLIST;
```
Note that you can use a pointer to a struct with only a declaration, but you must have a definition to use the struct directly. | Every name in C, before it is used, has to be declared. To declare is (just) to explain what type the name describes. This is information for the compiler how to treat the object of this name.
Definition, on the other hand, instructs the compiler to reserve memory for the object. A definition is always also a declaration.
In your case, the statement:
```
STRLIST* list;
```
is indeed a definition but it is a definition of a *pointer* to your (earlier declared) struct. It declares the name 'list' and it also reserves memory for the *address* that may point to an object of your struct *after* it is defined. So it does *not* in fact define the actual struct. It does not create an object described by your structure — it does not reserve/allocate memory for such an object. |
38,194,057 | How do I declare, versus define a struct, such as for data shared between multiple files. I understand the idea when defining primitives. So, for example, I might have:
```
extern int myvalue; /* in shared header file */
```
and
```
int myvalue = 5; /* in data.c file */
```
But, how do I do the same thing for structs. For example, if I have the following type:
```
typedef struct {
size_t size;
char * strings[];
} STRLIST;
```
If I then use the statement:
```
STRLIST list;
```
This is both a declaration and definition. So, how do apply the same principle of using an extern? | 2016/07/05 | [
"https://Stackoverflow.com/questions/38194057",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1655700/"
] | To declare an *instance of* a struct (or a pointer to one):
```
extern STRLIST* ptrList;
extern STRLIST list;
```
To define it:
```
STRLIST* ptrList;
STRLIST list;
```
To declare a *struct type*:
```
typedef struct STRLIST;
```
To define it:
```
typedef struct {
size_t size;
char * strings[];
} STRLIST;
```
Note that you can use a pointer to a struct with only a declaration, but you must have a definition to use the struct directly. | Just a small clarification to dbush's answer:
From the latest C standard (Feb 2020):
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2494.pdf>
>
> 6.7.2.1 Structure and union specifiers (p1)
>
>
> Syntax
>
>
> 1 struct-or-union-specifier:
>
>
> struct-or-union attribute-specifier-sequenceopt identifieropt {
> member-declaration-list }
>
>
>
In conclusion, the part:
```
struct STRLIST{
size_t size;
char * strings[];
};
```
Is your struct's declaration.
Adding the typedef, defines the *type* STRLIST:
```
typedef struct {
size_t size;
char * strings[];
} STRLIST;
```
And this is your definition:
```
STRLIST list;
```
Rule of thumb: a definition provides memory to the instance. a declaration doesn't. |
38,194,057 | How do I declare, versus define a struct, such as for data shared between multiple files. I understand the idea when defining primitives. So, for example, I might have:
```
extern int myvalue; /* in shared header file */
```
and
```
int myvalue = 5; /* in data.c file */
```
But, how do I do the same thing for structs. For example, if I have the following type:
```
typedef struct {
size_t size;
char * strings[];
} STRLIST;
```
If I then use the statement:
```
STRLIST list;
```
This is both a declaration and definition. So, how do apply the same principle of using an extern? | 2016/07/05 | [
"https://Stackoverflow.com/questions/38194057",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1655700/"
] | Every name in C, before it is used, has to be declared. To declare is (just) to explain what type the name describes. This is information for the compiler how to treat the object of this name.
Definition, on the other hand, instructs the compiler to reserve memory for the object. A definition is always also a declaration.
In your case, the statement:
```
STRLIST* list;
```
is indeed a definition but it is a definition of a *pointer* to your (earlier declared) struct. It declares the name 'list' and it also reserves memory for the *address* that may point to an object of your struct *after* it is defined. So it does *not* in fact define the actual struct. It does not create an object described by your structure — it does not reserve/allocate memory for such an object. | Just a small clarification to dbush's answer:
From the latest C standard (Feb 2020):
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2494.pdf>
>
> 6.7.2.1 Structure and union specifiers (p1)
>
>
> Syntax
>
>
> 1 struct-or-union-specifier:
>
>
> struct-or-union attribute-specifier-sequenceopt identifieropt {
> member-declaration-list }
>
>
>
In conclusion, the part:
```
struct STRLIST{
size_t size;
char * strings[];
};
```
Is your struct's declaration.
Adding the typedef, defines the *type* STRLIST:
```
typedef struct {
size_t size;
char * strings[];
} STRLIST;
```
And this is your definition:
```
STRLIST list;
```
Rule of thumb: a definition provides memory to the instance. a declaration doesn't. |
25,912 | There is a dataset that contains body mass ($x$) and metabolic rate ($y$) from many different organisms. It is common to fit the data to the model of the form $y=ax^b$ and estimate the parameters $a$ and $b$ (see [Kleiber's law](http://en.wikipedia.org/wiki/Kleiber%27s_law) and [The Metabolic theory of ecology](http://en.wikipedia.org/wiki/Metabolic_theory_of_ecology)). In doing so, it is also common to log transform $y$ and $x$ and create the linear relationship log($y$)=log($a$)+$b$log($x$) and perform linear regression analysis based on the log transformed data. Is this approach better than directly estimating $a$ and $b$ based on nonlinear regression for $y=ax^b$ (because results are different)? | 2014/12/16 | [
"https://biology.stackexchange.com/questions/25912",
"https://biology.stackexchange.com",
"https://biology.stackexchange.com/users/11555/"
] | **Short answer**: The results of the two approaches (linear versus non-linear model) do not match because the relationship between body mass and basal metabolic rate does not strictly follow a power law.
---
It is indeed the case that if the relationship between two variables follows a power law the two approaches should provide comparable results, but important differences could arise due to [Jensen's inequality](https://stats.stackexchange.com/a/58077/97671). In order to test whether the reported differences between the two approaches are due to Jensen's inequality or to some biological factor I obtained data from [Kolokotrones et al. (2010)](https://www.nature.com/nature/journal/v464/n7289/full/nature08920.html) who have in turn taken them from [McNab (2008)](http://www.sciencedirect.com/science/article/pii/S1095643308007782). [Kolokotrones et al. (2010)](https://www.nature.com/nature/journal/v464/n7289/full/nature08920.html) investigated the issue of whether a power law is appropriate by performing linear regression on log-transformed data but they did not attempt to fit the data with non-linear regression.
I've fitted a non-linear model of the form:
$$ B = \alpha M^b$$ , where $M$ the body mass (in grams) and $B$ the basal metabolic rate (in Watts),
which gave coefficients $\alpha = 0.005$ and $b = 0.87$.
I also fitted a linear model of the form:
$$ log\_{10}(B) = blog\_{10}(M) + log\_{10}(\alpha) $$
which gave coefficients $ \alpha = -1.7 $ and $ b = 0.72 $.
It appears that the results of the two approaches are indeed different. Below I plot the results of the two fits. On the variables' original scale we see that the linear model fails to predict observations from species with large mass and that the non-linear model does much better in this respect (upper left). However, when we look at the two models after log-transform, it is clear that the non-linear model fails to predict many observations from species with low mass (upper right). Looking at the residuals of the non-linear model we see that the errors are multiplicative as the variance of the residuals is increasing with (log-transformed) fitted values (bottom left). This indicates that fitting with a linear model on log-transformed data is warranted. However, the plot of linear model's residuals over log-transformed fitted values (bottom right) confirms that the linearity assumption is violated. Thus, neither method is appropriate for this dataset and the quadratic term the authors of the cited paper added in the linear model fitted on the log-transformed variables appears to be warranted in order to account for the observed convexity.
[](https://i.stack.imgur.com/LGbf5.png)
We can conclude that for this dataset the results of the linear model approach do not match those of the non-linear model approach because *the data do not strictly follow a power law*. Rather, the megafauna appears to follow a different trend compared to smaller animals. [Kolokotrones et al. (2010)](https://www.nature.com/nature/journal/v464/n7289/full/nature08920.html) found that adjusting for temperature improved the linear fit, in addition to the inclusion of the quadratic term. The resulting model was:
$$ log\_{10}B = \beta\_0 + \beta\_1log\_{10}M + \beta\_2(log\_{10}M)^2 + \frac{\beta\_T}{T} + \epsilon $$
The R code used to generate the results for this answer along with the data used can be found in the following git repository in GitLab:
<https://gitlab.com/vkehayas-public/metabolic_scaling>
**References**
Kolokotrones, T., Van Savage, Deeds, E. J., & Fontana, W. (2010).
Curvature in metabolic scaling. *Nature*, **464**:7289, 753–756. [https://doi.org/10.1038/nature08920](https://www.nature.com/nature/journal/v464/n7289/full/nature08920.html)
McNab, B.K. (2008). An analysis of the factors that influence the level and scaling of mammalian BMR. *Comparative Biochemistry and Physiology Part A: Molecular & Integrative Physiology*, **151**:1, 5-28. [https://doi.org/10.1016/j.cbpa.2008.05.008](http://www.sciencedirect.com/science/article/pii/S1095643308007782). | What will happen during log-conversion is that the large scale variation that happens in data points with high value will be compressed. This will actually produce an estimate that should be more robust toward outliers (because their deviation from the mean will be compressed).
If the data was perfectly modeled (i.e. no or few errors) then it should not matter.
With that said, I don't expect major differences between the two approaches. |
11,003,318 | I am trying to make a gridview with large icon for an app but I couldn't find any tutorial about modifying a cell size on a grid layout on android. Can anyone give me an example or a link about it please?
Thanks. | 2012/06/12 | [
"https://Stackoverflow.com/questions/11003318",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/869360/"
] | just like the other [adapterViews](http://developer.android.com/reference/android/widget/AdapterView.html) ,on gridView (which extends adapterView) the size that is determined of the children is based on the size that they want to become , as written in the android API:
>
> An AdapterView is a view whose children are determined by an Adapter.
>
>
> | Did you try `android:numColumns="2"` |
57,340,976 | I have the following list:
```
<ul class="nav nav-pills nav-pills-warning nav-pills-icons justify-content-center" role="tablist">
<li class="nav-item">
<a class="nav-link" data-toggle="tab" data-role-slug="admin" href="#" "="" role="tablist">
<i class="material-icons">supervisor_account</i> Admins
</a>
</li>
<li class="nav-item">
<a class="nav-link active show" data-toggle="tab" data-role-slug="operator" href="#" role="tablist">
<i class="material-icons">person</i> Operators
</a>
</li>
</ul>
```
I need to get the attribute `data-role-slug` I actually get the value in the following way:
```
$('a[data-role-slug]').on('click', function (e) {
let roleSlug = $(e.target).data('role-slug');
console.log(roleSlug);
});
```
the method works well, the only problem happen when the user click on the `<i>` tag inside the `<a>` tag, in that case the `roleSlug` will be `undefined`.
Is there a way to handle this issue without hard code? | 2019/08/03 | [
"https://Stackoverflow.com/questions/57340976",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10950788/"
] | Just use `this` inside the event handler. It will be the `<a>` instance the event occurred on regardless of what child is targeted
Or alternatively `e.currentTarget` will return the same instance as well
```
$('a[data-role-slug]').on('click', function (e) {
let roleSlug = $(this).data('role-slug');
// OR $(e.currentTarget).data('role-slug');
console.log(roleSlug);
});
``` | That's because the target of an event is the element that actually received it, not the one is bubbled up to.
However you can try to be sneaky, maybe try something like this ?
```
$('a[data-role-slug]').each((index, element) => {
element.on('click', () => {
let roleSlug = element.data('role-slug');
console.log(roleSlug);
});
});
```
Alternatively you can use the `.parent` method to find the right element
```
$('a[data-role-slug]').on('click', function (e) {
let roleSlug = $(e.target).data('role-slug');
if (!roleSlug) {
roleSlug = $(e.target).parent('a[data-role-slug]').data('role-slug');
}
console.log(roleSlug);
});
``` |
1,068,974 | I have a PL/SQL function in an Oracle database that I can't change. This function takes a parameter which identifies an entity, creates a copy of that entity and then returns the ID of the copy. This looks something like
FUNCTION copy\_entity(id IN NUMBER) RETURN NUMBER
I need to call this function from Hibernate. I tried creating a named SQL query with something similar to
CALL copy\_entity(:id)
as the query, but from this I can't seem to get the return value of the function. Hibernate's "return-scalar" and similar options require a column name to return and I don't have a column name. This lead me to
SELECT copy\_entity(:id) AS newEntityId
with "return-scalar" using newEntityId as column name, but this also did not work since Oracle then throws an exception that I can't call INSERT (to save the copy) in a SELECT.
Is there any way to get the return value of such a PL/SQL function? The function is actually much more complex and still required in other parts of the app, so re-writing it is not really an option. | 2009/07/01 | [
"https://Stackoverflow.com/questions/1068974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3587/"
] | The problem is that ie6/ie7 will expand an empty element to the height of your font. You can get around this by adding `font-size:0` and `line-height:0` to `.menu ul li.separator`.
A better solution would be to add a thicker bottom border to the `<li>` that is before the separator.
```
.menu ul li.sep {border-bottom-width:6px}
<div class="menu">
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li class="sep"><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
<li><a href="#">Item 5</a></li>
<li><a href="#">Item 6</a></li>
</ul>
</div>
``` | Maybe you should try setting your `li` as follows:
```
li{
display:block;
float:left;
height:myHeight;
clear:right;//may be necessary, can't check with IE7
}
```
This is what I've done with similar problems. |
1,068,974 | I have a PL/SQL function in an Oracle database that I can't change. This function takes a parameter which identifies an entity, creates a copy of that entity and then returns the ID of the copy. This looks something like
FUNCTION copy\_entity(id IN NUMBER) RETURN NUMBER
I need to call this function from Hibernate. I tried creating a named SQL query with something similar to
CALL copy\_entity(:id)
as the query, but from this I can't seem to get the return value of the function. Hibernate's "return-scalar" and similar options require a column name to return and I don't have a column name. This lead me to
SELECT copy\_entity(:id) AS newEntityId
with "return-scalar" using newEntityId as column name, but this also did not work since Oracle then throws an exception that I can't call INSERT (to save the copy) in a SELECT.
Is there any way to get the return value of such a PL/SQL function? The function is actually much more complex and still required in other parts of the app, so re-writing it is not really an option. | 2009/07/01 | [
"https://Stackoverflow.com/questions/1068974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3587/"
] | The problem is that ie6/ie7 will expand an empty element to the height of your font. You can get around this by adding `font-size:0` and `line-height:0` to `.menu ul li.separator`.
A better solution would be to add a thicker bottom border to the `<li>` that is before the separator.
```
.menu ul li.sep {border-bottom-width:6px}
<div class="menu">
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li class="sep"><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
<li><a href="#">Item 5</a></li>
<li><a href="#">Item 6</a></li>
</ul>
</div>
``` | Set your css for the LI to `display: block;`. |
1,068,974 | I have a PL/SQL function in an Oracle database that I can't change. This function takes a parameter which identifies an entity, creates a copy of that entity and then returns the ID of the copy. This looks something like
FUNCTION copy\_entity(id IN NUMBER) RETURN NUMBER
I need to call this function from Hibernate. I tried creating a named SQL query with something similar to
CALL copy\_entity(:id)
as the query, but from this I can't seem to get the return value of the function. Hibernate's "return-scalar" and similar options require a column name to return and I don't have a column name. This lead me to
SELECT copy\_entity(:id) AS newEntityId
with "return-scalar" using newEntityId as column name, but this also did not work since Oracle then throws an exception that I can't call INSERT (to save the copy) in a SELECT.
Is there any way to get the return value of such a PL/SQL function? The function is actually much more complex and still required in other parts of the app, so re-writing it is not really an option. | 2009/07/01 | [
"https://Stackoverflow.com/questions/1068974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3587/"
] | The problem is that ie6/ie7 will expand an empty element to the height of your font. You can get around this by adding `font-size:0` and `line-height:0` to `.menu ul li.separator`.
A better solution would be to add a thicker bottom border to the `<li>` that is before the separator.
```
.menu ul li.sep {border-bottom-width:6px}
<div class="menu">
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li class="sep"><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
<li><a href="#">Item 5</a></li>
<li><a href="#">Item 6</a></li>
</ul>
</div>
``` | In addition to Daniel A. White answer you can experiment with line-height to center your text vertically and create the necessary height. |
1,068,974 | I have a PL/SQL function in an Oracle database that I can't change. This function takes a parameter which identifies an entity, creates a copy of that entity and then returns the ID of the copy. This looks something like
FUNCTION copy\_entity(id IN NUMBER) RETURN NUMBER
I need to call this function from Hibernate. I tried creating a named SQL query with something similar to
CALL copy\_entity(:id)
as the query, but from this I can't seem to get the return value of the function. Hibernate's "return-scalar" and similar options require a column name to return and I don't have a column name. This lead me to
SELECT copy\_entity(:id) AS newEntityId
with "return-scalar" using newEntityId as column name, but this also did not work since Oracle then throws an exception that I can't call INSERT (to save the copy) in a SELECT.
Is there any way to get the return value of such a PL/SQL function? The function is actually much more complex and still required in other parts of the app, so re-writing it is not really an option. | 2009/07/01 | [
"https://Stackoverflow.com/questions/1068974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3587/"
] | The problem is that ie6/ie7 will expand an empty element to the height of your font. You can get around this by adding `font-size:0` and `line-height:0` to `.menu ul li.separator`.
A better solution would be to add a thicker bottom border to the `<li>` that is before the separator.
```
.menu ul li.sep {border-bottom-width:6px}
<div class="menu">
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li class="sep"><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
<li><a href="#">Item 5</a></li>
<li><a href="#">Item 6</a></li>
</ul>
</div>
``` | Have you tried adding a `line-height` attribute to `.menu ul li`?
Else have you tried using horizontal rule `<hr>` as a separator instead? If you're using horizontal rule, you can set the `margin-top` and `margin-bottom` to `0px` and see what happens. Can't guarantee it looks the same on IE and other browsers, but at least you tried. =) |
1,068,974 | I have a PL/SQL function in an Oracle database that I can't change. This function takes a parameter which identifies an entity, creates a copy of that entity and then returns the ID of the copy. This looks something like
FUNCTION copy\_entity(id IN NUMBER) RETURN NUMBER
I need to call this function from Hibernate. I tried creating a named SQL query with something similar to
CALL copy\_entity(:id)
as the query, but from this I can't seem to get the return value of the function. Hibernate's "return-scalar" and similar options require a column name to return and I don't have a column name. This lead me to
SELECT copy\_entity(:id) AS newEntityId
with "return-scalar" using newEntityId as column name, but this also did not work since Oracle then throws an exception that I can't call INSERT (to save the copy) in a SELECT.
Is there any way to get the return value of such a PL/SQL function? The function is actually much more complex and still required in other parts of the app, so re-writing it is not really an option. | 2009/07/01 | [
"https://Stackoverflow.com/questions/1068974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3587/"
] | The problem is that ie6/ie7 will expand an empty element to the height of your font. You can get around this by adding `font-size:0` and `line-height:0` to `.menu ul li.separator`.
A better solution would be to add a thicker bottom border to the `<li>` that is before the separator.
```
.menu ul li.sep {border-bottom-width:6px}
<div class="menu">
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li class="sep"><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
<li><a href="#">Item 5</a></li>
<li><a href="#">Item 6</a></li>
</ul>
</div>
``` | Do what was suggested in the previous posts. If these changes are causing issues in browsers other than IE, you can do the following to have only IE use them:
```
.selector {
prop1 : val1; /* default value for all browsers */
*prop1 : val2; /* only IE will pick this one up and it will override the initial value of prop1. */
}
```
This works much better than trying to do special commenting to include separate style sheets, etc. |
1,068,974 | I have a PL/SQL function in an Oracle database that I can't change. This function takes a parameter which identifies an entity, creates a copy of that entity and then returns the ID of the copy. This looks something like
FUNCTION copy\_entity(id IN NUMBER) RETURN NUMBER
I need to call this function from Hibernate. I tried creating a named SQL query with something similar to
CALL copy\_entity(:id)
as the query, but from this I can't seem to get the return value of the function. Hibernate's "return-scalar" and similar options require a column name to return and I don't have a column name. This lead me to
SELECT copy\_entity(:id) AS newEntityId
with "return-scalar" using newEntityId as column name, but this also did not work since Oracle then throws an exception that I can't call INSERT (to save the copy) in a SELECT.
Is there any way to get the return value of such a PL/SQL function? The function is actually much more complex and still required in other parts of the app, so re-writing it is not really an option. | 2009/07/01 | [
"https://Stackoverflow.com/questions/1068974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3587/"
] | Set your css for the LI to `display: block;`. | Have you tried adding a `line-height` attribute to `.menu ul li`?
Else have you tried using horizontal rule `<hr>` as a separator instead? If you're using horizontal rule, you can set the `margin-top` and `margin-bottom` to `0px` and see what happens. Can't guarantee it looks the same on IE and other browsers, but at least you tried. =) |
1,068,974 | I have a PL/SQL function in an Oracle database that I can't change. This function takes a parameter which identifies an entity, creates a copy of that entity and then returns the ID of the copy. This looks something like
FUNCTION copy\_entity(id IN NUMBER) RETURN NUMBER
I need to call this function from Hibernate. I tried creating a named SQL query with something similar to
CALL copy\_entity(:id)
as the query, but from this I can't seem to get the return value of the function. Hibernate's "return-scalar" and similar options require a column name to return and I don't have a column name. This lead me to
SELECT copy\_entity(:id) AS newEntityId
with "return-scalar" using newEntityId as column name, but this also did not work since Oracle then throws an exception that I can't call INSERT (to save the copy) in a SELECT.
Is there any way to get the return value of such a PL/SQL function? The function is actually much more complex and still required in other parts of the app, so re-writing it is not really an option. | 2009/07/01 | [
"https://Stackoverflow.com/questions/1068974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3587/"
] | Set your css for the LI to `display: block;`. | Do what was suggested in the previous posts. If these changes are causing issues in browsers other than IE, you can do the following to have only IE use them:
```
.selector {
prop1 : val1; /* default value for all browsers */
*prop1 : val2; /* only IE will pick this one up and it will override the initial value of prop1. */
}
```
This works much better than trying to do special commenting to include separate style sheets, etc. |
1,068,974 | I have a PL/SQL function in an Oracle database that I can't change. This function takes a parameter which identifies an entity, creates a copy of that entity and then returns the ID of the copy. This looks something like
FUNCTION copy\_entity(id IN NUMBER) RETURN NUMBER
I need to call this function from Hibernate. I tried creating a named SQL query with something similar to
CALL copy\_entity(:id)
as the query, but from this I can't seem to get the return value of the function. Hibernate's "return-scalar" and similar options require a column name to return and I don't have a column name. This lead me to
SELECT copy\_entity(:id) AS newEntityId
with "return-scalar" using newEntityId as column name, but this also did not work since Oracle then throws an exception that I can't call INSERT (to save the copy) in a SELECT.
Is there any way to get the return value of such a PL/SQL function? The function is actually much more complex and still required in other parts of the app, so re-writing it is not really an option. | 2009/07/01 | [
"https://Stackoverflow.com/questions/1068974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3587/"
] | Maybe you should try setting your `li` as follows:
```
li{
display:block;
float:left;
height:myHeight;
clear:right;//may be necessary, can't check with IE7
}
```
This is what I've done with similar problems. | In addition to Daniel A. White answer you can experiment with line-height to center your text vertically and create the necessary height. |
1,068,974 | I have a PL/SQL function in an Oracle database that I can't change. This function takes a parameter which identifies an entity, creates a copy of that entity and then returns the ID of the copy. This looks something like
FUNCTION copy\_entity(id IN NUMBER) RETURN NUMBER
I need to call this function from Hibernate. I tried creating a named SQL query with something similar to
CALL copy\_entity(:id)
as the query, but from this I can't seem to get the return value of the function. Hibernate's "return-scalar" and similar options require a column name to return and I don't have a column name. This lead me to
SELECT copy\_entity(:id) AS newEntityId
with "return-scalar" using newEntityId as column name, but this also did not work since Oracle then throws an exception that I can't call INSERT (to save the copy) in a SELECT.
Is there any way to get the return value of such a PL/SQL function? The function is actually much more complex and still required in other parts of the app, so re-writing it is not really an option. | 2009/07/01 | [
"https://Stackoverflow.com/questions/1068974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3587/"
] | Maybe you should try setting your `li` as follows:
```
li{
display:block;
float:left;
height:myHeight;
clear:right;//may be necessary, can't check with IE7
}
```
This is what I've done with similar problems. | Do what was suggested in the previous posts. If these changes are causing issues in browsers other than IE, you can do the following to have only IE use them:
```
.selector {
prop1 : val1; /* default value for all browsers */
*prop1 : val2; /* only IE will pick this one up and it will override the initial value of prop1. */
}
```
This works much better than trying to do special commenting to include separate style sheets, etc. |
1,068,974 | I have a PL/SQL function in an Oracle database that I can't change. This function takes a parameter which identifies an entity, creates a copy of that entity and then returns the ID of the copy. This looks something like
FUNCTION copy\_entity(id IN NUMBER) RETURN NUMBER
I need to call this function from Hibernate. I tried creating a named SQL query with something similar to
CALL copy\_entity(:id)
as the query, but from this I can't seem to get the return value of the function. Hibernate's "return-scalar" and similar options require a column name to return and I don't have a column name. This lead me to
SELECT copy\_entity(:id) AS newEntityId
with "return-scalar" using newEntityId as column name, but this also did not work since Oracle then throws an exception that I can't call INSERT (to save the copy) in a SELECT.
Is there any way to get the return value of such a PL/SQL function? The function is actually much more complex and still required in other parts of the app, so re-writing it is not really an option. | 2009/07/01 | [
"https://Stackoverflow.com/questions/1068974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3587/"
] | Set your css for the LI to `display: block;`. | In addition to Daniel A. White answer you can experiment with line-height to center your text vertically and create the necessary height. |
20,826,290 | I'm trying to merge a two ImageViews to make them look like as one, but there's bounding box that prevents them to be totally next to each other.

```
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/plant" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/red_base" />
```
I tried setting padding and margin to 0 but it doesn't do it
Note: those two pictures that I used don't have a blank space around them.
Thanks! | 2013/12/29 | [
"https://Stackoverflow.com/questions/20826290",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1426489/"
] | ```
set below two properties
android:adjustViewBounds="true"
android:scaleType="fitEnd"
``` | in android gives some default padding 8dp for view:
try this:
```
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="-4dp"
android:src="@drawable/plant" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="-4dp"
android:src="@drawable/red_base" />
``` |
20,826,290 | I'm trying to merge a two ImageViews to make them look like as one, but there's bounding box that prevents them to be totally next to each other.

```
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/plant" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/red_base" />
```
I tried setting padding and margin to 0 but it doesn't do it
Note: those two pictures that I used don't have a blank space around them.
Thanks! | 2013/12/29 | [
"https://Stackoverflow.com/questions/20826290",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1426489/"
] | ```
set below two properties
android:adjustViewBounds="true"
android:scaleType="fitEnd"
``` | Set top margin for the below image as -5 dp i.e. `android:layout_marginTop="-5dp"`
Below is your updated code
```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/icon" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="-25dp"
android:src="@drawable/icon" />
</LinearLayout>
```
\*Updated margin to -25dp, just to observe the change. |
20,826,290 | I'm trying to merge a two ImageViews to make them look like as one, but there's bounding box that prevents them to be totally next to each other.

```
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/plant" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/red_base" />
```
I tried setting padding and margin to 0 but it doesn't do it
Note: those two pictures that I used don't have a blank space around them.
Thanks! | 2013/12/29 | [
"https://Stackoverflow.com/questions/20826290",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1426489/"
] | ```
set below two properties
android:adjustViewBounds="true"
android:scaleType="fitEnd"
``` | You need to set the [scaleType](http://developer.android.com/reference/android/widget/ImageView.html#attr_android%3ascaleType) property of the ImageView. |
20,826,290 | I'm trying to merge a two ImageViews to make them look like as one, but there's bounding box that prevents them to be totally next to each other.

```
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/plant" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/red_base" />
```
I tried setting padding and margin to 0 but it doesn't do it
Note: those two pictures that I used don't have a blank space around them.
Thanks! | 2013/12/29 | [
"https://Stackoverflow.com/questions/20826290",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1426489/"
] | ```
set below two properties
android:adjustViewBounds="true"
android:scaleType="fitEnd"
``` | Push them to relative layout and place them manually, some thing like this:
```
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_marginTop="180dp"
android:src="@drawable/plant" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:src="@drawable/red_base" />
</RelativeLayout>
``` |
20,826,290 | I'm trying to merge a two ImageViews to make them look like as one, but there's bounding box that prevents them to be totally next to each other.

```
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/plant" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/red_base" />
```
I tried setting padding and margin to 0 but it doesn't do it
Note: those two pictures that I used don't have a blank space around them.
Thanks! | 2013/12/29 | [
"https://Stackoverflow.com/questions/20826290",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1426489/"
] | in android gives some default padding 8dp for view:
try this:
```
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="-4dp"
android:src="@drawable/plant" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="-4dp"
android:src="@drawable/red_base" />
``` | Set top margin for the below image as -5 dp i.e. `android:layout_marginTop="-5dp"`
Below is your updated code
```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/icon" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="-25dp"
android:src="@drawable/icon" />
</LinearLayout>
```
\*Updated margin to -25dp, just to observe the change. |
20,826,290 | I'm trying to merge a two ImageViews to make them look like as one, but there's bounding box that prevents them to be totally next to each other.

```
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/plant" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/red_base" />
```
I tried setting padding and margin to 0 but it doesn't do it
Note: those two pictures that I used don't have a blank space around them.
Thanks! | 2013/12/29 | [
"https://Stackoverflow.com/questions/20826290",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1426489/"
] | in android gives some default padding 8dp for view:
try this:
```
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="-4dp"
android:src="@drawable/plant" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="-4dp"
android:src="@drawable/red_base" />
``` | You need to set the [scaleType](http://developer.android.com/reference/android/widget/ImageView.html#attr_android%3ascaleType) property of the ImageView. |
20,826,290 | I'm trying to merge a two ImageViews to make them look like as one, but there's bounding box that prevents them to be totally next to each other.

```
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/plant" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/red_base" />
```
I tried setting padding and margin to 0 but it doesn't do it
Note: those two pictures that I used don't have a blank space around them.
Thanks! | 2013/12/29 | [
"https://Stackoverflow.com/questions/20826290",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1426489/"
] | in android gives some default padding 8dp for view:
try this:
```
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="-4dp"
android:src="@drawable/plant" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="0dp"
android:padding="-4dp"
android:src="@drawable/red_base" />
``` | Push them to relative layout and place them manually, some thing like this:
```
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_marginTop="180dp"
android:src="@drawable/plant" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:src="@drawable/red_base" />
</RelativeLayout>
``` |
248,370 | I want to build a flat ground level deck approx 25x26ft. I have very limited space between the ground and the door, so it needs to be streamlined.
I plan to use 3 26’ 2x10 as primary frame supports and than use 12’ 2x10 as joists with 12” spacing.
Wondering how many posts do I need for each 26’ piece of lumber? Will 4 posts for each 26’ (6-1/2 apart) be enough?
Also, will 12’ span for joists cause any issue?
[](https://i.stack.imgur.com/qlMqH.jpg) | 2022/04/27 | [
"https://diy.stackexchange.com/questions/248370",
"https://diy.stackexchange.com",
"https://diy.stackexchange.com/users/25752/"
] | Contact your power company. Say:
"Am I correct that my smart meter has a large contactor in it, so that you can remotely shut off my power with a few keystrokes on your computer?"
And
"If I have you do that for 10 minutes, will you require a permit and inspection to turn it back on?"
And this may lead to a short conversation about exactly what it is that you are doing, and they are likely to say "Oh. That's fine."
At which point, have them de-energize; check that it is de-energized; do your thing and call them to turn it back on.
Note that this uses "Ethernet over Powerline" communication at grand scale which means *grandly bad* bit rate on a rather busy comm channel. So it can take some minutes for the command to actually get through the queue. | There's a couple of ways to play this, assuming you don't want to just YOLO this and shove them on with your bare hand (not the greatest idea)
1. Ask your utility to kill the power to your house for a few minutes. They might not like coming out for something this minor, but I can't say how well this will or won't go. Your mileage will vary greatly here. This is, hands down, the safest way to do it, though.
2. Buy some lineman rubber gloves and shove them on. You can buy them commercially. Not as safe as having a dead panel, but the gloves are designed to come into contact with much higher voltage live wires than what your panel will ever see. These aren't crazy expensive, but you might not ever have another use for them (unless you like working on live panels for some odd reason) |
36,552,197 | I'm trying to implement a Fast Fourier Transform (Radix-2) in MS's Excel VBA. The code I'm using pulls data from a range in the worksheet, does the calculations, then dumps the results in the adjacent columns. What I'm having trouble with is 1) know what to do with the resulting X[k] arrays, and 2) matching these results with the results from Excel's built in FFT (they do not currently match). The code is shown below. Thanks in advance for your help.
```
Sub Enforce_DecimationInTime()
On Error GoTo ERROR_HANDLING
Dim SubName As String
SubName = "Enforce_DecimationInTime()"
Dim WS As Worksheet
Dim n As Long, v As Long, LR As Long, x As Long
Set WS = Worksheets("FFT")
LR = WS.Range("A" & Rows.Count).End(xlUp).Row
n = LR - 1
Do Until 2 ^ x <= n And 2 ^ (x + 1) > n 'locates largest power of 2 from size of input array
x = x + 1
Loop
n = n - (n - 2 ^ x) 'calculates n using the largest power of 2
If n + 1 <> WS.Range("A" & Rows.Count).End(xlUp).Row Then
WS.Range("A" & 2 ^ x + 2 & ":A" & LR).Delete xlUp 'deletes extra input data
End If
v = WorksheetFunction.Log(n, 2) 'calculates number of decimations necessary
Application.ScreenUpdating = False
For x = 1 To v
Call Called_Core.DecimationInTime(WS, n, 2 ^ x, x) 'calls decimation in time subroutine
Next x
Application.ScreenUpdating = True
Exit Sub
ERROR_HANDLING:
MsgBox "Error encountered in " & SubName & ": exiting subroutine." _
& vbNewLine _
& vbNewLine & "Error description: " & Err.Description _
& vbNewLine & "Error number: " & Err.Number, vbCritical, Title:="Error!"
End
End Sub
```
The above subroutine calls the below subroutine through a For/Next loop to the count of "v".
```
Sub DecimationInTime(WS As Worksheet, n As Long, Factor As Integer, x As Long)
On Error GoTo ERROR_HANDLING
Dim SubName As String
SubName = "DecimationInTime()"
Dim f_1() As Single, f_2() As Single
Dim i As Long, m As Long, k As Long
Dim TFactor_N1 As String, TFactor_N2 As String, X_k() As String
Dim G_1() As Variant, G_2() As Variant
ReDim f_1(0 To n / Factor - 1) As Single
ReDim f_2(0 To n / Factor - 1) As Single
ReDim G_1(0 To n / 1 - 1) As Variant
ReDim G_2(0 To n / 1 - 1) As Variant
ReDim X_k(0 To n - 1) As String
TFactor_N1 = WorksheetFunction.Complex(0, -2 * WorksheetFunction.Pi / (n / 1)) 'twiddle factor for N
TFactor_N2 = WorksheetFunction.Complex(0, -2 * WorksheetFunction.Pi / (n / 2)) 'twiddle factor for N/2
For i = 0 To n / Factor - 1
f_1(i) = WS.Range("A" & 2 * i + 2).Value 'assign input data
f_2(i) = WS.Range("A" & 2 * i + 3).Value 'assign input data
Next i
WS.Cells(1, 1 + x).Value = "X[" & x & "]" 'labels X[k] column with k number
For k = 0 To n / 2 - 1
For m = 0 To n / Factor - 1
G_1(m) = WorksheetFunction.ImProduct(WorksheetFunction.ImPower(TFactor_N2, k * m), WorksheetFunction.Complex(f_1(m), 0)) 'defines G_1[m]
G_2(m) = WorksheetFunction.ImProduct(WorksheetFunction.ImPower(TFactor_N2, k * m), WorksheetFunction.Complex(f_2(m), 0)) 'defines G_2[m]
Next m
X_k(k) = WorksheetFunction.ImSum(WorksheetFunction.ImSum(G_1), WorksheetFunction.ImProduct(WorksheetFunction.ImSum(G_2), WorksheetFunction.ImPower(TFactor_N1, k))) 'defines X[k] for k
If k <= n / 2 Then X_k(k + n / 2) = WorksheetFunction.ImSum(WorksheetFunction.ImSum(G_1), WorksheetFunction.ImProduct(WorksheetFunction.ImSum(G_2), WorksheetFunction.ImPower(TFactor_N1, k), WorksheetFunction.Complex(-1, 0))) 'defines X[k] for k + n/2
WS.Cells(k + 2, 1 + x).Value = X_k(k)
WS.Cells(k + 2 + n / 2, 1 + x).Value = X_k(k + n / 2)
Next k
Exit Sub
ERROR_HANDLING:
MsgBox "Error encountered in " & SubName & ": exiting subroutine." _
& vbNewLine _
& vbNewLine & "Error description: " & Err.Description _
& vbNewLine & "Error number: " & Err.Number, vbCritical, Title:="Error!"
End
End Sub
``` | 2016/04/11 | [
"https://Stackoverflow.com/questions/36552197",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5748328/"
] | I went back through the process and determined my problem was that I had assigned the wrong values to the twiddle factors, TFactor\_N1 and TFactor\_N2. After fixing this problem and adjusting which values are displayed, I was able to get the same results as Excel's built in FFT. The fixed code is show below.
```
Sub Enforce_DecimationInTime()
On Error GoTo ERROR_HANDLING
Dim SubName As String
SubName = "Enforce_DecimationInTime()"
Dim WS As Worksheet
Dim n As Long, v As Long, LR As Long, x As Long
Dim TFactor_N1 As String, TFactor_N2 As String
Set WS = Worksheets("FFT")
LR = WS.Range("A" & Rows.Count).End(xlUp).Row
n = LR - 1
Do Until 2 ^ x <= n And 2 ^ (x + 1) > n 'locates largest power of 2 from size of input array
x = x + 1
Loop
n = n - (n - 2 ^ x) 'calculates n using the largest power of 2
If n + 1 <> WS.Range("A" & Rows.Count).End(xlUp).Row Then
WS.Range("A" & 2 ^ x + 2 & ":A" & LR).Delete xlUp 'deletes extra input data
End If
v = WorksheetFunction.Log(n, 2) 'calculates number of decimations necessary
TFactor_N1 = WorksheetFunction.ImExp(WorksheetFunction.Complex(0, -2 * WorksheetFunction.Pi / (n / 1))) 'twiddle factor for N
TFactor_N2 = WorksheetFunction.ImExp(WorksheetFunction.Complex(0, -2 * WorksheetFunction.Pi / (n / 2))) 'twiddle factor for N/2
Application.ScreenUpdating = False
For x = 1 To v
Call Called_Core.DecimationInTime(WS, n, 2 ^ x, x, TFactor_N1, TFactor_N2) 'calls decimation in time subroutine
Next x
Application.ScreenUpdating = True
Exit Sub
ERROR_HANDLING:
MsgBox "Error encountered in " & SubName & ": exiting subroutine." _
& vbNewLine _
& vbNewLine & "Error description: " & Err.Description _
& vbNewLine & "Error number: " & Err.Number, vbCritical, Title:="Error!"
End
End Sub
Sub DecimationInTime(WS As Worksheet, n As Long, Factor As Integer, x As Long, TFactor_N1 As String, TFactor_N2 As String)
On Error GoTo ERROR_HANDLING
Dim SubName As String
SubName = "DecimationInTime()"
Dim f_1() As String, f_2() As String
Dim i As Long, m As Long, k As Long
Dim X_k() As String
Dim G_1() As Variant, G_2() As Variant
ReDim f_1(0 To n / Factor - 1) As String
ReDim f_2(0 To n / Factor - 1) As String
ReDim G_1(0 To n / 1 - 1) As Variant
ReDim G_2(0 To n / 1 - 1) As Variant
ReDim X_k(0 To n - 1) As String
For i = 0 To n / Factor - 1
f_1(i) = WS.Cells(2 * i + 2, 1).Value 'assign input data
f_2(i) = WS.Cells(2 * i + 3, 1).Value 'assign input data
Next i
For k = 0 To n / 2 - 1
For m = 0 To n / Factor - 1 'defines G_1[m] and G_2[m]
G_1(m) = WorksheetFunction.ImProduct(WorksheetFunction.ImPower(TFactor_N2, k * m), f_1(m))
G_2(m) = WorksheetFunction.ImProduct(WorksheetFunction.ImPower(TFactor_N2, k * m), f_2(m))
Next m 'defines X[k] for k and k + n/2
X_k(k) = WorksheetFunction.ImSum(WorksheetFunction.ImSum(G_1), WorksheetFunction.ImProduct(WorksheetFunction.ImSum(G_2), WorksheetFunction.ImPower(TFactor_N1, k)))
If k <= n / 2 Then X_k(k + n / 2) = WorksheetFunction.ImSub(WorksheetFunction.ImSum(G_1), WorksheetFunction.ImProduct(WorksheetFunction.ImSum(G_2), WorksheetFunction.ImPower(TFactor_N1, k)))
If x = 1 Then
WS.Cells(k + 2, 1 + x).Value = X_k(k)
WS.Cells(k + 2 + n / 2, 1 + x).Value = X_k(k + n / 2)
End If
Next k
Exit Sub
ERROR_HANDLING:
MsgBox "Error encountered in " & SubName & ": exiting subroutine." _
& vbNewLine _
& vbNewLine & "Error description: " & Err.Description _
& vbNewLine & "Error number: " & Err.Number, vbCritical, Title:="Error!"
End
End Sub
``` | The function call is not good
Call Called\_Core.DecimationInTime(WS, n, 2 ^ x, x, TFactor\_N1, TFactor\_N2)
It should be:
Call DecimationInTime(WS, n, 2 ^ x, x, TFactor\_N1, TFactor\_N2) |
36,552,197 | I'm trying to implement a Fast Fourier Transform (Radix-2) in MS's Excel VBA. The code I'm using pulls data from a range in the worksheet, does the calculations, then dumps the results in the adjacent columns. What I'm having trouble with is 1) know what to do with the resulting X[k] arrays, and 2) matching these results with the results from Excel's built in FFT (they do not currently match). The code is shown below. Thanks in advance for your help.
```
Sub Enforce_DecimationInTime()
On Error GoTo ERROR_HANDLING
Dim SubName As String
SubName = "Enforce_DecimationInTime()"
Dim WS As Worksheet
Dim n As Long, v As Long, LR As Long, x As Long
Set WS = Worksheets("FFT")
LR = WS.Range("A" & Rows.Count).End(xlUp).Row
n = LR - 1
Do Until 2 ^ x <= n And 2 ^ (x + 1) > n 'locates largest power of 2 from size of input array
x = x + 1
Loop
n = n - (n - 2 ^ x) 'calculates n using the largest power of 2
If n + 1 <> WS.Range("A" & Rows.Count).End(xlUp).Row Then
WS.Range("A" & 2 ^ x + 2 & ":A" & LR).Delete xlUp 'deletes extra input data
End If
v = WorksheetFunction.Log(n, 2) 'calculates number of decimations necessary
Application.ScreenUpdating = False
For x = 1 To v
Call Called_Core.DecimationInTime(WS, n, 2 ^ x, x) 'calls decimation in time subroutine
Next x
Application.ScreenUpdating = True
Exit Sub
ERROR_HANDLING:
MsgBox "Error encountered in " & SubName & ": exiting subroutine." _
& vbNewLine _
& vbNewLine & "Error description: " & Err.Description _
& vbNewLine & "Error number: " & Err.Number, vbCritical, Title:="Error!"
End
End Sub
```
The above subroutine calls the below subroutine through a For/Next loop to the count of "v".
```
Sub DecimationInTime(WS As Worksheet, n As Long, Factor As Integer, x As Long)
On Error GoTo ERROR_HANDLING
Dim SubName As String
SubName = "DecimationInTime()"
Dim f_1() As Single, f_2() As Single
Dim i As Long, m As Long, k As Long
Dim TFactor_N1 As String, TFactor_N2 As String, X_k() As String
Dim G_1() As Variant, G_2() As Variant
ReDim f_1(0 To n / Factor - 1) As Single
ReDim f_2(0 To n / Factor - 1) As Single
ReDim G_1(0 To n / 1 - 1) As Variant
ReDim G_2(0 To n / 1 - 1) As Variant
ReDim X_k(0 To n - 1) As String
TFactor_N1 = WorksheetFunction.Complex(0, -2 * WorksheetFunction.Pi / (n / 1)) 'twiddle factor for N
TFactor_N2 = WorksheetFunction.Complex(0, -2 * WorksheetFunction.Pi / (n / 2)) 'twiddle factor for N/2
For i = 0 To n / Factor - 1
f_1(i) = WS.Range("A" & 2 * i + 2).Value 'assign input data
f_2(i) = WS.Range("A" & 2 * i + 3).Value 'assign input data
Next i
WS.Cells(1, 1 + x).Value = "X[" & x & "]" 'labels X[k] column with k number
For k = 0 To n / 2 - 1
For m = 0 To n / Factor - 1
G_1(m) = WorksheetFunction.ImProduct(WorksheetFunction.ImPower(TFactor_N2, k * m), WorksheetFunction.Complex(f_1(m), 0)) 'defines G_1[m]
G_2(m) = WorksheetFunction.ImProduct(WorksheetFunction.ImPower(TFactor_N2, k * m), WorksheetFunction.Complex(f_2(m), 0)) 'defines G_2[m]
Next m
X_k(k) = WorksheetFunction.ImSum(WorksheetFunction.ImSum(G_1), WorksheetFunction.ImProduct(WorksheetFunction.ImSum(G_2), WorksheetFunction.ImPower(TFactor_N1, k))) 'defines X[k] for k
If k <= n / 2 Then X_k(k + n / 2) = WorksheetFunction.ImSum(WorksheetFunction.ImSum(G_1), WorksheetFunction.ImProduct(WorksheetFunction.ImSum(G_2), WorksheetFunction.ImPower(TFactor_N1, k), WorksheetFunction.Complex(-1, 0))) 'defines X[k] for k + n/2
WS.Cells(k + 2, 1 + x).Value = X_k(k)
WS.Cells(k + 2 + n / 2, 1 + x).Value = X_k(k + n / 2)
Next k
Exit Sub
ERROR_HANDLING:
MsgBox "Error encountered in " & SubName & ": exiting subroutine." _
& vbNewLine _
& vbNewLine & "Error description: " & Err.Description _
& vbNewLine & "Error number: " & Err.Number, vbCritical, Title:="Error!"
End
End Sub
``` | 2016/04/11 | [
"https://Stackoverflow.com/questions/36552197",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5748328/"
] | I went back through the process and determined my problem was that I had assigned the wrong values to the twiddle factors, TFactor\_N1 and TFactor\_N2. After fixing this problem and adjusting which values are displayed, I was able to get the same results as Excel's built in FFT. The fixed code is show below.
```
Sub Enforce_DecimationInTime()
On Error GoTo ERROR_HANDLING
Dim SubName As String
SubName = "Enforce_DecimationInTime()"
Dim WS As Worksheet
Dim n As Long, v As Long, LR As Long, x As Long
Dim TFactor_N1 As String, TFactor_N2 As String
Set WS = Worksheets("FFT")
LR = WS.Range("A" & Rows.Count).End(xlUp).Row
n = LR - 1
Do Until 2 ^ x <= n And 2 ^ (x + 1) > n 'locates largest power of 2 from size of input array
x = x + 1
Loop
n = n - (n - 2 ^ x) 'calculates n using the largest power of 2
If n + 1 <> WS.Range("A" & Rows.Count).End(xlUp).Row Then
WS.Range("A" & 2 ^ x + 2 & ":A" & LR).Delete xlUp 'deletes extra input data
End If
v = WorksheetFunction.Log(n, 2) 'calculates number of decimations necessary
TFactor_N1 = WorksheetFunction.ImExp(WorksheetFunction.Complex(0, -2 * WorksheetFunction.Pi / (n / 1))) 'twiddle factor for N
TFactor_N2 = WorksheetFunction.ImExp(WorksheetFunction.Complex(0, -2 * WorksheetFunction.Pi / (n / 2))) 'twiddle factor for N/2
Application.ScreenUpdating = False
For x = 1 To v
Call Called_Core.DecimationInTime(WS, n, 2 ^ x, x, TFactor_N1, TFactor_N2) 'calls decimation in time subroutine
Next x
Application.ScreenUpdating = True
Exit Sub
ERROR_HANDLING:
MsgBox "Error encountered in " & SubName & ": exiting subroutine." _
& vbNewLine _
& vbNewLine & "Error description: " & Err.Description _
& vbNewLine & "Error number: " & Err.Number, vbCritical, Title:="Error!"
End
End Sub
Sub DecimationInTime(WS As Worksheet, n As Long, Factor As Integer, x As Long, TFactor_N1 As String, TFactor_N2 As String)
On Error GoTo ERROR_HANDLING
Dim SubName As String
SubName = "DecimationInTime()"
Dim f_1() As String, f_2() As String
Dim i As Long, m As Long, k As Long
Dim X_k() As String
Dim G_1() As Variant, G_2() As Variant
ReDim f_1(0 To n / Factor - 1) As String
ReDim f_2(0 To n / Factor - 1) As String
ReDim G_1(0 To n / 1 - 1) As Variant
ReDim G_2(0 To n / 1 - 1) As Variant
ReDim X_k(0 To n - 1) As String
For i = 0 To n / Factor - 1
f_1(i) = WS.Cells(2 * i + 2, 1).Value 'assign input data
f_2(i) = WS.Cells(2 * i + 3, 1).Value 'assign input data
Next i
For k = 0 To n / 2 - 1
For m = 0 To n / Factor - 1 'defines G_1[m] and G_2[m]
G_1(m) = WorksheetFunction.ImProduct(WorksheetFunction.ImPower(TFactor_N2, k * m), f_1(m))
G_2(m) = WorksheetFunction.ImProduct(WorksheetFunction.ImPower(TFactor_N2, k * m), f_2(m))
Next m 'defines X[k] for k and k + n/2
X_k(k) = WorksheetFunction.ImSum(WorksheetFunction.ImSum(G_1), WorksheetFunction.ImProduct(WorksheetFunction.ImSum(G_2), WorksheetFunction.ImPower(TFactor_N1, k)))
If k <= n / 2 Then X_k(k + n / 2) = WorksheetFunction.ImSub(WorksheetFunction.ImSum(G_1), WorksheetFunction.ImProduct(WorksheetFunction.ImSum(G_2), WorksheetFunction.ImPower(TFactor_N1, k)))
If x = 1 Then
WS.Cells(k + 2, 1 + x).Value = X_k(k)
WS.Cells(k + 2 + n / 2, 1 + x).Value = X_k(k + n / 2)
End If
Next k
Exit Sub
ERROR_HANDLING:
MsgBox "Error encountered in " & SubName & ": exiting subroutine." _
& vbNewLine _
& vbNewLine & "Error description: " & Err.Description _
& vbNewLine & "Error number: " & Err.Number, vbCritical, Title:="Error!"
End
End Sub
``` | Implementing FFT in ExcelVBA is kind of involved, but not too bad. For typical applications, the input signal is usually real-valued, not coplex-valued. This would be the case if you were measuring a dynamic signal from a velocity or acceleration transducer, or microphone.
Shown here is a DFT that will convert any number of input pairs, (eg. time and velocity). They do not have to be 2^N number of data (required for FFT). Usually the time is evenly divided so that all you need is DeltaTime (the time interval between your data). Let me drop in the code here:
```
Sub dft()
Dim ytime(0 To 18000) As Double 'Time history values such as velocity or acceleration
Dim omega(0 To 8096) As Double 'Discreet frequency values used in transform
Dim yfreqr(0 To 8096) As Double 'Real valued component of transform
Dim yfreqi(0 To 8096) As Double 'Imaginary component of transform
Dim t As Double, sumr As Double, sumi As Double, sum As Double 'Cumulative sums
Dim omegadt As Double, omegat As Double, deltime As Double 'More constants self explanitory
Dim wksInData As Worksheet 'This is the Excel worksheet where the data is read from and written to
Dim s As Integer, i As Integer 'Counters for the transform loops
Dim transdim As Integer 'Dimension of the transform
'Read number of values to read, delta time
'Read in dimension of transform
Set wksInData = Worksheets("DFT Input") 'This is what I named the worksheet
numval = wksInData.Cells(5, 2)
deltime = wksInData.Cells(6, 2)
transdim = wksInData.Cells(5, 4)
For i = 0 To numval - 1 'Read in all the input data, its just a long column
ytime(i) = wksInData.Cells(i + 8, 2) 'So the input starts on row 8 column 2 (time values on column 1 for plotting)
Next i 'Loop until you have all the numbers you need
'Start the transform outer loop...for each discreet frequency
'Value s is the counter from 0 to 1/2 transform dimension
'So if you have 2000 numbers to convert, transdim is 2000
For s = 0 To transdim / 2 'Since transform is complex valued, use only 1/2 the number of transdim
sumr = 0# 'Set the sum of real values to zero
sumi = 0# 'Set the sum of imaginary values to zero
omega(s) = 2# * 3.14159265 * s / (transdim * deltime) 'These are the discreet frequencies
omegadt = omega(s) * deltime 'Just a number used in computations
' Start the inner loop for DFT
For i = 0 To numval - 1
sumr = sumr + ytime(i) * Cos(omegadt * i) 'This is the real valued sum
sumi = sumi + ytime(i) * Sin(omegadt * i) 'This is the complex valued sum
Next i ' and back for more
yfreqr(s) = sumr * 2# / transdim 'This is what is called the twiddle factor, just a constant
yfreqi(s) = -sumi * 2# / transdim 'Imaginary component is negative
Next s
'One last adjustment for the first and last transform values
'They are only 1/2 of the rest, but it is easiest to do this now after the inner loop is done
yfreqr(0) = yfreqr(0) / 2# 'Beginning factor
yfreqi(0) = yfreqi(0) / 2#
yfreqr(transdim / 2) = yfreqr(transdim / 2) / 2# 'End factor
yfreqi(transdim / 2) = yfreqi(transdim / 2) / 2#
wksInData.Cells(2, 8) = "Output" 'Just a column text header
For s = 0 To transdim / 2 'And write the output to columns 3, 4, 5 to the worksheet
wksInData.Cells(s + 8, 3) = omega(s) 'remember that magnitude is sqrt(real ^2 + imaginary ^2 )
wksInData.Cells(s + 8, 4) = yfreqr(s) 'but you can do this with an Excel formula on the worksheet
wksInData.Cells(s + 8, 5) = yfreqi(s) 'same with phase angle = arctan(Imaginary/Real)
Next s 'End of writeout loop.
'This is the inverse DFT
'I like to check my calculation,
'Should get the original time series back
For i = 0 To numval - 1
sum = 0
t = deltime * i
For s = 0 To transdim / 2
omegat = omega(s) * t
sum = sum + yfreqr(s) * Cos(omegat) - yfreqi(s) * Sin(omegat)
Next s
ytime(i) = sum
Next i
``` |
46,465,366 | I tried to create a spring boot deployable war file and then deployed it to weblogic 12c. Application startup failed with the exception:
```
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
ERROR SpringApplication - Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLServletRegistrationBean' defined in class path resource
...
```
Nested exception is:
```
java.lang.IllegalStateException: No *.graphqls files found on classpath. Please add a graphql schema to the classpath or add a SchemaParser bean to your application context.
```
In fact, the above mentioned files `*.graphqls` exist in the war under `WEB-INF/classes/` folder. If the war file was unzipped to the local disk and redeploy the app in exploded format, we won't see this exception.
Do I miss anything?
Thanks. | 2017/09/28 | [
"https://Stackoverflow.com/questions/46465366",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3432316/"
] | I wasted 8 hours in this loophole, piecing together various clues I got from other people facing the same problem.
\*\*solution 1 is to deploy your application as exploded WAR in Weblogic.
I assume you already prepared your spring boot application for deployment on Weblogic, there are several tricks on this topic but they are available on the Internet (exclude embedded tomcat and specify WAR packaging in POM.XML, create webapp/WEB-INF folder with weblogic.xml and servlet xml).
Now create a folder on the server, /home/oracle/wars/myapp for example, and just copy the unpacked contents of your WAR to that folder.
Then go to Deployments - Install, navigate to /home/oracle/wars/ and choose myapp folder from the radio button list, and simply follow the default steps to deploy.
Pay attention, you need a plain web.xml file along with weblogic.xml, otherwise Weblogic will not see it as 'Web application'\*\*
Deploying as exploded WAR is a workaround to avoid the creation of \_wl\_cls\_gen.jar which is at the source of this problem.
\*\* Solution 2
By default the lookup location is set to "classpath:graphql/\*\*/"
which is not picked up by PathMatchingResourcePatternResolver.
Set this in your application yaml or properties:
```
spring: graphql: schema: locations: classpath*:graphql/**/
```
Finally, for this particular error, \*\*/\*.graphqls file not found when deploying to weblogic, nothing of the below worked, I am mentioning it so you don't waste your time as well:
1. Adding resource tag in POM
src/main/resources
\*\*/\*.properties
\*\*/\*.graphqls
2. Adding in application.properties
graphql.tools.schema-location-pattern=\*\*/\*.graphqls
3. Adding in application.properties
graphql.servlet.exception-handlers-enabled=true
4. Newer versions of GraphQL libraries, I tried it and everything fails with this error from graphql 7.0.1 onwards
5. Adding spring-boot-starter-parent in POM | Without seeing your code, or knowing your spring-boot version, it's difficult to really diagnose your issue. There were small changes here and there that had to be to get my spring-boot app to run on WebLogic. Thinks like inclusion of weblogic.xml and some dependencies here and there
The main one being the addition of `implements WebApplicationInitializer` to my application class like so.
```
@SpringBootApplication
public class Application extends SpringBootServletInitializer
implements
WebApplicationInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
```
It looks like a few other had issues similar to yours, maybe these can help you out. It seems like you might be having issues with having spring-boot with other spring (but not spring-boot) dependencies. It's impossible to really tell as I don't know what your pom file or application class file look like.
[One](https://stackoverflow.com/questions/21783391/spring-boot-unable-to-start-embeddedwebapplicationcontext-due-to-missing-embedd)
[Two](https://github.com/codecentric/spring-boot-admin/issues/155)
[Three](https://stackoverflow.com/questions/30958968/spring-framework-unable-to-start-embedded-container)
[Four](https://github.com/spring-cloud/spring-cloud-config/issues/645) |
46,465,366 | I tried to create a spring boot deployable war file and then deployed it to weblogic 12c. Application startup failed with the exception:
```
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
ERROR SpringApplication - Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLServletRegistrationBean' defined in class path resource
...
```
Nested exception is:
```
java.lang.IllegalStateException: No *.graphqls files found on classpath. Please add a graphql schema to the classpath or add a SchemaParser bean to your application context.
```
In fact, the above mentioned files `*.graphqls` exist in the war under `WEB-INF/classes/` folder. If the war file was unzipped to the local disk and redeploy the app in exploded format, we won't see this exception.
Do I miss anything?
Thanks. | 2017/09/28 | [
"https://Stackoverflow.com/questions/46465366",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3432316/"
] | I wasted 8 hours in this loophole, piecing together various clues I got from other people facing the same problem.
\*\*solution 1 is to deploy your application as exploded WAR in Weblogic.
I assume you already prepared your spring boot application for deployment on Weblogic, there are several tricks on this topic but they are available on the Internet (exclude embedded tomcat and specify WAR packaging in POM.XML, create webapp/WEB-INF folder with weblogic.xml and servlet xml).
Now create a folder on the server, /home/oracle/wars/myapp for example, and just copy the unpacked contents of your WAR to that folder.
Then go to Deployments - Install, navigate to /home/oracle/wars/ and choose myapp folder from the radio button list, and simply follow the default steps to deploy.
Pay attention, you need a plain web.xml file along with weblogic.xml, otherwise Weblogic will not see it as 'Web application'\*\*
Deploying as exploded WAR is a workaround to avoid the creation of \_wl\_cls\_gen.jar which is at the source of this problem.
\*\* Solution 2
By default the lookup location is set to "classpath:graphql/\*\*/"
which is not picked up by PathMatchingResourcePatternResolver.
Set this in your application yaml or properties:
```
spring: graphql: schema: locations: classpath*:graphql/**/
```
Finally, for this particular error, \*\*/\*.graphqls file not found when deploying to weblogic, nothing of the below worked, I am mentioning it so you don't waste your time as well:
1. Adding resource tag in POM
src/main/resources
\*\*/\*.properties
\*\*/\*.graphqls
2. Adding in application.properties
graphql.tools.schema-location-pattern=\*\*/\*.graphqls
3. Adding in application.properties
graphql.servlet.exception-handlers-enabled=true
4. Newer versions of GraphQL libraries, I tried it and everything fails with this error from graphql 7.0.1 onwards
5. Adding spring-boot-starter-parent in POM | I've figured out the cause of this issue. It's a bit odd in weblogic when deploying war file. It creates an internal \_wl\_cls\_gen.jar file to package all files for /WEB-INF/classes folder.
but the application still looks for resources in match directory like /j2ee/wl12/cp\_domain/servers/cp\_msp01/tmp/\_WL\_user/cpapps-graphql-results/g4qyhf/war/WEB-INF/classes/\*\*/\*.graphqls and find nothing matched. |
38,819 | [This question on SO](https://stackoverflow.com/questions/2215314/sybase-central-issues-on-64-bit-windows-2008-server-r2) clearly belongs elsewhere, but the asker already put a bounty on the question.
If the question is migrated, does the rep get refunded? Does the question continue to be a bounty question on the target site if the user has enough rep? (The asker in the referenced question does not have any associated accounts, but I'm curious about what happens.)
Edit: I just tried to add my own close vote, but apparently you can't when there's an open bounty. However, a mod should still be able to close/migrate/etc. | 2010/02/09 | [
"https://meta.stackexchange.com/questions/38819",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/136558/"
] | The correct procedure would be to flag for moderator attention. If required diamond moderators can migrate the question by removing the bounty.
* Bounty is removed and refunded
* Question is closed and migrated
I have flagged the question as well for the SO mods to look at it | Questions with bounties on them can't be closed or migrated (unless by a superpower of mod type personage). It'll stay until the bounty's accepted or expired. |
38,819 | [This question on SO](https://stackoverflow.com/questions/2215314/sybase-central-issues-on-64-bit-windows-2008-server-r2) clearly belongs elsewhere, but the asker already put a bounty on the question.
If the question is migrated, does the rep get refunded? Does the question continue to be a bounty question on the target site if the user has enough rep? (The asker in the referenced question does not have any associated accounts, but I'm curious about what happens.)
Edit: I just tried to add my own close vote, but apparently you can't when there's an open bounty. However, a mod should still be able to close/migrate/etc. | 2010/02/09 | [
"https://meta.stackexchange.com/questions/38819",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/136558/"
] | Questions with bounties on them can't be closed or migrated (unless by a superpower of mod type personage). It'll stay until the bounty's accepted or expired. | I can confirm that if the question is migrated and the bounty was not awarded in the original page, then the reputation is refunded. I proposed +100 bounty for this [question](https://math.stackexchange.com/questions/33617/a-sequence-of-order-statistics-from-an-iid-sequence) in stats.SE which I could not award, so I suggested to migrate the question, and then proposed +100 bounty in math.SE. For other reasons I checked my `/reputation` page today and saw that I had 100 more reputation than I should. So the reputation is refunded, but with some time delay, about a month in my case. |
38,819 | [This question on SO](https://stackoverflow.com/questions/2215314/sybase-central-issues-on-64-bit-windows-2008-server-r2) clearly belongs elsewhere, but the asker already put a bounty on the question.
If the question is migrated, does the rep get refunded? Does the question continue to be a bounty question on the target site if the user has enough rep? (The asker in the referenced question does not have any associated accounts, but I'm curious about what happens.)
Edit: I just tried to add my own close vote, but apparently you can't when there's an open bounty. However, a mod should still be able to close/migrate/etc. | 2010/02/09 | [
"https://meta.stackexchange.com/questions/38819",
"https://meta.stackexchange.com",
"https://meta.stackexchange.com/users/136558/"
] | The correct procedure would be to flag for moderator attention. If required diamond moderators can migrate the question by removing the bounty.
* Bounty is removed and refunded
* Question is closed and migrated
I have flagged the question as well for the SO mods to look at it | I can confirm that if the question is migrated and the bounty was not awarded in the original page, then the reputation is refunded. I proposed +100 bounty for this [question](https://math.stackexchange.com/questions/33617/a-sequence-of-order-statistics-from-an-iid-sequence) in stats.SE which I could not award, so I suggested to migrate the question, and then proposed +100 bounty in math.SE. For other reasons I checked my `/reputation` page today and saw that I had 100 more reputation than I should. So the reputation is refunded, but with some time delay, about a month in my case. |
58,286,178 | I have a simple input with an ngModel in it, the thing is that I can't see in real time what that ngModel contains and I get an error saying `Cannot read property 'content' of undefined`
```html
<input ([ngModel])="page.content" />
{{ page.content }}
```
```js
export interface Page {
uid: string;
content: string;
}
@Input() page: Page;
ngOnInit() {
console.log(this.page.content)
}
```
So, this is what I tried and what I'm trying to do is to get a `console.log` of the things I have typed in real-time as I am typing in the `<input ([ngModel])="page.content" />`
Here is a [stackblitz](https://stackblitz.com/edit/angular-b8sps6) for reference | 2019/10/08 | [
"https://Stackoverflow.com/questions/58286178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12025029/"
] | This happens because during the Angular lifecycle when your page is first created the value of page is null.
What you can do in your .html you could do this :
`[(ngModel)]="page?.content"`.
This checks if page exists before trying to access content.
Hope this helps! | You must initialize page object.
Try this:
```
ngOnInit() {
this.page = { uid: '1234', content: 'hello' }
}
```
or
```
ngOnInit() {
this.page = { uid: '', content: '' }
}
```
Regards |
58,286,178 | I have a simple input with an ngModel in it, the thing is that I can't see in real time what that ngModel contains and I get an error saying `Cannot read property 'content' of undefined`
```html
<input ([ngModel])="page.content" />
{{ page.content }}
```
```js
export interface Page {
uid: string;
content: string;
}
@Input() page: Page;
ngOnInit() {
console.log(this.page.content)
}
```
So, this is what I tried and what I'm trying to do is to get a `console.log` of the things I have typed in real-time as I am typing in the `<input ([ngModel])="page.content" />`
Here is a [stackblitz](https://stackblitz.com/edit/angular-b8sps6) for reference | 2019/10/08 | [
"https://Stackoverflow.com/questions/58286178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12025029/"
] | Please make the following change in your html:
```
[(ngModel)]="page.content"
```
instead of
```
([ngModel])="page.content"
```
and initialise the object in your ts:
```
this.page = {uid: '000001', content: 'zero'};
```
Please find the modified demo:
[modified stackblitz](https://stackblitz.com/edit/angular-leymzs)
Hope this helps. | You must initialize page object.
Try this:
```
ngOnInit() {
this.page = { uid: '1234', content: 'hello' }
}
```
or
```
ngOnInit() {
this.page = { uid: '', content: '' }
}
```
Regards |
58,286,178 | I have a simple input with an ngModel in it, the thing is that I can't see in real time what that ngModel contains and I get an error saying `Cannot read property 'content' of undefined`
```html
<input ([ngModel])="page.content" />
{{ page.content }}
```
```js
export interface Page {
uid: string;
content: string;
}
@Input() page: Page;
ngOnInit() {
console.log(this.page.content)
}
```
So, this is what I tried and what I'm trying to do is to get a `console.log` of the things I have typed in real-time as I am typing in the `<input ([ngModel])="page.content" />`
Here is a [stackblitz](https://stackblitz.com/edit/angular-b8sps6) for reference | 2019/10/08 | [
"https://Stackoverflow.com/questions/58286178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12025029/"
] | This happens because during the Angular lifecycle when your page is first created the value of page is null.
What you can do in your .html you could do this :
`[(ngModel)]="page?.content"`.
This checks if page exists before trying to access content.
Hope this helps! | Please make the following change in your html:
```
[(ngModel)]="page.content"
```
instead of
```
([ngModel])="page.content"
```
and initialise the object in your ts:
```
this.page = {uid: '000001', content: 'zero'};
```
Please find the modified demo:
[modified stackblitz](https://stackblitz.com/edit/angular-leymzs)
Hope this helps. |
72,875,246 | I created a Service to read data from the database.
In order to achieve that, I want to make a Controller and throw this controller I want to call first the `ReadingDataService`.
**Error Message:**
>
> **Too few arguments** to function `TryPlugin\Service\ReadingData::__construct()`, **1 passed** in `/var/www/html/var/cache/dev_he0523cc28be2f689acaab5c325675d68/ContainerFt0wDoq/Shopware_Production_KernelDevDebugContainer.php` on line 25455 and **exactly 2 expected**
>
>
>
**Code:**
**ReadingData.php**
```php
class ReadingData
{
private EntityRepositoryInterface $productRepository;
private Context $con;
public function __construct(EntityRepositoryInterface $productRepository, Context $con)
{
$this->productRepository = $productRepository;
$this->con = $con;
}
public function readData(): void
{
$criteria1 = new Criteria();
$products = $this->productRepository->search($criteria1, $this->con)->getEntities();
}
}
```
**PageController.php**
```php
/**
* @RouteScope (scopes={"storefront"})
*/
class PageController extends StorefrontController
{
/**
* @Route("/examples", name="examples", methods={"GET"})
*/
public function showExample(ReadingData $ReadingDatan): Response
{
$meinData = $ReadingDatan->readData();
return $this->renderStorefront('@Storefront/storefront/page/content/index.html.twig', [
'products' => $meinData,
]);
}
}
```
**Service.xml:**
```xml
<service id="TryPlugin\Service\ReadingData">
<argument type="service" id="product.repository"/>
</service>
<!--ReadingDate From Controller-->
<service id="TryPlugin\Storefront\Controller\PageController" public="true">
<call method="setContainer">
<argument type="service" id="service_container"/>
</call>
<tag name="controller.service_arguments"/>
</service>
``` | 2022/07/05 | [
"https://Stackoverflow.com/questions/72875246",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17204096/"
] | You need to pass the 2nd argument in `service.xml`
--------------------------------------------------
Your class requires two arguments:
```php
public function __construct(EntityRepositoryInterface $productRepository, Context $con) { //...
```
but only provides one in `service.xml`:
```xml
<service id="TryPlugin\Service\ReadingData">
<argument type="service" id="product.repository"/>
<!-- Need argument for `Context $con` -->
</service>
```
Looking at the documentation, `Context` does not appear to be [autowired](https://symfony.com/doc/current/service_container/autowiring.html) by default.
Therefore, you must [inject the service](https://developer.shopware.com/docs/guides/plugins/plugins/plugin-fundamentals/dependency-injection) yourself in `service.xml`.
If you grow tired of all ways specifying the arguments in `service.xml`, look into enabling and configuring [autowire for ShopWare](https://symfony.com/doc/current/service_container/autowiring.html). | This is unecessary in the first place.
Do the following in your controller and pass the context down:
```
namespace TryPlugin\Storefront\Controller;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\Routing\Annotation\LoginRequired;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use TryPlugin\Service\ReadingData;
/**
* @RouteScope (scopes={"storefront"})
*/
class PageController extends StorefrontController
{
/**
* @Route("/examples", name="examples", methods={"GET"})
*/
public function showExample(ReadingData $ReadingDatan, Context $context): Response
{
$meinData = $ReadingDatan->readData($context);
return $this->renderStorefront('@Storefront/storefront/page/content/index.html.twig', [
'products' => $meinData,
]);
}
}
```
This will work since there is a parameter resolver for controllers. |
2,398,161 | I'm trying to add paths to my classpath in the Clojure REPL that I've set up in Emacs using ELPA. Apparently, this isn't the $CLASSPATH environment variable, but rather the swank-clojure-classpath variable that Swank sets up. Because I used ELPA to install Swank, Clojure, etc., there are a ton of .el files that take care of everything instead of my .emacs file. Unfortunately, I can't figure out how to change the classpath now.
I've tried using (setq 'swank-clojure-extra-classpaths (list ...)) both before and after the ELPA stuff in my .emacs, and I've tried adding paths directly to swank-clojure-classpath in .emacs, .emacs.d/init.el, and .emacs.d/user/user.el, but nothing works.
What I'm ultimately trying to do is to add both the current directory "." and the directory in which I keep my Clojure programs. I'm assuming swank-clojure-classpath is the thing I need to set here. Thanks for your help. | 2010/03/07 | [
"https://Stackoverflow.com/questions/2398161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/288389/"
] | As mac says, you can use
```
M-x swank-clojure-project
```
to establish a slime REPL to a clojure project; the command will ask you for your projects root directory, and will establish a classpath that includes a variety of directories including src/ lib/ and resources/ if they are present.
Alternatively, if you are using leiningen, you can start that in a terminal with the command
```
$ lein swank
```
from inside your project root directory. This will establish a standard project classpath (as above). From here you can connect to this running process via Emacs with the command
```
M-x slime-connect
```
Finally a third option which I'd recommend is to connect via Emacs/slime (with `M-x slime-connect`) to a process started by your own shell script which specifies a custom set of JVM command line arguments e.g.
```
#!/bin/bash
java -server -cp "./lib/*":./src clojure.main -e "(do (require 'swank.swank) (swank.swank/start-repl))"
```
This allows you explicit control over how the VM is started, and is likely similar to what you will likely have to do in production anyway. | You want:
```
M-x swank-clojure-project
```
This adds all jars in your /lib dir.
If you want to :use a clojure file (bar.clj), in for instance /foo you would do:
```
(ns foo
(:use foo.bar))
``` |
2,398,161 | I'm trying to add paths to my classpath in the Clojure REPL that I've set up in Emacs using ELPA. Apparently, this isn't the $CLASSPATH environment variable, but rather the swank-clojure-classpath variable that Swank sets up. Because I used ELPA to install Swank, Clojure, etc., there are a ton of .el files that take care of everything instead of my .emacs file. Unfortunately, I can't figure out how to change the classpath now.
I've tried using (setq 'swank-clojure-extra-classpaths (list ...)) both before and after the ELPA stuff in my .emacs, and I've tried adding paths directly to swank-clojure-classpath in .emacs, .emacs.d/init.el, and .emacs.d/user/user.el, but nothing works.
What I'm ultimately trying to do is to add both the current directory "." and the directory in which I keep my Clojure programs. I'm assuming swank-clojure-classpath is the thing I need to set here. Thanks for your help. | 2010/03/07 | [
"https://Stackoverflow.com/questions/2398161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/288389/"
] | As mac says, you can use
```
M-x swank-clojure-project
```
to establish a slime REPL to a clojure project; the command will ask you for your projects root directory, and will establish a classpath that includes a variety of directories including src/ lib/ and resources/ if they are present.
Alternatively, if you are using leiningen, you can start that in a terminal with the command
```
$ lein swank
```
from inside your project root directory. This will establish a standard project classpath (as above). From here you can connect to this running process via Emacs with the command
```
M-x slime-connect
```
Finally a third option which I'd recommend is to connect via Emacs/slime (with `M-x slime-connect`) to a process started by your own shell script which specifies a custom set of JVM command line arguments e.g.
```
#!/bin/bash
java -server -cp "./lib/*":./src clojure.main -e "(do (require 'swank.swank) (swank.swank/start-repl))"
```
This allows you explicit control over how the VM is started, and is likely similar to what you will likely have to do in production anyway. | Sorry I cannot help you with an answer, but maybe your question is wrong:
I myself haven't started a clojure session from within Emacs for ages. I think the better way is to describe all your dependencies in a single place (e.g. the maven `pom.xml` or leiningen's `project.clj`) and then start a swank session with those dependencies. I.e. add the `swank-clojure` lib to your (dev-)dependencies and then use `lein swank` or `maven swank` (not sure about the last one -- haven't used that much and not in a while) from the command line to start a swank session and use `M-x slime-connect` to attach to that session.
The advantage is that you get all the things in your classpath that you need -- and not more, so you cannot mistakenly use something from the repl that your final project doesn't know about.
[This blog post gives a good summary how to do this right.](http://mdelaurentis.tumblr.com/post/421253627/clojure-emacs) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.