qid
int64 1
74.7M
| question
stringlengths 0
58.3k
| date
stringlengths 10
10
| metadata
list | response_j
stringlengths 2
48.3k
| response_k
stringlengths 2
40.5k
|
---|---|---|---|---|---|
208,002 | I'm new to LaTeX and I have a question about the LaTeX code (which I have to do for my essay), for the inner product of vectors on an exponential\*,how can I fix the problem that the two vektors k and x have their vectors taht are not parallel . *The vector of k is much higher that the vector in x* ( I use the command \overrightarrow for the vector, and I have also use the \displaystyle for a sum that exist in the same equation).
How can I fix that?
Thanks cheers :) | 2014/10/19 | [
"https://tex.stackexchange.com/questions/208002",
"https://tex.stackexchange.com",
"https://tex.stackexchange.com/users/64448/"
]
| Actually, X11 is not erased but moved to /opt/X11.
So, the simplest solution would probably be to manually add the symbolic link from /usr/X11 to /opt/X11:
```
sudo ln -s /opt/X11 /usr/X11
``` | I had the exact same problem with another program that was working prior to upgrading to OS X Yosemite, and then returned the following error subsequent to upgrading:
```
dyld: Library not loaded: /usr/X11/lib/libX11.6.dylib
Referenced from: /Users/grosbj/LANL/MCNP5/bin/mcnp5
Reason: image not found
Trace/BPT trap: 5
```
fabianfuchs' suggestion fixed it!:
```
sudo ln -s /opt/X11 /usr/X11
```
Thanks! |
208,002 | I'm new to LaTeX and I have a question about the LaTeX code (which I have to do for my essay), for the inner product of vectors on an exponential\*,how can I fix the problem that the two vektors k and x have their vectors taht are not parallel . *The vector of k is much higher that the vector in x* ( I use the command \overrightarrow for the vector, and I have also use the \displaystyle for a sum that exist in the same equation).
How can I fix that?
Thanks cheers :) | 2014/10/19 | [
"https://tex.stackexchange.com/questions/208002",
"https://tex.stackexchange.com",
"https://tex.stackexchange.com/users/64448/"
]
| Actually, X11 is not erased but moved to /opt/X11.
So, the simplest solution would probably be to manually add the symbolic link from /usr/X11 to /opt/X11:
```
sudo ln -s /opt/X11 /usr/X11
``` | Same problem after installing OSX Catalina ...
But now, you need to make a link like this:
```
sudo ln -s /opt/X11 /private/var/select/X11
```
(The link `/usr/X11` points to `/private/var/select/X11` and can't be modified.) |
208,002 | I'm new to LaTeX and I have a question about the LaTeX code (which I have to do for my essay), for the inner product of vectors on an exponential\*,how can I fix the problem that the two vektors k and x have their vectors taht are not parallel . *The vector of k is much higher that the vector in x* ( I use the command \overrightarrow for the vector, and I have also use the \displaystyle for a sum that exist in the same equation).
How can I fix that?
Thanks cheers :) | 2014/10/19 | [
"https://tex.stackexchange.com/questions/208002",
"https://tex.stackexchange.com",
"https://tex.stackexchange.com/users/64448/"
]
| Same problem after installing OSX Catalina ...
But now, you need to make a link like this:
```
sudo ln -s /opt/X11 /private/var/select/X11
```
(The link `/usr/X11` points to `/private/var/select/X11` and can't be modified.) | I had the exact same problem with another program that was working prior to upgrading to OS X Yosemite, and then returned the following error subsequent to upgrading:
```
dyld: Library not loaded: /usr/X11/lib/libX11.6.dylib
Referenced from: /Users/grosbj/LANL/MCNP5/bin/mcnp5
Reason: image not found
Trace/BPT trap: 5
```
fabianfuchs' suggestion fixed it!:
```
sudo ln -s /opt/X11 /usr/X11
```
Thanks! |
14,580,615 | I have installed Drush-5.4-2012-06-04-Installer-v1.0.18.msi in the location C:\ProgramData\Drush by default. I run the program and moved to drupal working directory.
When I type drush it is showing "drush is not recognized as an internal or external command " error. Do I need to configure anything before run? Please help. | 2013/01/29 | [
"https://Stackoverflow.com/questions/14580615",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1679480/"
]
| You need to set the path variable :
* right click on **computer**
* go to **properties**
* click **advanced system settings** then
* click on **environment variable**, then
* find the variable **path**
* and edit it
add this to end of the variable value **C:ProgramData\Propeople\Drush** and restart the drush, It should work. | Faced this problem while i was installing drush with composer.
For anyone who have installed drush with composer, if this problem occures, You will have to set PATH variable as follows.
```
F:\Users\{YOUR-USERNAME}\AppData\Roaming\Composer\vendor\drush\drush\;
```
I did this and now my path variables are below.
```
F:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;F:\Program Files\TortoiseSVN\bin;F:\Program Files\Git\cmd;F:\wamp\bin\php\php5.5.12;F:\ProgramData\ComposerSetup\bin;F:\Users\user\AppData\Roaming\Composer\vendor\drush\drush\;
```
Be careful, Just don't copy paste above variables, you have to append drush path to existing variables.
 |
14,580,615 | I have installed Drush-5.4-2012-06-04-Installer-v1.0.18.msi in the location C:\ProgramData\Drush by default. I run the program and moved to drupal working directory.
When I type drush it is showing "drush is not recognized as an internal or external command " error. Do I need to configure anything before run? Please help. | 2013/01/29 | [
"https://Stackoverflow.com/questions/14580615",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1679480/"
]
| You need to set the path variable :
* right click on **computer**
* go to **properties**
* click **advanced system settings** then
* click on **environment variable**, then
* find the variable **path**
* and edit it
add this to end of the variable value **C:ProgramData\Propeople\Drush** and restart the drush, It should work. | For Drupal, you need to run `composer require drush/drush` command from the root project folder |
14,580,615 | I have installed Drush-5.4-2012-06-04-Installer-v1.0.18.msi in the location C:\ProgramData\Drush by default. I run the program and moved to drupal working directory.
When I type drush it is showing "drush is not recognized as an internal or external command " error. Do I need to configure anything before run? Please help. | 2013/01/29 | [
"https://Stackoverflow.com/questions/14580615",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1679480/"
]
| Faced this problem while i was installing drush with composer.
For anyone who have installed drush with composer, if this problem occures, You will have to set PATH variable as follows.
```
F:\Users\{YOUR-USERNAME}\AppData\Roaming\Composer\vendor\drush\drush\;
```
I did this and now my path variables are below.
```
F:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;F:\Program Files\TortoiseSVN\bin;F:\Program Files\Git\cmd;F:\wamp\bin\php\php5.5.12;F:\ProgramData\ComposerSetup\bin;F:\Users\user\AppData\Roaming\Composer\vendor\drush\drush\;
```
Be careful, Just don't copy paste above variables, you have to append drush path to existing variables.
 | For Drupal, you need to run `composer require drush/drush` command from the root project folder |
46,598,234 | i'm new to java and am trying to return the value of commission to be printed out in the last line. but i keep getting the incompatible types: unexpected return value error.
```
import java.util.Scanner;
public class retail {
public static void main (String[] args){
char code;
double commission;
String enumber;
double retail_price=0;
Scanner scan = new Scanner(System.in);
System.out.println("Enter employee number: ");
enumber= scan.nextLine();
System.out.println("Enter retail price: ");
retail_price= scan.nextDouble();
System.out.println("Enter code:");
code=scan.next().charAt(0);
if (code == 'A'){ commission = (retail_price/100)*6;}
else if (code == 'a') {commission = (retail_price/100)*6;}
else if (code == 'B') {commission = (retail_price/100)*8;}
else if (code == 'b') {commission = (retail_price/100)*8;}
else if (code == 'C') {commission = (retail_price/100)*10;}
else if (code == 'c') {commission = (retail_price/100)*10;}
else{System.out.println("Invalid code");}
return commission;
System.out.println("Employee number: "+enumber);
System.out.println("Retail price: "+retail_price);
System.out.println("Commission: "+commission);
}
}
``` | 2017/10/06 | [
"https://Stackoverflow.com/questions/46598234",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8730148/"
]
| Extending your code:
```
from datetime import datetime, date,timedelta
from pytz import timezone
tz1 = timezone('utc')
tz2 = timezone('Asia/Kolkata')
tz3 = timezone('America/Los_Angeles')
dt1 = datetime.now(tz=tz1)
dt2 = datetime.now(tz=tz2)
print(dt1)
print(dt2)
start_of_week = dt1+timedelta(days=0-dt1.weekday())
end_of_week = dt1+timedelta(days=6-dt1.weekday())
print(start_of_week)
print(end_of_week)
``` | I'm expanding chakris answer:
**updated** Since a week either can start or end on the same day, when you input sunday and the week start with sunday you have two options.
Maybe you can change the code to fit your needs.
```
from datetime import datetime, date,timedelta
from pytz import timezone
def week_startandend(dt_,weekstart=0):
"""Returns tuple with start date of week and end day of week."""
index = (dt_.weekday() + (7-weekstart % 7) ) % 7
# Calculate start and end
start = dt_+timedelta(days=0-index)
end = dt_+timedelta(days=6-index)
# if week doesnt start on the same day we can return
if index != 0:
return {"start":start.date(),"end":end.date()}
# else we need to calculate the other option
else:
start2 = dt_+timedelta(days=-7)
end2 = dt_
return {"start1":start.date(),"end1":end.date(),
"start2":start2.date(),"end2":end2.date()}
tz1 = timezone('utc')
tz2 = timezone('Asia/Kolkata')
dt1 = datetime.now(tz=tz1)
dt2 = datetime.now(tz=tz2)
print(week_startandend(dt1)) # defaults to 0
print(week_startandend(dt2,weekstart=6)) # 6 = sunday
```
Returns
```
{'start': datetime.date(2017, 10, 2), 'end': datetime.date(2017, 10, 8)}
{'start1': datetime.date(2017, 10, 8), 'end1': datetime.date(2017, 10, 14),
'start2': datetime.date(2017, 10, 1), 'end2': datetime.date(2017, 10, 8)}
```
In [352]: |
211,310 | We have a message queue on our queue server to which no-one has access. During a test we removed all the users from the queue. Now no-one can access it at all. | 2010/11/16 | [
"https://superuser.com/questions/211310",
"https://superuser.com",
"https://superuser.com/users/25713/"
]
| There is a file in the system32\msmq\storage\lqs directory that contains the configuration for this queue. Find the file that contains the name of the queue you are talking about. If you delete the file and restart MSMQ, the queue has gone. Obviously don't delete any of the other files! | Also you can run this code snippet. Note that your project should reference System.Messaging
```
using System.Messaging;
.
.
.
MessageQueue[] msmques = MessageQueue.GetPrivateQueuesByMachine(".");
foreach (var item in msmques)
{
MessageQueue.Delete(".\\"+item.QueueName);
}
``` |
71,116,939 | currently, I am struggling with how the MongoDB document system works. I want to fetch array elements with an auto-generated id but how to fetch that specific data that I don't know.
my current schema is
```
const ItemPricesSchema = new mongoose.Schema({
_id : {
type: String
},
ItemsPrices: {
type: [{
barcode : {
type: String
},
itemName : {
type: String
},
price : {
type: String
}
}]
}
});
```
current data is stored in this way
```
{
"_id": "[email protected]",
"ItemsPrices": [
{
"barcode": "345345",
"itemName": "maggie",
"price": "45",
"_id": "620a971e11120abbde5f4c3a"
},
{
"barcode": "356345",
"itemName": "monster",
"price": "70",
"_id": "620a971e11120abbde5f4c3b"
}
],
"__v": 0
}
```
what I want to achieve is that I want to find array elements through ids
if I want a specific array element with id "620a971e11120abbde5f4c3b" what should I do??
I have tried $unwind , $in, $match...
the result should be like
```
{
"_id": "[email protected]",
"ItemsPrices": [
{
"barcode": "356345",
"itemName": "monster",
"price": "70",
"_id": "620a971e11120abbde5f4c3b"
}
],
"__v": 0
}
```
what I tried is like this from the answer
```
router.get('/filter/:id', async (req, res) => {
try {
const item = await ItemPricesSchema.aggregate([
{$project: {
"ItemsPrices": {
$filter: {
input: "$ItemsPrices",
as: "item",
cond: {
$eq: [
"$$item._id",
"620a8dd1c88ae3eb88a8107a"
]
}
}
}
}
}
])
res.json(item);
console.log(item);
} catch (error) {
res.status(500).json({message: error.message});
}
})
```
and returns something like this (Empty arrays)
```
[
{
"_id": "[email protected]",
"ItemsPrices": []
},
{
"_id": "[email protected]",
"ItemsPrices: []
},
{
"_id": "[email protected]",
"ItemsPrices": []
},
{
"_id": "[email protected]",
"ItemsPrices": []
}
]
```
but If I search for price $$item.price
```
cond: {
$eq: [
"$$item.price",
"30"
]
}
```
it returns the perfect output
```
[
{
"_id": "[email protected]",
"ItemsPrices": []
},
{
"_id": "[email protected]",
"ItemsPrices: []
},
{
"_id": "[email protected]",
"ItemsPrices": []
},
{
"_id": "[email protected]",
"ItemsPrices": [
{
"barcode":"234456345",
"price":"30",
"itemName":"monster",
"_id":"620a8dd1c88ae3eb88a8107a"
}
]
}
]
``` | 2022/02/14 | [
"https://Stackoverflow.com/questions/71116939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13931640/"
]
| You can do an aggregation with `$project` and apply `$filter` on the array part. In mongoose you can apply the aggregation query in a more or less similar way <https://mongoosejs.com/docs/api/aggregate.html>
```js
db.collection.aggregate([
{
$project: {
"ItemsPrices": {
$filter: {
input: "$ItemsPrices",
as: "item",
cond: {
$eq: [
"$$item._id",
mongoose.Types.ObjectId("620a971e11120abbde5f4c3b")
]
}
}
},
"__v": 1 //when projecting 1 means in the final result this field appears
}
}
])
```
[more examples](https://stackoverflow.com/questions/15117030/how-to-filter-array-in-subdocument-with-mongodb)
[demo](https://mongoplayground.net/p/ZUinQ3EMgpc) | Option 1:
Use `$filter` in an aggregation query as explained by [cmgchess](https://stackoverflow.com/users/13583510/cmgchess)
Option 2:
If you only want one object from array you can use [$elemMatch](https://docs.mongodb.com/manual/reference/operator/query/elemMatch/) like this:
```
db.collection.find({
"ItemsPrices._id": "620a971e11120abbde5f4c3b"
},
{
"ItemsPrices": {
"$elemMatch": {
"_id": "620a971e11120abbde5f4c3b"
}
}
})
```
Example [here](https://mongoplayground.net/p/-92IHT-i9k3)
But take care, using `$elemMatch` only the first element is returned. Check [this other example](https://mongoplayground.net/p/0yEf42vfAed) where there are two objects with the desired `_id` but only returns one.
As said before, if you only one (or only exists one) maybe you can use `find` and `$elemMatch` to avoid a filter by the entire array. But if can be multiple values use `$filter`. |
174,835 | I am playing Minecraft with the [Oceancraft](http://www.minecraftmods.com/oceancraft/) mod installed. Among other things, this adds quicksand, which if you step in you begin to sink and slowly suffocate.
Once you have stepped in quicksand - is there any way to avoid your untimely demise? I've tried walking out of it but when I get to the last block I can't jump over it. I've also tried digging up the neighboring blocks and the offending quicksand itself but I still drown.
Is there any way to avoid drowning in quicksand if you haven't managed to avoid it? | 2014/07/04 | [
"https://gaming.stackexchange.com/questions/174835",
"https://gaming.stackexchange.com",
"https://gaming.stackexchange.com/users/16659/"
]
| If I meet Quicksand on any map, it mostly appears like

So if you stepped in it you can easily dig the 2 neighboring blocks in a depth of 2, kinda like this.

And the you can easily walk off the quicksand the direction you dug.
The most important part is the depth of two blocks to dig, if you just dig one block, it's too high to walk off. | If you have a fast shovel like an efficiency II or a diamond shovel, it is sometimes possible to dig the quicksand you're stuck in, and a jump boost like the Famguide mod's Familiar Rana or a jump boost II beacon can allow you to escape if you don't sink too deep, but a fast shovel will do. But you must try before you sink too deep. If you sink too deep, it's not possible to escape. |
174,835 | I am playing Minecraft with the [Oceancraft](http://www.minecraftmods.com/oceancraft/) mod installed. Among other things, this adds quicksand, which if you step in you begin to sink and slowly suffocate.
Once you have stepped in quicksand - is there any way to avoid your untimely demise? I've tried walking out of it but when I get to the last block I can't jump over it. I've also tried digging up the neighboring blocks and the offending quicksand itself but I still drown.
Is there any way to avoid drowning in quicksand if you haven't managed to avoid it? | 2014/07/04 | [
"https://gaming.stackexchange.com/questions/174835",
"https://gaming.stackexchange.com",
"https://gaming.stackexchange.com/users/16659/"
]
| If I meet Quicksand on any map, it mostly appears like

So if you stepped in it you can easily dig the 2 neighboring blocks in a depth of 2, kinda like this.

And the you can easily walk off the quicksand the direction you dug.
The most important part is the depth of two blocks to dig, if you just dig one block, it's too high to walk off. | Placing a torch in quicksand on adjacent blocks briefly clears the quicksand, long enough to help you escape. |
20,330,154 | I need to display in excel a matrix, but my last column display special caracteres in excel.
I want to convert this last column in number or String, to be display correctly.
My matrix
```
data
= 'A1' [48]
'A2' [44]
'A3' [45]
'A4' [46]
```
This last column (with brackets) seems to be double.
I want something as this :
```
data
= 'A1' 48
'A2' 44
'A3' 45
'A4' 46
``` | 2013/12/02 | [
"https://Stackoverflow.com/questions/20330154",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/359706/"
]
| Try like this:
```
Class<String[]> cls = String[].class;
``` | `String[].class` should do for you. |
18,226,346 | i need to make a div position absolute and make it in center but i used does not make it happen. i have gone crazy trying to make it to the center.
i have tried using left and right value to 0. it should have made the div to the center automatically.
need to figure out what went wrong?
help please!
here is the code that i have tried and stuck
```
.slider-wrap {
width: 1000px;
height: 500px;
left: 0;
right: 0;
top: 100px;
background: #096;
z-index: 99;
margin: 0 auto;
}
``` | 2013/08/14 | [
"https://Stackoverflow.com/questions/18226346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2427498/"
]
| You forgot to set the position to absolute
```
.slider-wrap {
width: 1000px;
height: 500px;
left:0; right:0;
top:100px;
background:#096;
z-index:99;
margin:0px auto;
}
```
Add `position:absolute;`
```
.slider-wrap {
position:absolute;
width: 1000px;
height: 500px;
left:0; right:0;
top:100px;
background:#096;
z-index:99;
margin:0px auto;
}
``` | The proper way to center a div is as such:
```
.slider-wrap {
...
margin-right: auto;
margin-left: auto;
}
```
Also note that `z-index` will not work unless you set the `position` attribute. ie: `position: absolute;` |
18,226,346 | i need to make a div position absolute and make it in center but i used does not make it happen. i have gone crazy trying to make it to the center.
i have tried using left and right value to 0. it should have made the div to the center automatically.
need to figure out what went wrong?
help please!
here is the code that i have tried and stuck
```
.slider-wrap {
width: 1000px;
height: 500px;
left: 0;
right: 0;
top: 100px;
background: #096;
z-index: 99;
margin: 0 auto;
}
``` | 2013/08/14 | [
"https://Stackoverflow.com/questions/18226346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2427498/"
]
| You forgot to set the position to absolute
```
.slider-wrap {
width: 1000px;
height: 500px;
left:0; right:0;
top:100px;
background:#096;
z-index:99;
margin:0px auto;
}
```
Add `position:absolute;`
```
.slider-wrap {
position:absolute;
width: 1000px;
height: 500px;
left:0; right:0;
top:100px;
background:#096;
z-index:99;
margin:0px auto;
}
``` | You need to add `position: absolute;` to your css for absolute positioning.
Note: Also add `position: relative;` to the *parent* element you whish to use as wrapper.
So for example:
```
.slider-container {
position: relative;
width: 100%;
height: 100%;
...
}
.slider-wrap {
position: absolute;
...
}
```
*The width and height of 100% is optional, just added it in case you want the container to take up the whole remaining space or the whole page if it's right after the opening body tag...*
To position the slider-wrap in the center of the screen (so both horizontal and vertical centered), try this:
```
html, body {
width: 100%;
height: 100%;
}
.slider-container {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
...
}
.slider-wrap {
position: absolute;
width: 1000px;
height: 500px;
top: 50%;
left: 50%;
margin-top: -250px; // half the height
margin-left: -500px; // half the width
...
}
```
If you're able to make the slider-wrap display inline with e.g. `display: inline-block;` (keep browser support in mind with this one), then you could use the following instead:
```
.slider-container {
position: relative;
width: 100%;
height: 100%;
text-align: center; // this one makes the slider-wrap center horizontally
...
}
.slider-wrap {
position: relative;
display: inline-block;
width: 1000px;
height: 500px;
vertical-align: middle; // this one does the vertical centering
...
}
```
Another option is using `display: table-cell;`. It's about the same as the previous one:
```
.slider-container {
position: relative;
display: table;
width: 100%;
height: 100%;
text-align: center;
...
}
.slider-wrap {
position: relative;
display: table-cell;
width: 1000px;
height: 500px;
vertical-align: middle;
...
}
```
Also `line-height: ?px;` will make vertical centering possible. But I think this answer is long enough now :-P
**Give it a try.** Fiddle around with this until you're happy with the result :-) |
18,226,346 | i need to make a div position absolute and make it in center but i used does not make it happen. i have gone crazy trying to make it to the center.
i have tried using left and right value to 0. it should have made the div to the center automatically.
need to figure out what went wrong?
help please!
here is the code that i have tried and stuck
```
.slider-wrap {
width: 1000px;
height: 500px;
left: 0;
right: 0;
top: 100px;
background: #096;
z-index: 99;
margin: 0 auto;
}
``` | 2013/08/14 | [
"https://Stackoverflow.com/questions/18226346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2427498/"
]
| You forgot to set the position to absolute
```
.slider-wrap {
width: 1000px;
height: 500px;
left:0; right:0;
top:100px;
background:#096;
z-index:99;
margin:0px auto;
}
```
Add `position:absolute;`
```
.slider-wrap {
position:absolute;
width: 1000px;
height: 500px;
left:0; right:0;
top:100px;
background:#096;
z-index:99;
margin:0px auto;
}
``` | Try this it should work fine.
display:block; |
71,783,339 | I'm trying to replace symbols from object in python, I used
```
df_summary.replace('\(|\)!,"-', '', regex=True)
```
[](https://i.stack.imgur.com/vozsS.jpg)
but it didn't change anything. | 2022/04/07 | [
"https://Stackoverflow.com/questions/71783339",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18737194/"
]
| The replace function is not *in place*. This means that your dataframe will be unchanged, and the result is returned as the return value of the replac function.
You can the the inplace parameter of replace:
```
df_summary.replace('\(|\)!,"-', '', regex=True, inplace=True)
```
Most of the pandas functions are note in place and require if needed either the inplace argument, or the assignement of the result to a new dataframe. | Apart from addind `regex=True` or setting the result to `df_summary` again, your are using a pattern:
```
`\(|\)!,"-`
```
That matches matches either `(` OR the string `\)!,"-`
As you are referring to symbols, and you want to replace all separate chars `(` `)` `!` `,` `"` `-` you can use a repeated character class `[()!,"-]+` to replace multiple consecutive matches at once.
```
df_summary.replace('[()!,"-]+', '', regex=True, inplace=True)
``` |
71,783,339 | I'm trying to replace symbols from object in python, I used
```
df_summary.replace('\(|\)!,"-', '', regex=True)
```
[](https://i.stack.imgur.com/vozsS.jpg)
but it didn't change anything. | 2022/04/07 | [
"https://Stackoverflow.com/questions/71783339",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18737194/"
]
| You can either do
```
df_summary.replace('\(|\)!,"-', '', regex=True, inplace=True)
```
or
```
df_summary = df_summary.replace('\(|\)!,"-', '', regex=True)
```
When you only do `df_summary.replace...`, this line returns you a pandas list. You forgot to save it. Please add comments to further assist you | Apart from addind `regex=True` or setting the result to `df_summary` again, your are using a pattern:
```
`\(|\)!,"-`
```
That matches matches either `(` OR the string `\)!,"-`
As you are referring to symbols, and you want to replace all separate chars `(` `)` `!` `,` `"` `-` you can use a repeated character class `[()!,"-]+` to replace multiple consecutive matches at once.
```
df_summary.replace('[()!,"-]+', '', regex=True, inplace=True)
``` |
14,870,665 | I'm developing a web solution to run in the clients existing portal. In this portal they already handle F1 differently from the default behaviour.
I would like to add a "Help" icon to my solution that when clicked simulates pressing F1. Of course I would like the solution to be as cross browser compatible as possible but the final version will run solely in Internet Explorer 8 (and actually with the compatibility button pressed - GRRRR).
I have found numerous functions to handle pressing F1 but non that describes how to simulate pressing F1 programmatically.
I'm using jQuery 1.8.2 if that helps...
Thanks in advance | 2013/02/14 | [
"https://Stackoverflow.com/questions/14870665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1480182/"
]
| You can use this to catch the event in IE:
* [Internet Explorer or any Browser F1 keypress displays your own help](https://stackoverflow.com/questions/3405412/internet-explorer-or-any-browser-f1-keypress-displays-your-own-help)
and use these to fire the event:
* [Is it possible to simulate key press events programmatically?](https://stackoverflow.com/questions/596481/simulate-javascript-key-events)
* <http://openwritings.net/public/javascript/simulate-pressing-key> | On this page <https://github.com/jeresig/jquery.hotkeys#readme> there is this quote:
*"Others, (IE) either let you handle built-in short-cuts, but will add their functionality after your code has executed. Or (Opera/Safari) will not pass those events to the DOM at all.
So, if you bind Ctrl-Q or Alt-F4 and your Safari/Opera window is closed don't be surprised."*
Which means that you probably can't do what you want to do, as pressing F1 will launch the help from Windows. |
14,870,665 | I'm developing a web solution to run in the clients existing portal. In this portal they already handle F1 differently from the default behaviour.
I would like to add a "Help" icon to my solution that when clicked simulates pressing F1. Of course I would like the solution to be as cross browser compatible as possible but the final version will run solely in Internet Explorer 8 (and actually with the compatibility button pressed - GRRRR).
I have found numerous functions to handle pressing F1 but non that describes how to simulate pressing F1 programmatically.
I'm using jQuery 1.8.2 if that helps...
Thanks in advance | 2013/02/14 | [
"https://Stackoverflow.com/questions/14870665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1480182/"
]
| You can use this to catch the event in IE:
* [Internet Explorer or any Browser F1 keypress displays your own help](https://stackoverflow.com/questions/3405412/internet-explorer-or-any-browser-f1-keypress-displays-your-own-help)
and use these to fire the event:
* [Is it possible to simulate key press events programmatically?](https://stackoverflow.com/questions/596481/simulate-javascript-key-events)
* <http://openwritings.net/public/javascript/simulate-pressing-key> | ```
jQuery.event.trigger({ type : 'keypress', which : 112 });
``` |
13,647 | I am attempting to complete some *simple* homework examples my Russian teacher has given me. (I am learning Russian in my free time, whilst I work full-time)
The example given in my textbook is:
>
> Given: Наша квартира была приватизирована пять лет назад.
>
>
> Desired: *Нашу квартиру приватизировали* пять лет назад.
>
>
>
I require the following clarifications:
1. Is my assumption that the sentence is going from the *active voice* in the *given* sentence, to the *passive voice* in the *desired* sentence, correct?
2. What part of speech is the word *«приватизирована»*? (My usual search source, [Wiktionary](https://wiktionary.org) is failing me.)
3. What is happening to the above mentioned word when it moves from the *given* sentence to the *desired* sentence?
4. Why does the above mentioned word decline into the plural past tense form, whereas in the first sentence *«быть»* is in its feminine form?
5. How does it happen? What topic or topics must I read, to elaborate this topic further?
6. Are there any rules regarding this? | 2016/12/09 | [
"https://russian.stackexchange.com/questions/13647",
"https://russian.stackexchange.com",
"https://russian.stackexchange.com/users/8075/"
]
| >
> Наша квартира *была приватизирована* пять лет назад.
>
>
>
The sentence is in the **passive voice** in the past formed with *быть* which agrees with the subject наша квартира in gender(feminine ) = была + приватизирована (past passive participle, short form) also agreeing in gender with the subject.The topic is *страдательный залог*.
>
> Нашу квартиру приватизировали пять лет назад.
>
>
>
The sentence is in the **active voice**, impersonal, past tense,formed with the verb which agrees with the "dummy" **they** (приватизировали), which is left out. The object is нашу квартиру (accusative sing).The topic is *безличные предложения*.
Both sentences mean the same and have a "hidden" agent. | >
> Is my assumption that the sentence is going from the active voice in the given sentence, to the passive voice in the desired sentence, correct?
>
>
>
Well, actually it's vice versa: passive to active.
>
> What part of speech is the word «приватизирована»?
>
>
>
This is "*краткое страдательное причастие*" (passive participle, short form, past tense, singular, feminine).
>
> What is happening to the above mentioned word when it moves from the given sentence to the desired sentence?
>
>
> Why does the above mentioned word decline into the plural past tense form, whereas in the first sentence «быть» is in its feminine form?
>
>
>
This is impersonate construction which is used along with "normal" active voice plural. I.e. "[they] did" (with "they" omitted) in Russian doesn't mean anyone in particular. |
6,402,339 | I would like to implement a robust IPC solution between a single JVM applet and a C++ application running on the same machine. What is the best approach for doing so?
Any suggestions will be greatly appreciated! Thanks! | 2011/06/19 | [
"https://Stackoverflow.com/questions/6402339",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/805320/"
]
| sockets are about your best (only reasonable?) choice. although if you are running an applet, you will have to deal with access permissions issues (signing the applet will probably solve these). | Sockets as a transport protocol.
JSON as a message protocol, with optional length header or trailing zero if required. |
35,815,261 | Hybrid apps are obviously a bit new, so it's hard to find good information on this. I know that I need to allow cross origin resource sharing on my server side pages, but this clearly adds a security flaw. On a phonegap/cordova app, I only have client-side control with ajax calls to my server-side page. This means that anyone can access my php pages. This means that anyone can essentially mimic my app by accessing all my data like account info, etc. My question is how can I confirm that only my app is accessing these pages? Please provide specific coding examples. | 2016/03/05 | [
"https://Stackoverflow.com/questions/35815261",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3822526/"
]
| I answered your question, and many others like it, in this blog post: [Client authenticity is not the server's problem](https://paragonie.com/blog/2016/03/client-authenticity-is-not-server-s-problem).
>
> One of the most basic rules of application security is **input validation**. The reason this rule is so fundamental is because your server only has control (and visibility) over the software running on itself. Every other device on the Internet is a black box that you can communicate with over networking protocols. You can't see what it's doing, you only see the messages that it sends.
>
>
>
...
>
> The server should remain agnostic to the client.
>
>
> The software on the client and the software on the server should have a mutual distrust towards each other. Any messages that the server receives should be validated for correctness and handled with care. Data should never be mixed with code if you can help it.
>
>
>
...
>
> The take-away is: Instead of trying to control your users, focus on making their misbehavior inconsequential to the stability and integrity of your server.
>
>
> | This question is asked here every day.
What you want to do is logically impossible. There is no solution. You cannot control the client. |
918,667 | I cannot connect to my server via ssh using my computer, but I can connect to this server via my cell phone using termius app. I have checked `/etc/hosts.allow` and `/etc/hosts.deny` and my iptables, and I have alse searched google, it seems no answer fits this problem. I don't know how to solve it , here is `ssh -v 183.17.228.80` output
```
debug1: Connecting to 183.17.228.80 [183.17.228.80] port 22.
debug1: Connection established.=======================
debug1: permanently_set_uid: 0/0
debug1: SELinux support disabled
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
ssh_exchange_identification: read: Connection reset by peer
```
I can ping this server, here is telnet
```
telnet 183.17.228.29 22
Trying 183.17.228.29...
Connected to 183.17.228.29.
Escape character is '^]'.
Connection closed by foreign host.
``` | 2017/05/25 | [
"https://askubuntu.com/questions/918667",
"https://askubuntu.com",
"https://askubuntu.com/users/673328/"
]
| The way I solved the problem is I went to the host machine and ran a few commands.
```
sudo mkdir /var/run/sshd
sudo chmod 755 -R /var/run/sshd
sudo service ssh restart
```
I got connected to the machine after that. | 1. Check that sshd in installed and running of the server.
2. Make sure that the daemon is installed and started.You must be able to 'man sshd'. I think that package it is in is open-ssl, and you will need to start the daemon ( and stop it when you don't need it.). |
918,667 | I cannot connect to my server via ssh using my computer, but I can connect to this server via my cell phone using termius app. I have checked `/etc/hosts.allow` and `/etc/hosts.deny` and my iptables, and I have alse searched google, it seems no answer fits this problem. I don't know how to solve it , here is `ssh -v 183.17.228.80` output
```
debug1: Connecting to 183.17.228.80 [183.17.228.80] port 22.
debug1: Connection established.=======================
debug1: permanently_set_uid: 0/0
debug1: SELinux support disabled
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
ssh_exchange_identification: read: Connection reset by peer
```
I can ping this server, here is telnet
```
telnet 183.17.228.29 22
Trying 183.17.228.29...
Connected to 183.17.228.29.
Escape character is '^]'.
Connection closed by foreign host.
``` | 2017/05/25 | [
"https://askubuntu.com/questions/918667",
"https://askubuntu.com",
"https://askubuntu.com/users/673328/"
]
| I had the same issue but after restarting the sshd daemon I could connect to host.
```
sudo systemctl restart sshd && systemctl status sshd
```
This is only a temporary workaround until you increase the MaxAuthTries parameter. | After many days, I do not know what was the problem in the end, perhaps I really had too many tries and had to wait. Or it was another thing, like a missing openssh installation. I posted a [working guide how to use ssh to download a git repo](https://stackoverflow.com/a/66648529/11154841) here, with the core of it as follows:
```
# first image only to download the git repo
FROM alpine as MY_TMP_GIT_IMAGE
RUN apk add --no-cache git
RUN mkdir -p /root/.ssh && chmod 700 /root/.ssh
COPY /.ssh/id_ed25519 /root/.ssh/id_ed25519
RUN chmod 600 /root/.ssh/id_ed25519
RUN apk -yqq add --no-cache openssh-client && ssh-keyscan -t ed25519 -H gitlab.com >> /root/.ssh/known_hosts
RUN git clone [email protected]:GITLAB_USERNAME/test.git
RUN rm -r /root/.ssh
# Start of the second image
FROM MY_BASE_IMAGE
COPY --from=MY_TMP_GIT_IMAGE /MY_GIT_REPO ./MY_GIT_REPO
``` |
918,667 | I cannot connect to my server via ssh using my computer, but I can connect to this server via my cell phone using termius app. I have checked `/etc/hosts.allow` and `/etc/hosts.deny` and my iptables, and I have alse searched google, it seems no answer fits this problem. I don't know how to solve it , here is `ssh -v 183.17.228.80` output
```
debug1: Connecting to 183.17.228.80 [183.17.228.80] port 22.
debug1: Connection established.=======================
debug1: permanently_set_uid: 0/0
debug1: SELinux support disabled
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
ssh_exchange_identification: read: Connection reset by peer
```
I can ping this server, here is telnet
```
telnet 183.17.228.29 22
Trying 183.17.228.29...
Connected to 183.17.228.29.
Escape character is '^]'.
Connection closed by foreign host.
``` | 2017/05/25 | [
"https://askubuntu.com/questions/918667",
"https://askubuntu.com",
"https://askubuntu.com/users/673328/"
]
| The above error happen when you have limit of failed try to authenticate to the server and you have too many ssh keys on your client (more than value of MaxAuthTries)
What you can try is to increase the value of MaxAuthTries and restart sshd daemon. Or you can limit the number of keys in your `~/.ssh` directory and use subdirectories and `~/.ssh/config` file to define key per host/group of hosts | After many days, I do not know what was the problem in the end, perhaps I really had too many tries and had to wait. Or it was another thing, like a missing openssh installation. I posted a [working guide how to use ssh to download a git repo](https://stackoverflow.com/a/66648529/11154841) here, with the core of it as follows:
```
# first image only to download the git repo
FROM alpine as MY_TMP_GIT_IMAGE
RUN apk add --no-cache git
RUN mkdir -p /root/.ssh && chmod 700 /root/.ssh
COPY /.ssh/id_ed25519 /root/.ssh/id_ed25519
RUN chmod 600 /root/.ssh/id_ed25519
RUN apk -yqq add --no-cache openssh-client && ssh-keyscan -t ed25519 -H gitlab.com >> /root/.ssh/known_hosts
RUN git clone [email protected]:GITLAB_USERNAME/test.git
RUN rm -r /root/.ssh
# Start of the second image
FROM MY_BASE_IMAGE
COPY --from=MY_TMP_GIT_IMAGE /MY_GIT_REPO ./MY_GIT_REPO
``` |
918,667 | I cannot connect to my server via ssh using my computer, but I can connect to this server via my cell phone using termius app. I have checked `/etc/hosts.allow` and `/etc/hosts.deny` and my iptables, and I have alse searched google, it seems no answer fits this problem. I don't know how to solve it , here is `ssh -v 183.17.228.80` output
```
debug1: Connecting to 183.17.228.80 [183.17.228.80] port 22.
debug1: Connection established.=======================
debug1: permanently_set_uid: 0/0
debug1: SELinux support disabled
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
ssh_exchange_identification: read: Connection reset by peer
```
I can ping this server, here is telnet
```
telnet 183.17.228.29 22
Trying 183.17.228.29...
Connected to 183.17.228.29.
Escape character is '^]'.
Connection closed by foreign host.
``` | 2017/05/25 | [
"https://askubuntu.com/questions/918667",
"https://askubuntu.com",
"https://askubuntu.com/users/673328/"
]
| The way I solved the problem is I went to the host machine and ran a few commands.
```
sudo mkdir /var/run/sshd
sudo chmod 755 -R /var/run/sshd
sudo service ssh restart
```
I got connected to the machine after that. | Create an new ssh key pair for user authentication. [SSH Keys and Public Key Authentication guide](https://www.ssh.com/ssh/keygen/)
Just follow the guide. |
918,667 | I cannot connect to my server via ssh using my computer, but I can connect to this server via my cell phone using termius app. I have checked `/etc/hosts.allow` and `/etc/hosts.deny` and my iptables, and I have alse searched google, it seems no answer fits this problem. I don't know how to solve it , here is `ssh -v 183.17.228.80` output
```
debug1: Connecting to 183.17.228.80 [183.17.228.80] port 22.
debug1: Connection established.=======================
debug1: permanently_set_uid: 0/0
debug1: SELinux support disabled
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
ssh_exchange_identification: read: Connection reset by peer
```
I can ping this server, here is telnet
```
telnet 183.17.228.29 22
Trying 183.17.228.29...
Connected to 183.17.228.29.
Escape character is '^]'.
Connection closed by foreign host.
``` | 2017/05/25 | [
"https://askubuntu.com/questions/918667",
"https://askubuntu.com",
"https://askubuntu.com/users/673328/"
]
| Just **reboot your server** which you want to ssh. It worked for me, previously I was facing the same issue. | This could be because you do not have an openssh server running on your ubuntu. You can run the below command to check the status of your openssh server.
```
ubuntu@ubuntu:~$ sudo systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-03-20 11:52:16 GMT; 5min ago
Process: 1034 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 1058 (sshd)
Tasks: 1
Memory: 5.1M
CPU: 122ms
CGroup: /system.slice/ssh.service
└─1058 /usr/sbin/sshd -D
Mar 20 11:52:15 ubuntu systemd[1]: Starting OpenBSD Secure Shell server...
Mar 20 11:52:16 ubuntu sshd[1058]: Server listening on 0.0.0.0 port 22.
Mar 20 11:52:16 ubuntu sshd[1058]: Server listening on :: port 22.
Mar 20 11:52:16 ubuntu systemd[1]: Started OpenBSD Secure Shell server.
Mar 20 11:52:24 ubuntu sshd[1131]: Connection closed by 10.0.2.2 port 60566 [preauth]
Mar 20 11:53:59 ubuntu sshd[1135]: Accepted password for ubuntu from 10.0.2.2 port 60654 ssh2
Mar 20 11:53:59 ubuntu sshd[1135]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0)
Mar 20 11:57:48 ubuntu sshd[1238]: Accepted password for ubuntu from 10.0.2.2 port 61124 ssh2
Mar 20 11:57:48 ubuntu sshd[1238]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0)
```
If the status is not `active (running)`, you might want to install and/or start the openssh-server. You can do so with the commands shown below.
```
sudo apt update
sudo apt install openssh-server
``` |
918,667 | I cannot connect to my server via ssh using my computer, but I can connect to this server via my cell phone using termius app. I have checked `/etc/hosts.allow` and `/etc/hosts.deny` and my iptables, and I have alse searched google, it seems no answer fits this problem. I don't know how to solve it , here is `ssh -v 183.17.228.80` output
```
debug1: Connecting to 183.17.228.80 [183.17.228.80] port 22.
debug1: Connection established.=======================
debug1: permanently_set_uid: 0/0
debug1: SELinux support disabled
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
ssh_exchange_identification: read: Connection reset by peer
```
I can ping this server, here is telnet
```
telnet 183.17.228.29 22
Trying 183.17.228.29...
Connected to 183.17.228.29.
Escape character is '^]'.
Connection closed by foreign host.
``` | 2017/05/25 | [
"https://askubuntu.com/questions/918667",
"https://askubuntu.com",
"https://askubuntu.com/users/673328/"
]
| My solution is add my local IP address to the `/etc/hosts.allow`:
```
sshd:192.168.10.88:allow
```
this works for me. | Create an new ssh key pair for user authentication. [SSH Keys and Public Key Authentication guide](https://www.ssh.com/ssh/keygen/)
Just follow the guide. |
918,667 | I cannot connect to my server via ssh using my computer, but I can connect to this server via my cell phone using termius app. I have checked `/etc/hosts.allow` and `/etc/hosts.deny` and my iptables, and I have alse searched google, it seems no answer fits this problem. I don't know how to solve it , here is `ssh -v 183.17.228.80` output
```
debug1: Connecting to 183.17.228.80 [183.17.228.80] port 22.
debug1: Connection established.=======================
debug1: permanently_set_uid: 0/0
debug1: SELinux support disabled
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
ssh_exchange_identification: read: Connection reset by peer
```
I can ping this server, here is telnet
```
telnet 183.17.228.29 22
Trying 183.17.228.29...
Connected to 183.17.228.29.
Escape character is '^]'.
Connection closed by foreign host.
``` | 2017/05/25 | [
"https://askubuntu.com/questions/918667",
"https://askubuntu.com",
"https://askubuntu.com/users/673328/"
]
| I had the same issue but after restarting the sshd daemon I could connect to host.
```
sudo systemctl restart sshd && systemctl status sshd
```
This is only a temporary workaround until you increase the MaxAuthTries parameter. | Create an new ssh key pair for user authentication. [SSH Keys and Public Key Authentication guide](https://www.ssh.com/ssh/keygen/)
Just follow the guide. |
918,667 | I cannot connect to my server via ssh using my computer, but I can connect to this server via my cell phone using termius app. I have checked `/etc/hosts.allow` and `/etc/hosts.deny` and my iptables, and I have alse searched google, it seems no answer fits this problem. I don't know how to solve it , here is `ssh -v 183.17.228.80` output
```
debug1: Connecting to 183.17.228.80 [183.17.228.80] port 22.
debug1: Connection established.=======================
debug1: permanently_set_uid: 0/0
debug1: SELinux support disabled
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
ssh_exchange_identification: read: Connection reset by peer
```
I can ping this server, here is telnet
```
telnet 183.17.228.29 22
Trying 183.17.228.29...
Connected to 183.17.228.29.
Escape character is '^]'.
Connection closed by foreign host.
``` | 2017/05/25 | [
"https://askubuntu.com/questions/918667",
"https://askubuntu.com",
"https://askubuntu.com/users/673328/"
]
| The way I solved the problem is I went to the host machine and ran a few commands.
```
sudo mkdir /var/run/sshd
sudo chmod 755 -R /var/run/sshd
sudo service ssh restart
```
I got connected to the machine after that. | The above error happen when you have limit of failed try to authenticate to the server and you have too many ssh keys on your client (more than value of MaxAuthTries)
What you can try is to increase the value of MaxAuthTries and restart sshd daemon. Or you can limit the number of keys in your `~/.ssh` directory and use subdirectories and `~/.ssh/config` file to define key per host/group of hosts |
918,667 | I cannot connect to my server via ssh using my computer, but I can connect to this server via my cell phone using termius app. I have checked `/etc/hosts.allow` and `/etc/hosts.deny` and my iptables, and I have alse searched google, it seems no answer fits this problem. I don't know how to solve it , here is `ssh -v 183.17.228.80` output
```
debug1: Connecting to 183.17.228.80 [183.17.228.80] port 22.
debug1: Connection established.=======================
debug1: permanently_set_uid: 0/0
debug1: SELinux support disabled
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
ssh_exchange_identification: read: Connection reset by peer
```
I can ping this server, here is telnet
```
telnet 183.17.228.29 22
Trying 183.17.228.29...
Connected to 183.17.228.29.
Escape character is '^]'.
Connection closed by foreign host.
``` | 2017/05/25 | [
"https://askubuntu.com/questions/918667",
"https://askubuntu.com",
"https://askubuntu.com/users/673328/"
]
| That actually means that your IP is blacklisted by the server. Try to whitelist your IP address to be able to login.
You may take a look at the /etc/hosts list to see if your server's ip address have changed. | Create an new ssh key pair for user authentication. [SSH Keys and Public Key Authentication guide](https://www.ssh.com/ssh/keygen/)
Just follow the guide. |
918,667 | I cannot connect to my server via ssh using my computer, but I can connect to this server via my cell phone using termius app. I have checked `/etc/hosts.allow` and `/etc/hosts.deny` and my iptables, and I have alse searched google, it seems no answer fits this problem. I don't know how to solve it , here is `ssh -v 183.17.228.80` output
```
debug1: Connecting to 183.17.228.80 [183.17.228.80] port 22.
debug1: Connection established.=======================
debug1: permanently_set_uid: 0/0
debug1: SELinux support disabled
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
ssh_exchange_identification: read: Connection reset by peer
```
I can ping this server, here is telnet
```
telnet 183.17.228.29 22
Trying 183.17.228.29...
Connected to 183.17.228.29.
Escape character is '^]'.
Connection closed by foreign host.
``` | 2017/05/25 | [
"https://askubuntu.com/questions/918667",
"https://askubuntu.com",
"https://askubuntu.com/users/673328/"
]
| This could be because you do not have an openssh server running on your ubuntu. You can run the below command to check the status of your openssh server.
```
ubuntu@ubuntu:~$ sudo systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-03-20 11:52:16 GMT; 5min ago
Process: 1034 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 1058 (sshd)
Tasks: 1
Memory: 5.1M
CPU: 122ms
CGroup: /system.slice/ssh.service
└─1058 /usr/sbin/sshd -D
Mar 20 11:52:15 ubuntu systemd[1]: Starting OpenBSD Secure Shell server...
Mar 20 11:52:16 ubuntu sshd[1058]: Server listening on 0.0.0.0 port 22.
Mar 20 11:52:16 ubuntu sshd[1058]: Server listening on :: port 22.
Mar 20 11:52:16 ubuntu systemd[1]: Started OpenBSD Secure Shell server.
Mar 20 11:52:24 ubuntu sshd[1131]: Connection closed by 10.0.2.2 port 60566 [preauth]
Mar 20 11:53:59 ubuntu sshd[1135]: Accepted password for ubuntu from 10.0.2.2 port 60654 ssh2
Mar 20 11:53:59 ubuntu sshd[1135]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0)
Mar 20 11:57:48 ubuntu sshd[1238]: Accepted password for ubuntu from 10.0.2.2 port 61124 ssh2
Mar 20 11:57:48 ubuntu sshd[1238]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0)
```
If the status is not `active (running)`, you might want to install and/or start the openssh-server. You can do so with the commands shown below.
```
sudo apt update
sudo apt install openssh-server
``` | I had this same thing happen, and needed to ssh -v 'ip addr' and then i saw that i needed to accept the certificate.
Also may be an ACL or route rule blocking putty: example -
Putty client has 10.x.x.x addr with firewalls blocking enterprise network from talking to DMZ hosts, but your cell phone at 58.x.x.x whatever public ip address can talk to the dmz host youre trying to reach.
so I'd look at the ssh -v info when you try to connect again, see if you can glean any info, and then check if there are rules keeping you from getting to your server at a firewall or router level, not in a denyhosts file on the server itself. |
39,529,824 | We have a requirement, that we want to select k random rows from a database.
So, our intial thought was going like this :-
```
table.objects.filter(..).order_by('?')[:k]
```
but then we read over the internet that this is highly inefficient solution so we came up with this (not so innovative):-
```
random.sample(table.objects.filter(..), k)
```
But this seems to be more slower than previous.
So, we want to know what is correct approach for selection exactly *k* rows from the database, which in our case is postgres. | 2016/09/16 | [
"https://Stackoverflow.com/questions/39529824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3596887/"
]
| You can do it like this:
```
<tr ng-repeat="(key, value) in data.Test">
<td> {{value.Testing.static.name}} </td>
</tr>
```
<https://jsfiddle.net/nh5zxoka/3/> | ```js
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.data = {
"Test": [{
"Testing": {
"static": {
"name": "test01"
},
"testboolean": true
}
}, {
"Testing": {
"static": {
"name": "test02"
},
"secondstatic": "yes"
}
}, {
"Testing": {
"static": {
"name": "test03"
}
}
}]
};
};
```
```html
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
<table>
<tr ng-repeat="d in data.Test">
<td> {{d.Testing.static.name}} </td>
</tr>
</table>
</div>
``` |
39,529,824 | We have a requirement, that we want to select k random rows from a database.
So, our intial thought was going like this :-
```
table.objects.filter(..).order_by('?')[:k]
```
but then we read over the internet that this is highly inefficient solution so we came up with this (not so innovative):-
```
random.sample(table.objects.filter(..), k)
```
But this seems to be more slower than previous.
So, we want to know what is correct approach for selection exactly *k* rows from the database, which in our case is postgres. | 2016/09/16 | [
"https://Stackoverflow.com/questions/39529824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3596887/"
]
| You can do it like this:
```
<tr ng-repeat="(key, value) in data.Test">
<td> {{value.Testing.static.name}} </td>
</tr>
```
<https://jsfiddle.net/nh5zxoka/3/> | You do not need the (key, value) here, just
```
<div ng-controller="MyCtrl">
<table>
<tr ng-repeat="val in data.Test">
<td> {{val.Testing.static.name}} </td>
</tr>
</table>
</div>
```
key[0] - is just the first letter of the key "Test" |
39,529,824 | We have a requirement, that we want to select k random rows from a database.
So, our intial thought was going like this :-
```
table.objects.filter(..).order_by('?')[:k]
```
but then we read over the internet that this is highly inefficient solution so we came up with this (not so innovative):-
```
random.sample(table.objects.filter(..), k)
```
But this seems to be more slower than previous.
So, we want to know what is correct approach for selection exactly *k* rows from the database, which in our case is postgres. | 2016/09/16 | [
"https://Stackoverflow.com/questions/39529824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3596887/"
]
| You can do it like this:
```
<tr ng-repeat="(key, value) in data.Test">
<td> {{value.Testing.static.name}} </td>
</tr>
```
<https://jsfiddle.net/nh5zxoka/3/> | Something like this will do the trick:
```
<div ng-controller="MyCtrl">
<table>
<tr ng-repeat="value in data.Test">
<td> {{value.Testing.static.name}} </td>
</tr>
</table>
</div>
```
If you are sure that the hierarchy of your JSON will remain the same, then there is no need to iterate in the json properties by using `(key, value) in data`.
[Updated fiddle](https://jsfiddle.net/0gucxcq2/). |
532,879 | $$\int\frac{\mathrm dx}{\sqrt x \cos(1-\sqrt x)}$$
please provide a hint about the substitution. The website gives a long answer [See here.](http://www.wolframalpha.com/input/?i=int%201/%28x%5E%281/2%29cos%281-x%5E%281/2%29%29)
Wondering if there is a simplification. | 2013/10/20 | [
"https://math.stackexchange.com/questions/532879",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/100812/"
]
| **Hint**:
$$u = 1 - \sqrt{x} \implies du = -\frac{1}{2 \sqrt{x}} dx$$
so the integral can be written as
$$\int \frac{1}{\cos(1 - \sqrt{x})} \frac{dx}{\sqrt{x}} = \int \frac{1}{\cos{u}} \frac{du}{-2} = -\frac{1}{2} \int \sec{u} du$$ | HINT: Let $u=1-\sqrt{x}$, and get the trig function out of the denominator. |
53,288,831 | Ruby's json library defaults to converting Time objects to Strings
```
require 'json'
Time.at(1000).utc.to_json # => "\"1970-01-01 00:16:40 UTC\""
```
The problem with this is that we lose precision. I'd like to\_json to produce a float instead.
I also know there are some workarounds using `oj` or requiring `json/add/time`, but both of these add excess data to the output and aren't the most portable.
A straightforward approach is to monkey patch Time, although I'm not fond of doing that, especially to core classes
```
class Time
def to_json(*a)
self.to_f.to_json(*a)
end
end
```
Are there any better approaches? | 2018/11/13 | [
"https://Stackoverflow.com/questions/53288831",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1449987/"
]
| >
> *A straightforward approach is to monkey patch Time, although I'm not fond of doing that, especially to core classes*
>
>
>
There's no JSON format for dates, as far as JSON cares they're just strings. Most languages understand [ISO 8601](https://github.com/ruby/ruby/blob/4444025d16ae1a586eee6a0ac9bdd09e33833f3c/ext/json/lib/json/add/time.rb), and that's what `Time#to_json` produces. So long as `Time#to_json` continues to produce an ISO 8601 datetime you'll remain backwards compatible.
```
require 'json'
require 'time' # for Time#iso8601 and Time.parse
class Time
def to_json
return self.iso8601(6).to_json
end
end
time = Time.at(1000.123456)
puts "Before: #{time.iso8601(6)}"
json_time = Time.at(1000.123456).to_json
puts "As JSON: #{json_time}"
# Demonstrate round tripping.
puts "Round trip: #{Time.parse(JSON.parse(json_time)).iso8601(6)}"
```
```
Before: 1969-12-31T16:16:40.123456-08:00
As JSON: "1969-12-31T16:16:40.123456-08:00"
Round trip: 1969-12-31T16:16:40.123456-08:00
```
---
If you're not comfortable with monkey patching globally, you can monkey patch in isolation by implementing `around`.
```
class Time
require 'time'
require 'json'
def precise_to_json(*args)
return iso8601(6).to_json(*args)
end
alias_method :original_to_json, :to_json
end
module PreciseJson
def self.around
# Swap in our precise_to_json as Time#to_json
Time.class_eval {
alias_method :to_json, :precise_to_json
}
# This block will use Time#precise_to_json as Time#to_json
yield
# Always put the original Time#to_json back.
ensure
Time.class_eval {
alias_method :to_json, :original_to_json
}
end
end
obj = {
time: Time.at(1000.123456),
string: "Basset Hounds Got Long Ears"
}
puts "Before: #{obj.to_json}"
PreciseJson.around {
puts "Around: #{obj.to_json}"
}
puts "After: #{obj.to_json}"
begin
PreciseJson.around {
raise Exception
}
rescue Exception
end
puts "After exception: #{obj.to_json}"
```
```
Before: {"time":"1969-12-31 16:16:40 -0800","string":"Basset Hounds Got Long Ears"}
Around: {"time":"1969-12-31T16:16:40.123456-08:00","string":"Basset Hounds Got Long Ears"}
After: {"time":"1969-12-31 16:16:40 -0800","string":"Basset Hounds Got Long Ears"}
After exception: {"time":"1969-12-31 16:16:40 -0800","string":"Basset Hounds Got Long Ears"}
``` | You could save the number of nanoseconds since the Epoch.
```
require 'time'
require 'json'
t = Time.now
#=> 2018-11-13 13:23:32 -0800
json = [t.to_i, t.nsec].to_json
#=> "[1542144212,883611300]"
secs, nsecs = JSON.parse(json)
#=> [1542144212, 883611300]
r = secs + 10**-9 * nsecs
#=> (15421442128836113/10000000)
tt = Time.at r
#=> 2018-11-13 13:23:32 -0800
t == tt
#=> true
```
Note `(10**-9).class #=> Rational`. |
39,379,637 | I would like to use multiple `geom_smooth` layers in a single ggplot2 chart. When I try to do that, the color scheme gets screwed up. Here is an example demonstrating what is happening.
We construct a simple dataframe we want to visualize.
```
df = data.frame(x = c("a", "b", "c"),
y1 = seq(1, 3),
y1_upr = seq(2, 4),
y1_lwr = seq(0, 2),
y2 = seq(2, 4),
y2_upr = seq(2.5, 4.5),
y2_lwr = seq(1.5, 3.5))
```
We can visualize y1 and y2 easily.
```
plot_obj = ggplot(data = df, aes(x = x, group = 1)) +
geom_line(aes(y = y1, colour = "y1")) +
geom_line(aes(y = y2, colour = "y2")) +
scale_colour_manual("", breaks = c("y1", "y2"), values = c("blue", "red"))
plot_obj
```
[](https://i.stack.imgur.com/s1og5.png)
If we add one `geom_smooth`, the behavior is still as expected.
```
plot_obj +
geom_smooth(aes(y = y1, ymin = y1_lwr, ymax = y1_upr), stat="identity", fill="blue", alpha=0.2)
```
[](https://i.stack.imgur.com/vzztE.png)
Lastly, we add the second `geom_smooth` layer.
```
plot_obj +
geom_smooth(aes(y = y1, ymin = y1_lwr, ymax = y1_upr), stat="identity", fill="blue", alpha=0.2) +
geom_smooth(aes(y = y2, ymin = y2_lwr, ymax = y2_upr), stat="identity", fill="red", alpha=0.2)
```
[](https://i.stack.imgur.com/cxFhg.png)
Notice that the top line is no longer red in the last chart. Why is this happening and how can it be fixed? Thank you! | 2016/09/07 | [
"https://Stackoverflow.com/questions/39379637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2252852/"
]
| Certainly reshaping your dataset will make things easier, and is the recommended approach. However, if you want to keep using separate layers:
As you haven't mapped a `color` for `geom_smooth`, it uses the default color of blue for the smoothed lines it drew. If you want just the ribbon, use `geom_ribbon` instead.
```
ggplot(data = df, aes(x = x, group = 1)) +
geom_line(aes(y = y1, colour = "y1")) +
geom_line(aes(y = y2, colour = "y2")) +
scale_colour_manual("", breaks = c("y1", "y2"), values = c("blue", "red")) +
geom_ribbon(aes(ymin = y1_lwr, ymax = y1_upr), stat="identity", fill="blue", alpha=0.2) +
geom_ribbon(aes(ymin = y2_lwr, ymax = y2_upr), stat="identity", fill="red", alpha=0.2)
```
[](https://i.stack.imgur.com/7cOAy.png)
Otherwise you'll need to map your colors for each smooth layer within `aes` or set them manually to red and blue or NA outside of `aes`.
```
ggplot(data = df, aes(x = x, group = 1)) +
geom_line(aes(y = y1, colour = "y1")) +
geom_line(aes(y = y2, colour = "y2")) +
scale_colour_manual("", breaks = c("y1", "y2"), values = c("blue", "red")) +
geom_smooth(aes(y = y1, ymin = y1_lwr, ymax = y1_upr, colour = "y1"),
stat="identity", fill="blue", alpha=0.2) +
geom_smooth(aes(y = y2, ymin = y2_lwr, ymax = y2_upr, colour = "y2"),
stat="identity", fill="red", alpha=0.2)
```
[](https://i.stack.imgur.com/G6qgf.png) | I would probably do something closer to this:
```
library(dplyr)
df1 <- df %>%
select(x,contains("y1")) %>%
rename(y = y1, y_upr = y1_upr, y_lwr = y1_lwr) %>%
mutate(grp = "y1")
df2 <- df %>%
select(x,contains("y2")) %>%
rename(y = y2, y_upr = y2_upr, y_lwr = y2_lwr) %>%
mutate(grp = "y2")
df_all <- bind_rows(df1, df2)
ggplot(df_all,aes(x = x, y = y, ymin = y_lwr, ymax = y_upr, group = grp)) +
geom_line(aes(color = grp)) +
geom_ribbon(aes(fill = grp), alpha = 0.2)
```
[](https://i.stack.imgur.com/tsYXG.png) |
44,392,223 | I am trying to perform two processes using bean, my problem is that I can not find the way these processes are performed continuously. The first process is to send an object and the second process is the response of the object.
```
@Component
public class Proceso implements InitializingBean{
private static final String XML_SCHEMA_LOCATION = "/proceso/model/schema/proceso.xsd";
private Envio envio;
private Respuesta respuesta;
public void Proceso_envio(Proceso proceso, OutputStream outputstream) throws JAXBException{
envio.marshal(proceso, outputstream);}
public void Proceso_respuesta(InputStream inputstream) throws JAXBException, FileNotFoundException{
Object obj = unmarshaller.unmarshal(inputStream);
return (Proceso_respuesta) obj;}
@Override
public void afterPropertiesSet() throws Exception{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(getClass().getResource(XML_SCHEMA_LOCATION));
JAXBContext jc = JAXBContext.newInstance(Envio.class, Respuesta.class);
this.marshaller = jc.createMarshaller();
this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
this.marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.displayName());
this.marshaller.setSchema(schema);
this.unmarshaller = jc.createUnmarshaller();
this.unmarshaller.setSchema(schema);
}
```
I imagine that with the code my question becomes clearer. | 2017/06/06 | [
"https://Stackoverflow.com/questions/44392223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7708486/"
]
| **HTML**
```
<select name="study-phase" onchange="myFunction()" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
<style type="text/css">
#a,
#b,
#c,
#d,
#f,
#g,
#h,
#j,
#k,
#e,
#i {
display: none;
}
</style>
```
**JS:**
```
function myFunction(){
console.log("myFunction gets called");
if (document.getElementById("study-phase").value == "pri") {
document.getElementById("a").style.display = "block";
}}
```
Just declare your function like this.
And add a console.log to make sure that function is getting called "onchange" or not, which is after this change. | You need to define the function before calling it,
For example, in the first select (example 1) im calling a function that isn't defined yet and nothing happens (see console for error)
in the second select (example 2) i define it first then call it.
This makes for a messy html layout with random scripts in it, so instead, you can use jquery to listen for the event (example 3).
```
$('.myselect').change(function(){})
```
Examples: <https://jsfiddle.net/hbmrktbj/> |
44,392,223 | I am trying to perform two processes using bean, my problem is that I can not find the way these processes are performed continuously. The first process is to send an object and the second process is the response of the object.
```
@Component
public class Proceso implements InitializingBean{
private static final String XML_SCHEMA_LOCATION = "/proceso/model/schema/proceso.xsd";
private Envio envio;
private Respuesta respuesta;
public void Proceso_envio(Proceso proceso, OutputStream outputstream) throws JAXBException{
envio.marshal(proceso, outputstream);}
public void Proceso_respuesta(InputStream inputstream) throws JAXBException, FileNotFoundException{
Object obj = unmarshaller.unmarshal(inputStream);
return (Proceso_respuesta) obj;}
@Override
public void afterPropertiesSet() throws Exception{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(getClass().getResource(XML_SCHEMA_LOCATION));
JAXBContext jc = JAXBContext.newInstance(Envio.class, Respuesta.class);
this.marshaller = jc.createMarshaller();
this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
this.marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.displayName());
this.marshaller.setSchema(schema);
this.unmarshaller = jc.createUnmarshaller();
this.unmarshaller.setSchema(schema);
}
```
I imagine that with the code my question becomes clearer. | 2017/06/06 | [
"https://Stackoverflow.com/questions/44392223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7708486/"
]
| Try using the `.change()` event :
**HTML**
```
<select name="study-phase" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
```
**JS**
```
$(function(){
$('#study-phase').change(function(){
if ($("#study-phase").val() == "pri") {
$("#a").css('display','block');
}
});
});
``` | To done this jquery will be more efficient so you just need to do some thing like this:-
1.Remove onchange="myFunction()" form your select
2.Add this code on your script:-
```
$('#study-phase').on('change',function(){
if ($(this).val() == "pri") {
$("#a")css('display','block');
}});
```
It will work fine |
44,392,223 | I am trying to perform two processes using bean, my problem is that I can not find the way these processes are performed continuously. The first process is to send an object and the second process is the response of the object.
```
@Component
public class Proceso implements InitializingBean{
private static final String XML_SCHEMA_LOCATION = "/proceso/model/schema/proceso.xsd";
private Envio envio;
private Respuesta respuesta;
public void Proceso_envio(Proceso proceso, OutputStream outputstream) throws JAXBException{
envio.marshal(proceso, outputstream);}
public void Proceso_respuesta(InputStream inputstream) throws JAXBException, FileNotFoundException{
Object obj = unmarshaller.unmarshal(inputStream);
return (Proceso_respuesta) obj;}
@Override
public void afterPropertiesSet() throws Exception{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(getClass().getResource(XML_SCHEMA_LOCATION));
JAXBContext jc = JAXBContext.newInstance(Envio.class, Respuesta.class);
this.marshaller = jc.createMarshaller();
this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
this.marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.displayName());
this.marshaller.setSchema(schema);
this.unmarshaller = jc.createUnmarshaller();
this.unmarshaller.setSchema(schema);
}
```
I imagine that with the code my question becomes clearer. | 2017/06/06 | [
"https://Stackoverflow.com/questions/44392223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7708486/"
]
| Try using the `.change()` event :
**HTML**
```
<select name="study-phase" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
```
**JS**
```
$(function(){
$('#study-phase').change(function(){
if ($("#study-phase").val() == "pri") {
$("#a").css('display','block');
}
});
});
``` | I guess what you want is that when you select the value pri in the first select the second take the value aa. As you use jquery I'll give you an example.
```
$( document ).ready(function() {
$("#study-phase").change(function(){
if($(this).val() === "pri")
{
$("#study-year").val("aa");
}
});
})
```
<https://codepen.io/anon/pen/VWLaqv> |
44,392,223 | I am trying to perform two processes using bean, my problem is that I can not find the way these processes are performed continuously. The first process is to send an object and the second process is the response of the object.
```
@Component
public class Proceso implements InitializingBean{
private static final String XML_SCHEMA_LOCATION = "/proceso/model/schema/proceso.xsd";
private Envio envio;
private Respuesta respuesta;
public void Proceso_envio(Proceso proceso, OutputStream outputstream) throws JAXBException{
envio.marshal(proceso, outputstream);}
public void Proceso_respuesta(InputStream inputstream) throws JAXBException, FileNotFoundException{
Object obj = unmarshaller.unmarshal(inputStream);
return (Proceso_respuesta) obj;}
@Override
public void afterPropertiesSet() throws Exception{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(getClass().getResource(XML_SCHEMA_LOCATION));
JAXBContext jc = JAXBContext.newInstance(Envio.class, Respuesta.class);
this.marshaller = jc.createMarshaller();
this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
this.marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.displayName());
this.marshaller.setSchema(schema);
this.unmarshaller = jc.createUnmarshaller();
this.unmarshaller.setSchema(schema);
}
```
I imagine that with the code my question becomes clearer. | 2017/06/06 | [
"https://Stackoverflow.com/questions/44392223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7708486/"
]
| **HTML**
```
<select name="study-phase" onchange="myFunction()" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
<style type="text/css">
#a,
#b,
#c,
#d,
#f,
#g,
#h,
#j,
#k,
#e,
#i {
display: none;
}
</style>
```
**JS:**
```
function myFunction(){
console.log("myFunction gets called");
if (document.getElementById("study-phase").value == "pri") {
document.getElementById("a").style.display = "block";
}}
```
Just declare your function like this.
And add a console.log to make sure that function is getting called "onchange" or not, which is after this change. | Your JavaScript isn't valid.
Moreover, I think you want to one of the option in the second dropdown once you make change in the first.
You can build on this logic further
Here is a sample minimal code:
```js
function myFunction() {
if (document.getElementById("study-phase").value == "pri")
document.getElementById("study-year").value = "aa";
};
```
```html
<select name="study-phase" onchange="myFunction()" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
``` |
44,392,223 | I am trying to perform two processes using bean, my problem is that I can not find the way these processes are performed continuously. The first process is to send an object and the second process is the response of the object.
```
@Component
public class Proceso implements InitializingBean{
private static final String XML_SCHEMA_LOCATION = "/proceso/model/schema/proceso.xsd";
private Envio envio;
private Respuesta respuesta;
public void Proceso_envio(Proceso proceso, OutputStream outputstream) throws JAXBException{
envio.marshal(proceso, outputstream);}
public void Proceso_respuesta(InputStream inputstream) throws JAXBException, FileNotFoundException{
Object obj = unmarshaller.unmarshal(inputStream);
return (Proceso_respuesta) obj;}
@Override
public void afterPropertiesSet() throws Exception{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(getClass().getResource(XML_SCHEMA_LOCATION));
JAXBContext jc = JAXBContext.newInstance(Envio.class, Respuesta.class);
this.marshaller = jc.createMarshaller();
this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
this.marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.displayName());
this.marshaller.setSchema(schema);
this.unmarshaller = jc.createUnmarshaller();
this.unmarshaller.setSchema(schema);
}
```
I imagine that with the code my question becomes clearer. | 2017/06/06 | [
"https://Stackoverflow.com/questions/44392223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7708486/"
]
| ```
$(function(myFunction()){
if (document.getElementById("study-phase").value == "pri") {
document.getElementById("a").style.display = "block";
}});
```
give error
```
Uncaught SyntaxError: Unexpected token (
```
apart if you revised your code as below it works, as it is vanillaJs you dont need jquery
```js
function myFunction() {
if (document.getElementById("study-phase").value == "pri") {
document.getElementById("a").style.display = "block";
}
};
```
```html
<select name="study-phase" onchange="myFunction()" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
<style type="text/css">
#a,
#b,
#c,
#d,
#f,
#g,
#h,
#j,
#k,
#e,
#i {
display: none;
}
</style>
``` | To done this jquery will be more efficient so you just need to do some thing like this:-
1.Remove onchange="myFunction()" form your select
2.Add this code on your script:-
```
$('#study-phase').on('change',function(){
if ($(this).val() == "pri") {
$("#a")css('display','block');
}});
```
It will work fine |
44,392,223 | I am trying to perform two processes using bean, my problem is that I can not find the way these processes are performed continuously. The first process is to send an object and the second process is the response of the object.
```
@Component
public class Proceso implements InitializingBean{
private static final String XML_SCHEMA_LOCATION = "/proceso/model/schema/proceso.xsd";
private Envio envio;
private Respuesta respuesta;
public void Proceso_envio(Proceso proceso, OutputStream outputstream) throws JAXBException{
envio.marshal(proceso, outputstream);}
public void Proceso_respuesta(InputStream inputstream) throws JAXBException, FileNotFoundException{
Object obj = unmarshaller.unmarshal(inputStream);
return (Proceso_respuesta) obj;}
@Override
public void afterPropertiesSet() throws Exception{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(getClass().getResource(XML_SCHEMA_LOCATION));
JAXBContext jc = JAXBContext.newInstance(Envio.class, Respuesta.class);
this.marshaller = jc.createMarshaller();
this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
this.marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.displayName());
this.marshaller.setSchema(schema);
this.unmarshaller = jc.createUnmarshaller();
this.unmarshaller.setSchema(schema);
}
```
I imagine that with the code my question becomes clearer. | 2017/06/06 | [
"https://Stackoverflow.com/questions/44392223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7708486/"
]
| **HTML**
```
<select name="study-phase" onchange="myFunction()" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
<style type="text/css">
#a,
#b,
#c,
#d,
#f,
#g,
#h,
#j,
#k,
#e,
#i {
display: none;
}
</style>
```
**JS:**
```
function myFunction(){
console.log("myFunction gets called");
if (document.getElementById("study-phase").value == "pri") {
document.getElementById("a").style.display = "block";
}}
```
Just declare your function like this.
And add a console.log to make sure that function is getting called "onchange" or not, which is after this change. | To done this jquery will be more efficient so you just need to do some thing like this:-
1.Remove onchange="myFunction()" form your select
2.Add this code on your script:-
```
$('#study-phase').on('change',function(){
if ($(this).val() == "pri") {
$("#a")css('display','block');
}});
```
It will work fine |
44,392,223 | I am trying to perform two processes using bean, my problem is that I can not find the way these processes are performed continuously. The first process is to send an object and the second process is the response of the object.
```
@Component
public class Proceso implements InitializingBean{
private static final String XML_SCHEMA_LOCATION = "/proceso/model/schema/proceso.xsd";
private Envio envio;
private Respuesta respuesta;
public void Proceso_envio(Proceso proceso, OutputStream outputstream) throws JAXBException{
envio.marshal(proceso, outputstream);}
public void Proceso_respuesta(InputStream inputstream) throws JAXBException, FileNotFoundException{
Object obj = unmarshaller.unmarshal(inputStream);
return (Proceso_respuesta) obj;}
@Override
public void afterPropertiesSet() throws Exception{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(getClass().getResource(XML_SCHEMA_LOCATION));
JAXBContext jc = JAXBContext.newInstance(Envio.class, Respuesta.class);
this.marshaller = jc.createMarshaller();
this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
this.marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.displayName());
this.marshaller.setSchema(schema);
this.unmarshaller = jc.createUnmarshaller();
this.unmarshaller.setSchema(schema);
}
```
I imagine that with the code my question becomes clearer. | 2017/06/06 | [
"https://Stackoverflow.com/questions/44392223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7708486/"
]
| ```
$(function(myFunction()){
if (document.getElementById("study-phase").value == "pri") {
document.getElementById("a").style.display = "block";
}});
```
give error
```
Uncaught SyntaxError: Unexpected token (
```
apart if you revised your code as below it works, as it is vanillaJs you dont need jquery
```js
function myFunction() {
if (document.getElementById("study-phase").value == "pri") {
document.getElementById("a").style.display = "block";
}
};
```
```html
<select name="study-phase" onchange="myFunction()" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
<style type="text/css">
#a,
#b,
#c,
#d,
#f,
#g,
#h,
#j,
#k,
#e,
#i {
display: none;
}
</style>
``` | You need to define the function before calling it,
For example, in the first select (example 1) im calling a function that isn't defined yet and nothing happens (see console for error)
in the second select (example 2) i define it first then call it.
This makes for a messy html layout with random scripts in it, so instead, you can use jquery to listen for the event (example 3).
```
$('.myselect').change(function(){})
```
Examples: <https://jsfiddle.net/hbmrktbj/> |
44,392,223 | I am trying to perform two processes using bean, my problem is that I can not find the way these processes are performed continuously. The first process is to send an object and the second process is the response of the object.
```
@Component
public class Proceso implements InitializingBean{
private static final String XML_SCHEMA_LOCATION = "/proceso/model/schema/proceso.xsd";
private Envio envio;
private Respuesta respuesta;
public void Proceso_envio(Proceso proceso, OutputStream outputstream) throws JAXBException{
envio.marshal(proceso, outputstream);}
public void Proceso_respuesta(InputStream inputstream) throws JAXBException, FileNotFoundException{
Object obj = unmarshaller.unmarshal(inputStream);
return (Proceso_respuesta) obj;}
@Override
public void afterPropertiesSet() throws Exception{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(getClass().getResource(XML_SCHEMA_LOCATION));
JAXBContext jc = JAXBContext.newInstance(Envio.class, Respuesta.class);
this.marshaller = jc.createMarshaller();
this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
this.marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.displayName());
this.marshaller.setSchema(schema);
this.unmarshaller = jc.createUnmarshaller();
this.unmarshaller.setSchema(schema);
}
```
I imagine that with the code my question becomes clearer. | 2017/06/06 | [
"https://Stackoverflow.com/questions/44392223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7708486/"
]
| ```
$(function(myFunction()){
if (document.getElementById("study-phase").value == "pri") {
document.getElementById("a").style.display = "block";
}});
```
give error
```
Uncaught SyntaxError: Unexpected token (
```
apart if you revised your code as below it works, as it is vanillaJs you dont need jquery
```js
function myFunction() {
if (document.getElementById("study-phase").value == "pri") {
document.getElementById("a").style.display = "block";
}
};
```
```html
<select name="study-phase" onchange="myFunction()" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
<style type="text/css">
#a,
#b,
#c,
#d,
#f,
#g,
#h,
#j,
#k,
#e,
#i {
display: none;
}
</style>
``` | Your JavaScript isn't valid.
Moreover, I think you want to one of the option in the second dropdown once you make change in the first.
You can build on this logic further
Here is a sample minimal code:
```js
function myFunction() {
if (document.getElementById("study-phase").value == "pri")
document.getElementById("study-year").value = "aa";
};
```
```html
<select name="study-phase" onchange="myFunction()" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
``` |
44,392,223 | I am trying to perform two processes using bean, my problem is that I can not find the way these processes are performed continuously. The first process is to send an object and the second process is the response of the object.
```
@Component
public class Proceso implements InitializingBean{
private static final String XML_SCHEMA_LOCATION = "/proceso/model/schema/proceso.xsd";
private Envio envio;
private Respuesta respuesta;
public void Proceso_envio(Proceso proceso, OutputStream outputstream) throws JAXBException{
envio.marshal(proceso, outputstream);}
public void Proceso_respuesta(InputStream inputstream) throws JAXBException, FileNotFoundException{
Object obj = unmarshaller.unmarshal(inputStream);
return (Proceso_respuesta) obj;}
@Override
public void afterPropertiesSet() throws Exception{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(getClass().getResource(XML_SCHEMA_LOCATION));
JAXBContext jc = JAXBContext.newInstance(Envio.class, Respuesta.class);
this.marshaller = jc.createMarshaller();
this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
this.marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.displayName());
this.marshaller.setSchema(schema);
this.unmarshaller = jc.createUnmarshaller();
this.unmarshaller.setSchema(schema);
}
```
I imagine that with the code my question becomes clearer. | 2017/06/06 | [
"https://Stackoverflow.com/questions/44392223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7708486/"
]
| **HTML**
```
<select name="study-phase" onchange="myFunction()" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
<style type="text/css">
#a,
#b,
#c,
#d,
#f,
#g,
#h,
#j,
#k,
#e,
#i {
display: none;
}
</style>
```
**JS:**
```
function myFunction(){
console.log("myFunction gets called");
if (document.getElementById("study-phase").value == "pri") {
document.getElementById("a").style.display = "block";
}}
```
Just declare your function like this.
And add a console.log to make sure that function is getting called "onchange" or not, which is after this change. | You can do something like this instead:
```js
$(document).ready(function() {
$("#study-phase").on("change", function() {
if (document.getElementById("study-phase").value === "pri") {
$('option#a').show();
}
});
});
```
```css
#a,
#b,
#c,
#d,
#f,
#g,
#h,
#j,
#k,
#e,
#i {
display: none;
}
```
```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="study-phase" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
``` |
44,392,223 | I am trying to perform two processes using bean, my problem is that I can not find the way these processes are performed continuously. The first process is to send an object and the second process is the response of the object.
```
@Component
public class Proceso implements InitializingBean{
private static final String XML_SCHEMA_LOCATION = "/proceso/model/schema/proceso.xsd";
private Envio envio;
private Respuesta respuesta;
public void Proceso_envio(Proceso proceso, OutputStream outputstream) throws JAXBException{
envio.marshal(proceso, outputstream);}
public void Proceso_respuesta(InputStream inputstream) throws JAXBException, FileNotFoundException{
Object obj = unmarshaller.unmarshal(inputStream);
return (Proceso_respuesta) obj;}
@Override
public void afterPropertiesSet() throws Exception{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(getClass().getResource(XML_SCHEMA_LOCATION));
JAXBContext jc = JAXBContext.newInstance(Envio.class, Respuesta.class);
this.marshaller = jc.createMarshaller();
this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
this.marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.displayName());
this.marshaller.setSchema(schema);
this.unmarshaller = jc.createUnmarshaller();
this.unmarshaller.setSchema(schema);
}
```
I imagine that with the code my question becomes clearer. | 2017/06/06 | [
"https://Stackoverflow.com/questions/44392223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7708486/"
]
| Try using the `.change()` event :
**HTML**
```
<select name="study-phase" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
```
**JS**
```
$(function(){
$('#study-phase').change(function(){
if ($("#study-phase").val() == "pri") {
$("#a").css('display','block');
}
});
});
``` | You can do something like this instead:
```js
$(document).ready(function() {
$("#study-phase").on("change", function() {
if (document.getElementById("study-phase").value === "pri") {
$('option#a').show();
}
});
});
```
```css
#a,
#b,
#c,
#d,
#f,
#g,
#h,
#j,
#k,
#e,
#i {
display: none;
}
```
```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="study-phase" id="study-phase" class="sp-input">
<option value=""></option>
<option id="pri" value="pri">Primary</option>
<option id="pre" value="pre">Prep</option>
<option id="sec" value="sec">Secondary</option>
</select>
<select name="study-year" id="study-year" class="sp-input">
<option value=""></option>
<option id="a" value="aa">Grade 1</option>
<option id="b" value="">Grade 2</option>
<option id="c" value="">Grade 3</option>
<option id="d" value="">Grade 4</option>
<option id="e" value="">Grade 5</option>
<option id="f" value="">Grade 6</option>
<option id="g" value="">Grade 7</option>
<option id="h" value="">Grade 8</option>
<option id="i" value="">Grade 9</option>
<option id="j" value="">Grade 10</option>
</select>
``` |
54,531,287 | I would like to be able to push each **|** into an array
Here is my function:
```
def pyramide(lines):
k = 1 * lines - 1
for i in range(0, lines):
for j in range(0, k):
print(end=" ")
k = k - 1
for j in range(0, i+1):
print("|", end=" ")
print("\r")
lines = 5
pyramide(lines)
```
What I tried:
```
for j in range(0, i+1):
each = print("|", end=" ")
array.push(each)
print("\r")
```
But it doesn't seem to add it into an array, my question is how I can push each **|** into an array so I can delete it later
Edit:
expected input:
```
pyramide(5)
```
expected output:
```
|
| |
| | |
| | | |
```
Then I should be able to remove a **|** from each line by
```
stickDelete(3, 2) # first paramater is the line, second is how much | would like to delete
|
| |
| | | |
``` | 2019/02/05 | [
"https://Stackoverflow.com/questions/54531287",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11013215/"
]
| Split it in 2:
* a list of arrays holding the '|' 's (or other character)
* a function to print the 'pyramid' arrays
Wrapped in a class you get something like:
```
class CPyramide(object):
def __init__(self, lines):
self.pir = []
# construct the array of arrays for the pyramid
# each one holding the n-bars for a row
for i in range(lines):
# construct the array using a listcomprehension
bars = ['|' for j in range(i+1)]
self.pir.append(bars)
def __str__(self):
"""print the pyramid"""
o = ""
# loop through all the rows that represent the pyramid
# and use enumerate to have them numerical from 0 to len(pir)
for i, L in enumerate(self.pir):
# spaces decrease with increase of rows ...
spaces = (len(self.pir) - i) * ' '
# so, a line starts with the n-spaces
o += spaces
# appended with the bars of that row all in L
o += ' '.join(L)
# and a newline, which is definitely something else
# then '\r' (on unix \r will show only one line when
# using '\r'!)
o += "\n"
return o
def stickDelete(self, line, n):
self.pir[line] = self.pir[line][n:]
print("===============")
cpir = CPyramide(5)
print(cpir)
cpir.stickDelete(3, 2)
print(cpir)
```
Output:
```
===============
|
| |
| | |
| | | |
| | | | |
|
| |
| | |
| |
| | | | |
``` | ```html
def triangle(n):
k = 2*n - 2
for i in range(0, n):
for j in range(0, k):
print(end=" ")
k = k - 1
for j in range(0, i+1):
print("| ", end="")
print("\r")
n = 5
triangle(n)
this will return
D:\>st.py
|
| |
| | |
| | | |
| | | | |
``` |
31,119,709 | I am trying to develop server-side using loopback with database connector.
However, I am quite confused with installing loopback on AWS.
[reference for installing loopback on AWS](http://docs.strongloop.com/display/SL/Amazon+EC2)
This website mentioned that only loopback of version 2.0 could be installed.
Yet, when I browse through loopback website, <https://strongloop.com/strongblog/how-to-setup-push-notifications-private-mbaas-amazon-aws-part-1/>, this website shows that it seems possible to install loopback of version higher than 2.0 on AWS. Since there are some features only available after version 2.1x, it would be nice if AWS allows installation of loopback of version higher than 2.0. Could anyone help me solve the problem? BTW, I am only using free tier of AWS and do not intend to pay at this moment. | 2015/06/29 | [
"https://Stackoverflow.com/questions/31119709",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5009672/"
]
| Even if you install the image that comes preconfigured with Loopback 2, you should be able to upgrade to newer versions using npm as you normally would (`sudo npm install -g strongloop` and the like). Imagine if there's a security issue that you'd need that wasn't backported for whatever reason...Loopback is just files and the image is just linux. You have free reign to update/upgrade whatever you need.
My recommendation would be to start out with a minimal Ubuntu image and install everything with npm. You'll understand the ecosystem better and won't be surprised by something you don't remember installing specifically.
One caveat that a bunch of preconfigured images have is they are only available on older instance types (m1 for instance--*pun not intended ;)*). They are slower and more expensive than newer instances. | You can probably install whatever you want.
The difference is that if you want a machine image that contains everything already there and don't want to build it yourself you're stuck to 2.0 here (<https://aws.amazon.com/marketplace/pp/B00PG9I0M0>)
What I would do is use the provided AMI and after that upgrade loopback manually. |
6,478,496 | I have a google site search
<http://www.google.com/cse/manage/create>
Which gives me the following working code:
```
<div id="cse" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', { language: 'en' });
google.setOnLoadCallback(function () {
var customSearchControl = new google.search.CustomSearchControl('013080392637799242034:ichqh_hal4w');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.draw('cse');
}, true);
</script>
```
On some of my pages, I have a search box. Can I make the text entered in that search box, post to this site search script and load?
For example:
* User is on Home.html
* They enter text in a search box
* Redirects them to Search.html
* Search.html takes the text they entered and does a search with it, without them needing to retype it in the empty box
At the moment I have:
```
// Temporary measure
SearchBox.click(function (event) {
SearchBox.attr('disabled', 'disabled');
SearchBox.css("background", "#efefef");
window.location.replace(Domainroot + "/search");
});
```
Which is less than ideal, but works OK. When a user clicks the search box it redirects them to the search page to save them double entering the query.
Thanks for any help! | 2011/06/25 | [
"https://Stackoverflow.com/questions/6478496",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/356635/"
]
| Have a look at <http://code.google.com/apis/customsearch/docs/js/cselement-reference.html#_methods-el>
It looks like the control you create comes with methods. It seems you are looking for the .execute(query) method. | One way is to have the iFrame code right on you homepage and you can customize it. You will find various ways to do it. But if you want to a more personalized thing like have a search box and then have results in your page then I would suggest you do a backend process to querying Google and then post back the results. Check Nokogiri example for what I mean. |
399,768 | Here is the MWE:
```
\documentclass{article}
\usepackage[shortlabels]{enumitem}
\begin{document}
\begin{enumerate}[label={Q.\arabic*.}]
\item This is 1
\item This is 2
\item This is 3A
\item This is 3B
\item This is 4
\end{enumerate}
\end{document}
```
How do I get labels to match the items details? So, it should Q.1., Q.2., Q.3.A, Q.3.B, Q.4, etc. instead of Q.1., Q.2., ..., Q.5., etc.? | 2017/11/05 | [
"https://tex.stackexchange.com/questions/399768",
"https://tex.stackexchange.com",
"https://tex.stackexchange.com/users/18495/"
]
| If you don't mind doing the special cases semi-manually, you could do the following:
```
\documentclass{article}
\usepackage[shortlabels]{enumitem}
\newlength{\aw}
\settowidth{\aw}{A}
\begin{document}
\begin{enumerate}[label={Q.\arabic*.\hspace*{\aw}}]
\item This is 1
\item This is 2
\addtocounter{enumi}{1}
\item[Q.\arabic{enumi}A.] This is 3A
\item[Q.\arabic{enumi}B.] This is 3B
\item This is 4
\item This is 5
\end{enumerate}
\end{document}
```
[](https://i.stack.imgur.com/ZFh5t.png) | Here is a semi-automated way of constructing these lists. With the code below, you can use the commands
```
\begin{MyList}
\item This is 1
\item This is 2
\item* This is 3A
\item* This is 3B\label{3B}
\item This is 4
\end{MyList}
```
to produce the list:
[](https://i.stack.imgur.com/WqzqN.png)
So, whenever `\item*` is used then a letter is added to the item number, with the item number increasing only if the last item was unstarred. You can still use `\item[label]` to override items labels if you wish with the caveat that the optional label will be ignored with `\item*[optional label]`.
Here is the full code, some explanations below:
```
\documentclass{article}
\usepackage[shortlabels]{enumitem}
\usepackage{xparse}
\let\realItem\item% save \item for use in \repeatingItem
\newif\ifRepeatingItem
\newcounter{repeatLabel}
\renewcommand\therepeatLabel{Q.\arabic{MyListi}\Alph{repeatLabel}.}
\NewDocumentCommand\repeatingItem{ so }{%
\IfBooleanTF{#1}{%
\ifRepeatingItem% need to stop enumi from incrementing
\else\stepcounter{MyListi}\setcounter{repeatLabel}{0}% reset repeat label counter
\fi%
\refstepcounter{repeatLabel}% increment counter
\realItem[\therepeatLabel]% print the label
\RepeatingItemtrue%
}{\IfValueTF{#2}{\realItem[#2]}{\realItem}%
\RepeatingItemfalse%
}%
}
\newlist{MyList}{enumerate}{1}% assuming no nesting
\setlist[MyList]{
label=Q.\arabic*.,
before=\let\item\repeatingItem,
widest=Q.8A.
}
\begin{document}
\begin{MyList}
\item This is 1
\item This is 2
\item* This is 3A
\item* This is 3B\label{3B}
\item This is 4
\end{MyList}
\end{document}
```
I have used `\newlist` to define a new `enumerate` like list, which I assume will not be nested -- it would be possible to allow nesting, but this is a little more complicated. Inside a `MyList` environment the `\item` command is really `\repeatingItem`, which uses some [xparse](https://www.ctan.org/pkg/xparse) magic to determine when a `*` is used.
Because the behaviour of `\item*` is different depending on whether the previous item was starred, I have defined a boolean `\ifRepeatingItem` to keep track of whether or not the last item was starred. Apart from this we just increment the various counters needed for the output. |
31,243,845 | I just created a basic html page layout and im currently trying to get it work on wordpress, created the header.php, index.php, footer.php, called them with php, well i followed this guide: <https://thethemefoundry.com/blog/html-wordpress/>
Did all thats on there, after i uploaded the theme and actived it i get this:

No divs, no images, just the text
I will include my code bellow of the original html/ css and the php files:
```css
/*
Theme Name: SSK theme
Theme URI:
Description: Tema para o site da ssk
Version: 1.0
Author: DA
Author URI: www
*/
body, div, h1, h2, h3, h4, h5, h6, p, ul, ol, li, dl, dt, dd, img, form, fieldset, input, blockquote {
margin: 0; padding: 0; border: 0;
}
body {
font-family: Helvetica, Arial, Sans-Serif;
line-height: 24px;
background: #eee url(images/body-bg.jpg) center top no-repeat;
width:100%;
height: 100%;
}
#container {
width: 80%;
margin: 0 auto;
height:1100px;
margin-top: -75px;
}
#container p {
margin-bottom: -50px;
color: #0066FF;
font-size: 25px;
}
#languages {
background-color: red;
height:22px;
width: 200px;
position: absolute;
top:60px; right: 125px;
}
#destaques {
margin-top: 75px;
width:100%;
background-color: grey;
}
#main_page_holder {
border-top: 2px solid blue;
position: relative;
margin-top: 110px;
width: 100%;
height: 30%;
}
#home_navigation_link {
margin-left: 1.7%;
margin-right: 1%;
margin-top: 2%;
width: 30%;
height: 35%;
display: inline-block;
background-color: #f2f2f2;
}
#Projetos {
margin-top: 110px;
width: 100%;
height: 20%;
background-color: orange;
}
#projsquare {
border-top: 2px solid blue;
margin-top: -0px;
height: 30%;
}
.squa {
width: 125px;
float:left;
height:125px;
background:magenta;
margin:10px;
margin-top: 90px;
}
#logo2 {
float: right;
width: 30%;
height: 100%;
background-color: red;
}
#logo2 img {
background-repeat: no-repeat;
width: 100%;
height: 30%;
}
.ima {
background-image: url("img/logo.png");
background-repeat: no-repeat;
width:35%;
height:100%;
background-color: blue;
float: left;
-moz-border-radius: 60%;
-webkit-border-radius: 60%;
border-radius: 60%;
border-color:white;
}
.ima img {
width:100%;
height:100%;
-moz-border-radius: 60%;
-webkit-border-radius: 60%;
border-radius: 60%;
border-color:white;
}
.tit {
color: #0066FF;;
float:left;
width:65%;
height:15%;
}
.tito {
width:65%;
height:15%;
background-color: black;
}
#categories {
list-style: none;
position: absolute;
top: 125px;
right: 125px;
font-size: 0;
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#1b75b1+0,529282+47,71ac4a+100 */
background: rgb(27, 117, 177);
/* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;
base64, PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzFiNzViMSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjQ3JSIgc3RvcC1jb2xvcj0iIzUyOTI4MiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM3MWFjNGEiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(left, rgb(27, 117, 177) 0%, rgb(82, 146, 130) 47%, rgb(113, 172, 74) 100%);
/* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgb(27, 117, 177)), color-stop(47%, rgb(82, 146, 130)), color-stop(100%, rgb(113, 172, 74)));
/* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgb(27, 117, 177) 0%, rgb(82, 146, 130) 47%, rgb(113, 172, 74) 100%);
/* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgb(27, 117, 177) 0%, rgb(82, 146, 130) 47%, rgb(113, 172, 74) 100%);
/* Opera 11.10+ */
background: -ms-linear-gradient(left, rgb(27, 117, 177) 0%, rgb(82, 146, 130) 47%, rgb(113, 172, 74) 100%);
/* IE10+ */
background: linear-gradient(to right, rgb(27, 117, 177) 0%, rgb(82, 146, 130) 47%, rgb(113, 172, 74) 100%);
/* W3C */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#1b75b1', endColorstr='#71ac4a', GradientType=1);
/* IE6-8 */
}
#categories li {
display: inline-block;
vertical-align: top;
position: relative;
}
#categories li a {
font-size: 15px;
color: white;
text-decoration: none;
padding: 6px 22px;
display: block;
}
#categories li:before{
content: '';
width: 1px;
height: 15px;
background: #fff;
position: absolute; top: 0; left: 0;
}
#categories li:first-child:before{
background: none;
}
#header {
overflow: hidden;
padding: 0 0 50px 0;
}
#mllcont {
height:40vh;
background-image: url("img/header.png");
background-repeat: no-repeat;
}
#slidecont {
background-image: url("img/back.jpg");
height:100vh;
background-color: red;
background-size: cover;
background-repeat: no-repeat;
}
#slidecont img {
width: 100%;
position: absolute;
left: 0;
bottom: 0;
}
#squares {
width:100%;
height:250px;
position: relative;
}
#divs p {
position: absolute;
bottom: -100px;
color: #0066FF;
font-size: 25px;
}
#divs div {
height: 300px;
width: 20%;
border: 0px solid red;
margin-left: 2.5%;
margin-right: 2.5%;
float: left; /*Here you can also use display: inline-block instead of float:left*/
background: white;
opacity: 0.7;
}
.circle{
border:1px solid red;
height:20px;
width:20px;
-webkit-border-radius: 40px;
-moz-border-radius: 40px;
border-radius: 40px;
position: relative;
}
#header h1 {
float: left;
}
#content, #footer, #header {
height: 100%;
}
```
```html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Particle</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<!--1 parte-->
<div id="slidecont">
<img src="img/banner.png"/>
<div id="mllcont">
<div id="logo">
</div>
<div id="languages">
</div>
<ul id="categories">
<li><a href="#">Menu1</a></li>
<li><a href="#">Menu2</a></li>
<li><a href="#">Menu3</a></li>
<li><a href="#">Menu4</a></li>
</ul>
</div>
</div>
<!--1 parte-->
<!--2 parte-->
<div id="container">
<div id="squares">
<div id="divs">
<div> <div class="tito"> </div> </div>
<div> <div class="tito"> </div> </div>
<div> <div class="tito"> </div> </div>
<div> <div class="tito"> </div> </div>
<p> Destaques </p>
</div>
</div>
<div id="main_page_holder">
<div id ="destaquetex">
</div>
<div id="home_navigation_link">
<div class="ima"> </div>
<div class="tit"> Nova liderança SKK </div>
</div>
<div id="home_navigation_link">
<div class="ima"> <img src="img/2.jpg"> </div>
<div class="tit"> Descontaminação </div>
</div>
<div id="home_navigation_link">
<div class="ima"> <img src="img/3.jpg"> </div>
<div class="tit"> ISOAIR </div>
</div>
<div id="home_navigation_link">
<div class="ima"> <img src="img/4.jpg"> </div>
<div class="tit"> SmartPower </div>
</div>
<div id="home_navigation_link">
<div class="ima"> <img src="img/4.jpg"> </div>
<div class="tit"> Móveis de congelação </div>
</div>
<div id="home_navigation_link">
<div class="ima"> <img src="img/6.jpg"> </div>
<div class="tit"> Universal R </div>
</div>
</div>
<p> Projetos</p>
<div id="projsquare">
<div class="squa"> </div>
<div class="squa"> </div>
<div class="squa"> </div>
<div class="squa"> </div>
<div id="logo2"> <img src="img/logo.png"> </div>
</div>
</div>
<!--2 parte-->
<!--3 parte-->
<div id="footer">
</div>
<!--3 parte-->
</body>
</html>
```
The files from the theme:
**INDEX.PHP**
```
<?php get_header(); ?>
<div id="container">
<div id="squares">
<div id="divs">
<div> <div class="tito"> </div> </div>
<div> <div class="tito"> </div> </div>
<div> <div class="tito"> </div> </div>
<div> <div class="tito"> </div> </div>
<p> Destaques </p>
</div>
</div>
<div id="main_page_holder">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-header">
<div class="date"><?php the_time( 'M j y' ); ?></div>
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<div class="author"><?php the_author(); ?></div>
</div><!--end post header-->
<div class="entry clear">
<?php if ( function_exists( 'add_theme_support' ) ) the_post_thumbnail(); ?>
<?php the_content(); ?>
<?php edit_post_link(); ?>
<?php wp_link_pages(); ?>
</div><!--end entry-->
<div class="post-footer">
<div class="comments"><?php comments_popup_link( 'Leave a Comment', '1 Comment', '% Comments' ); ?></div>
</div><!--end post footer-->
</div><!--end post-->
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
<div class="navigation index">
<div class="alignleft"><?php next_posts_link( 'Older Entries' ); ?></div>
<div class="alignright"><?php previous_posts_link( 'Newer Entries' ); ?></div>
</div><!--end navigation-->
<?php else : ?>
<?php endif; ?>
<div id ="destaquetex">
</div>
<div id="home_navigation_link">
<div class="ima"> </div>
<div class="tit"> Nova liderança SKK </div>
</div>
<div id="home_navigation_link">
<div class="ima"> <img src="img/2.jpg"> </div>
<div class="tit"> Descontaminação </div>
</div>
<div id="home_navigation_link">
<div class="ima"> <img src="img/3.jpg"> </div>
<div class="tit"> ISOAIR </div>
</div>
<div id="home_navigation_link">
<div class="ima"> <img src="img/4.jpg"> </div>
<div class="tit"> SmartPower </div>
</div>
<div id="home_navigation_link">
<div class="ima"> <img src="img/4.jpg"> </div>
<div class="tit"> Móveis de congelação </div>
</div>
<div id="home_navigation_link">
<div class="ima"> <img src="img/6.jpg"> </div>
<div class="tit"> Universal R </div>
</div>
</div>
<p> Projetos</p>
<div id="projsquare">
<div class="squa"> </div>
<div class="squa"> </div>
<div class="squa"> </div>
<div class="squa"> </div>
<div id="logo2"> <img src="img/logo.png"> </div>
</div>
</div>
<?php get_footer(); ?>
```
**Header.php**
```
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width">
<title><?php wp_title( '|', true, 'right' ); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js"></script>
<![endif]-->
<?php wp_head(); ?>
<div id="slidecont">
<img src="img/banner.png"/>
<div id="mllcont">
<div id="logo">
</div>
<div id="languages">
</div>
<ul id="categories">
<li><a href="#">Menu1</a></li>
<li><a href="#">Menu2</a></li>
<li><a href="#">Menu3</a></li>
<li><a href="#">Menu4</a></li>
</ul>
</div>
</div>
```
**footer.php**
```
<div id="footer">
</div>
``` | 2015/07/06 | [
"https://Stackoverflow.com/questions/31243845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3864939/"
]
| Whenever you use links, such as
```
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
```
Wordpress needs to know the *path to your css file*. Your normal built is somehow like this:
```
index.php
/wp-content/
/wp-content/themes/
/wp-content/themes/theme_name/
/wp-content/themes/theme_name/index.php
/wp-content/themes/theme_name/style.css
/wp-content/themes/theme_name/images/
/wp-content/themes/theme_name/images/image.jpg
```
So the `file path` needs to be relative to your `theme folder`. You can use a php snippet, to get the url of your theme:
```
<?php bloginfo('template_url'); ?>
```
If you want to include that, you can change your urls. For example
```
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<img src="images/image.jpg">
```
turns into:
```
<link href="<?php bloginfo('template_url'); ?>/style.css" rel="stylesheet" type="text/css" media="screen" />
<img src="<?php bloginfo('template_url'); ?>/images/image.jpg">
```
Do this to all file paths using `src` or `href` inside your `index.php`, `header.php`, `footer.php`, and other `php files`. | Easiest way to link eg css/js files to your site is via functions-file.
Create file functions.php to your folder /wp-content/themes/theme\_name/ with this content:
```
function scripts_here() {
wp_enqueue_style( 'stylename', get_template_directory_uri() . '/path_to_your_css.css' );
}
add_action( 'wp_enqueue_scripts', 'scripts_here' );
```
If you need to more css files, just use wp\_enqueue\_style-function..Take a look: <https://codex.wordpress.org/Function_Reference/wp_enqueue_style> |
3,540,533 | I have a theme in which there are numerous options, like:-
* Setting Theme Type among many available
* Setting Body Background Color & Image
* Setting Header & Footer Images
* Setting General Font Face, Size & Color
* Setting Text Area Background Color, and Font Face & Font Color
* Setting Form Area Background Color & Rounder Corners option
* Setting Form Element Background Color, and Font Face & Font Color
* Setting Link Default Color, Hover Color & Visited Color, with / without decoration
* Providing options to upload any number of Images to be used in the user's blog
* and many more...
Can anybody please provide any info as to how this can be done in a best possible way, using custom PHP & jQuery?
I'm also open to other ways around.
**EDIT:-**
I have got some 12 themes all worked out, along with their own style sheets defined & icon packs. I have also got them to load upon each of the customer's personal taste. **What I don't know is that how to manage the changes made to the customer's theme choice by that customer from his own account?** This has to take effect both the times :-
* when the customer is making / loading the changes from his account
* when the customer is viewing his account along with the changes
BTW, many many thanks for such a quick response, by two users & letting me know about my incomplete question.
Any help is greatly appreciated. | 2010/08/22 | [
"https://Stackoverflow.com/questions/3540533",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/332019/"
]
| Try something like this:
```
<?php
function template($file, $data = array())
{
ob_start();
extract($data);
include_once 'path/to/theme/folder/' . $file . '.php';
return ob_get_clean();
}
// Assign values to the template file
$values['theme_type'] = 'default';
$values['bg_color'] = '#FFFFFF';
$values['bg_image'] = 'path/to/bg/image.jpg';
$values['font_face'] = 'Tahoma, Arial, Verdana';
$values['font_size'] = '12px';
$values['font_color'] = '#000000';
// And so on...
// Output template file
echo template('theme_layout', $values);
?>
```
And the `theme_layout.php` file in `'path/to/theme/folder/theme_layout.php'` should look like this:
```
<html>
<head>
<title>Theme Name</title>
<style type="text/css">
body {
background-color: <?php echo $bg_color; ?>;
background-image: url(<?php echo $bg_image; ?>);
font-family: <?php echo $font_face; ?>;
font-size: <?php echo $font_size; ?>;
font-color: <?php echo $font_color; ?>;
}
</style>
</head>
<body>
Theme type is: <?php echo $theme_type; ?>
</body>
</html>
```
**Update**
You are right that was only the concept, here's what you have to do: Add new table in database `user_themes` for example and save all user related values there. For example user enters the admin page and sees a theme options like BG Color/Image, Font Name/Size/Color and enters his own values there... Form is submitted and values are saved in the database. Then during the theme display (where I assigned values to the template files) you get user entered theme options from database and assign as a theme values.
I really don't understand where jQuery should be used here, maybe in the form where user submits his options.
Hope this is helpful. | Create various stylesheets (`.css`). Each stylesheet represents a theme. Change the `<link>` element's `href` attribute to match the path to the selected theme.
If you're allowing user-uploaded CSS files, make sure to sanitize the input, as IE has the ability to execute parts of a CSS file as if it were JavaScript, leading to possible XSS attacks. |
28,275 | Ich suche ein Wort, welches jemanden beschreibt, der äußerst glaubwürdig ist. Also jemanden, bei dem **quasi niemand auf die Idee kommen würde, sie/ihn der Lüge zu bezichtigen,** bzw. jemanden, dem man vertraut.
Außer unantastbar, vertrauenswürdig und glaubwürdig fällt mir nichts ein.
Das gesuchte Wort sollte das fett Geschriebene betonen. | 2016/02/19 | [
"https://german.stackexchange.com/questions/28275",
"https://german.stackexchange.com",
"https://german.stackexchange.com/users/16926/"
]
| Ich würde eine solche Person **[integer](http://www.duden.de/rechtschreibung/integer)** nennen.
Allerdings setzt dies voraus, dass sie hohe moralische Ansprüche an sich selbst hat - formal kann auch ein aus Überzeugung **böse** handelnder Mensch als integer bezeichnet werden, wenn er damit seinem eigenen Wertesystem folgt. (Siehe Wikipedia zu [Integrität (Ethik)](https://de.wikipedia.org/wiki/Integrit%C3%A4t_(Ethik)))
Im allgemeinen Sprachgebrauch bedeutet *integer* allerdings *rechtschaffen **gut***. | Als Alternative fällt mir da noch das übertragene *Institution* ein. So wie in:
>
> Dieser Mann/diese Frau ist eine Institution.
>
>
> |
28,275 | Ich suche ein Wort, welches jemanden beschreibt, der äußerst glaubwürdig ist. Also jemanden, bei dem **quasi niemand auf die Idee kommen würde, sie/ihn der Lüge zu bezichtigen,** bzw. jemanden, dem man vertraut.
Außer unantastbar, vertrauenswürdig und glaubwürdig fällt mir nichts ein.
Das gesuchte Wort sollte das fett Geschriebene betonen. | 2016/02/19 | [
"https://german.stackexchange.com/questions/28275",
"https://german.stackexchange.com",
"https://german.stackexchange.com/users/16926/"
]
| Ich würde eine solche Person **[integer](http://www.duden.de/rechtschreibung/integer)** nennen.
Allerdings setzt dies voraus, dass sie hohe moralische Ansprüche an sich selbst hat - formal kann auch ein aus Überzeugung **böse** handelnder Mensch als integer bezeichnet werden, wenn er damit seinem eigenen Wertesystem folgt. (Siehe Wikipedia zu [Integrität (Ethik)](https://de.wikipedia.org/wiki/Integrit%C3%A4t_(Ethik)))
Im allgemeinen Sprachgebrauch bedeutet *integer* allerdings *rechtschaffen **gut***. | wie wäre es mit **über jeden Zweifel erhaben**? |
28,275 | Ich suche ein Wort, welches jemanden beschreibt, der äußerst glaubwürdig ist. Also jemanden, bei dem **quasi niemand auf die Idee kommen würde, sie/ihn der Lüge zu bezichtigen,** bzw. jemanden, dem man vertraut.
Außer unantastbar, vertrauenswürdig und glaubwürdig fällt mir nichts ein.
Das gesuchte Wort sollte das fett Geschriebene betonen. | 2016/02/19 | [
"https://german.stackexchange.com/questions/28275",
"https://german.stackexchange.com",
"https://german.stackexchange.com/users/16926/"
]
| Ich würde eine solche Person **[integer](http://www.duden.de/rechtschreibung/integer)** nennen.
Allerdings setzt dies voraus, dass sie hohe moralische Ansprüche an sich selbst hat - formal kann auch ein aus Überzeugung **böse** handelnder Mensch als integer bezeichnet werden, wenn er damit seinem eigenen Wertesystem folgt. (Siehe Wikipedia zu [Integrität (Ethik)](https://de.wikipedia.org/wiki/Integrit%C3%A4t_(Ethik)))
Im allgemeinen Sprachgebrauch bedeutet *integer* allerdings *rechtschaffen **gut***. | Als Alternative würde ich noch ***[grundehrlich](http://www.duden.de/rechtschreibung/grundehrlich)*** ins Rennen werfen. Der Nachteil ist, dass es ausschließlich etwas darüber aussagt, welchen Wahrheitsgehalt die Äußerungen der Person haben, als darüber, wie die Person von anderen wahrgenommen wird. |
28,275 | Ich suche ein Wort, welches jemanden beschreibt, der äußerst glaubwürdig ist. Also jemanden, bei dem **quasi niemand auf die Idee kommen würde, sie/ihn der Lüge zu bezichtigen,** bzw. jemanden, dem man vertraut.
Außer unantastbar, vertrauenswürdig und glaubwürdig fällt mir nichts ein.
Das gesuchte Wort sollte das fett Geschriebene betonen. | 2016/02/19 | [
"https://german.stackexchange.com/questions/28275",
"https://german.stackexchange.com",
"https://german.stackexchange.com/users/16926/"
]
| wie wäre es mit **über jeden Zweifel erhaben**? | Als Alternative fällt mir da noch das übertragene *Institution* ein. So wie in:
>
> Dieser Mann/diese Frau ist eine Institution.
>
>
> |
28,275 | Ich suche ein Wort, welches jemanden beschreibt, der äußerst glaubwürdig ist. Also jemanden, bei dem **quasi niemand auf die Idee kommen würde, sie/ihn der Lüge zu bezichtigen,** bzw. jemanden, dem man vertraut.
Außer unantastbar, vertrauenswürdig und glaubwürdig fällt mir nichts ein.
Das gesuchte Wort sollte das fett Geschriebene betonen. | 2016/02/19 | [
"https://german.stackexchange.com/questions/28275",
"https://german.stackexchange.com",
"https://german.stackexchange.com/users/16926/"
]
| Als Alternative würde ich noch ***[grundehrlich](http://www.duden.de/rechtschreibung/grundehrlich)*** ins Rennen werfen. Der Nachteil ist, dass es ausschließlich etwas darüber aussagt, welchen Wahrheitsgehalt die Äußerungen der Person haben, als darüber, wie die Person von anderen wahrgenommen wird. | Als Alternative fällt mir da noch das übertragene *Institution* ein. So wie in:
>
> Dieser Mann/diese Frau ist eine Institution.
>
>
> |
28,275 | Ich suche ein Wort, welches jemanden beschreibt, der äußerst glaubwürdig ist. Also jemanden, bei dem **quasi niemand auf die Idee kommen würde, sie/ihn der Lüge zu bezichtigen,** bzw. jemanden, dem man vertraut.
Außer unantastbar, vertrauenswürdig und glaubwürdig fällt mir nichts ein.
Das gesuchte Wort sollte das fett Geschriebene betonen. | 2016/02/19 | [
"https://german.stackexchange.com/questions/28275",
"https://german.stackexchange.com",
"https://german.stackexchange.com/users/16926/"
]
| wie wäre es mit **über jeden Zweifel erhaben**? | Als Alternative würde ich noch ***[grundehrlich](http://www.duden.de/rechtschreibung/grundehrlich)*** ins Rennen werfen. Der Nachteil ist, dass es ausschließlich etwas darüber aussagt, welchen Wahrheitsgehalt die Äußerungen der Person haben, als darüber, wie die Person von anderen wahrgenommen wird. |
6,059,257 | I'm using IceFaces 1.8.2 with Tomcat 6
On a irregular basis I get the message "Connection is lost" with the option to reload the page. This is not acceptable for a public site.
My question now is if this approach makes sense:
```
Ice.onConnectionLost('document:body',
function() {
window.location.href=window.location.href;
});
```
The idea is to reload the current page on connectin problems. Do oyu think this would solve the issue or could this create other problems (I assume that reloading the current url is OK and does not cause any workflow issues).
Thanks. | 2011/05/19 | [
"https://Stackoverflow.com/questions/6059257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/266478/"
]
| I suggest using the `java.text.DateFormat` as shown in [this page](http://www.rgagnon.com/javadetails/java-0099.html) :
```
public static boolean isValidDateStr(String date) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
sdf.setLenient(false);
sdf.parse(date);
}
catch (ParseException e) {
return false;
}
catch (IllegalArgumentException e) {
return false;
}
return true;
}
``` | I thing using regex for this is almost impossible, due to the complex calculation required for leap years. Jon Skeet is right: use `new SimpleDateFormat("yyyyMMdd")` for this. |
6,059,257 | I'm using IceFaces 1.8.2 with Tomcat 6
On a irregular basis I get the message "Connection is lost" with the option to reload the page. This is not acceptable for a public site.
My question now is if this approach makes sense:
```
Ice.onConnectionLost('document:body',
function() {
window.location.href=window.location.href;
});
```
The idea is to reload the current page on connectin problems. Do oyu think this would solve the issue or could this create other problems (I assume that reloading the current url is OK and does not cause any workflow issues).
Thanks. | 2011/05/19 | [
"https://Stackoverflow.com/questions/6059257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/266478/"
]
| I suggest using the `java.text.DateFormat` as shown in [this page](http://www.rgagnon.com/javadetails/java-0099.html) :
```
public static boolean isValidDateStr(String date) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
sdf.setLenient(false);
sdf.parse(date);
}
catch (ParseException e) {
return false;
}
catch (IllegalArgumentException e) {
return false;
}
return true;
}
``` | the regex for a leap year is very complex: case in point: (this also incorporates full date checking)
```
"(((\\d\\d)(0[48]|[2468][048]|[13579][26])|([02468][048]|[13579][26])(00))(02)([012]\\d))|(\\d\\d([02468][1235679]|[13579][01345789])(02)([01]\\d|2[012345678]))|(\\d\\d\\d\\d((0[13578]|1[02])([012]\\d|3[01])|((0[46]|11)([012]\\d|30))))"
```
first section separates out the the general case with non ending on 00
the second section handles the century year so only years divisable by 400 are leap years (1900 is not a leap year)
then in the last section it handles all the other months
(I didn't really test this but it should work close enough) |
6,059,257 | I'm using IceFaces 1.8.2 with Tomcat 6
On a irregular basis I get the message "Connection is lost" with the option to reload the page. This is not acceptable for a public site.
My question now is if this approach makes sense:
```
Ice.onConnectionLost('document:body',
function() {
window.location.href=window.location.href;
});
```
The idea is to reload the current page on connectin problems. Do oyu think this would solve the issue or could this create other problems (I assume that reloading the current url is OK and does not cause any workflow issues).
Thanks. | 2011/05/19 | [
"https://Stackoverflow.com/questions/6059257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/266478/"
]
| I thing using regex for this is almost impossible, due to the complex calculation required for leap years. Jon Skeet is right: use `new SimpleDateFormat("yyyyMMdd")` for this. | the regex for a leap year is very complex: case in point: (this also incorporates full date checking)
```
"(((\\d\\d)(0[48]|[2468][048]|[13579][26])|([02468][048]|[13579][26])(00))(02)([012]\\d))|(\\d\\d([02468][1235679]|[13579][01345789])(02)([01]\\d|2[012345678]))|(\\d\\d\\d\\d((0[13578]|1[02])([012]\\d|3[01])|((0[46]|11)([012]\\d|30))))"
```
first section separates out the the general case with non ending on 00
the second section handles the century year so only years divisable by 400 are leap years (1900 is not a leap year)
then in the last section it handles all the other months
(I didn't really test this but it should work close enough) |
50,549,041 | Just for fun, I am trying to create a magazine style, two-column layout with CSS like in the image below:
[](https://i.stack.imgur.com/YENLa.png)
I plan to do it by as many means as possible. Probably first with just some `div's` and `float's`. Then with the CSS table, then with a flexbox and finally with a CSS grid.
I don't even know if it is going to be possible with all, or any, but I am just trying.
So, here's what I've got till now.
[](https://i.stack.imgur.com/KylPE.png)
I can't seem to get the picture quite in the center with the text all around it.
I am not necessarily looking for an answer with just floats, or just the CSS grid. I am really interested in looking for anything that does it because I think this is a nice challenging thing to try out. :-)
Here is [the code on github](https://github.com/Sathyaish/Practice/blob/master/CSS/my-exercises/magazine-1.html) and below is the code snippet.
```css
:root {
margin-left: 8%;
margin-right: 8%;
}
#left, #right {
width: 40%;
}
#left {
margin-right: 4%;
float: left;
}
#right {
float: right;
}
p > span:first-of-type {
color: red;
margin-right: 2px;
}
#centerImage {
float: left;
src: url(https://raw.githubusercontent.com/Sathyaish/Practice/master/CSS/images/image.png);
}
```
```html
<h2>An do on frankness so cordially immediate recommend contained</h2>
<div id = "left">
<p><span>Para 1</span>He difficult contented we determine ourselves me am earnestly. Hour no find it park. Eat welcomed any husbands moderate.
Led was misery played waited almost cousin living. Of intention contained is by middleton am. Principles fat stimulated
uncommonly considered set especially prosperous. Sons at park mr meet as fact like.</p>
<p><span>Para 2</span>No comfort do written conduct at prevent manners on. Celebrated contrasted discretion him sympathize her collecting occasional.
Do answered bachelor occasion in of offended no concerns. Supply worthy warmth branch of no ye. Voice tried known
to as my to. Though wished merits or be. Alone visit use these smart rooms ham. No waiting in on enjoyed placing
it inquiry.</p>
<p><span>Para 3</span>Sentiments two occasional affronting solicitude travelling and one contrasted. Fortune day out married parties. Happiness
remainder joy but earnestly for off. Took sold add play may none him few. If as increasing contrasted entreaties
be. Now summer who day looked our behind moment coming. Pain son rose more park way that. An stairs as be lovers
uneasy.</p>
<p><span>Para 4</span>In post mean shot ye. There out her child sir his lived. Design at uneasy me season of branch on praise esteem. Abilities
discourse believing consisted remaining to no. Mistaken no me denoting dashwood as screened. Whence or esteem easily
he on. Dissuade husbands at of no if disposal.</p>
</div>
<img id = "centerImage" src = "../images/image.png" />
<div id="right">
<p><span>Para 5</span>Prevailed sincerity behaviour to so do principle mr. As departure at no propriety zealously my. On dear rent if girl
view. First on smart there he sense. Earnestly enjoyment her you resources. Brother chamber ten old against. Mr be
cottage so related minuter is. Delicate say and blessing ladyship exertion few margaret. Delight herself welcome
against smiling its for. Suspected discovery by he affection household of principle perfectly he.</p>
<p><span>Para 6</span>On no twenty spring of in esteem spirit likely estate. Continue new you declared differed learning bringing honoured.
At mean mind so upon they rent am walk. Shortly am waiting inhabit smiling he chiefly of in. Lain tore time gone
him his dear sure. Fat decisively estimating affronting assistance not. Resolve pursuit regular so calling me. West
he plan girl been my then up no.</p>
<p><span>Para 7</span>Sudden looked elinor off gay estate nor silent. Son read such next see the rest two. Was use extent old entire sussex.
Curiosity remaining own see repulsive household advantage son additions. Supposing exquisite daughters eagerness
why repulsive for. Praise turned it lovers be warmly by. Little do it eldest former be if.</p>
<p><span>Para 8</span>Expenses as material breeding insisted building to in. Continual so distrusts pronounce by unwilling listening. Thing
do taste on we manor. Him had wound use found hoped. Of distrusts immediate enjoyment curiosity do. Marianne numerous
saw thoughts the humoured.</p>
</div>
``` | 2018/05/27 | [
"https://Stackoverflow.com/questions/50549041",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/303685/"
]
| Instead of performing the entire multiplication, you only need to keep track of the factors of 2 and 5. If a number can be written as `N = 2^a * 5^b * (factors other than 2 or 5)`, then the number of trailing zeros in `N` is `min(a, b)`. (This is because a trailing zero is just a factor of 10, which requires one 2 and one 5.)
Note that multiplication adds together the exponents of the factors. So, if you can write:
```
s(n-2) = 2^a * 5^b * (factors other than 2 or 5)
s(n-1) = 2^c * 5^d * (factors other than 2 or 5)
```
Then we have:
```
s(n) = s(n-1) * s(n-2)
= 2^(a+c) * 5^(b+d) * (factors other than 2 or 5)
```
Therefore, we can treat this problem like two [Fibonacci sequences](https://en.wikipedia.org/wiki/Fibonacci_number). You start with the number of 2s and 5s in `s(0)` and `s(1)`, and compute the number of 2s and 5s in `s(2), s(3), ..., s(n)` in the Fibonacci-sequence manner:
```
#2s in s(n) = (#2s in s(n-1)) + (#2s in s(n-2))
#5s in s(n) = (#5s in s(n-1)) + (#5s in s(n-2))
```
Finally, the number of trailing zeros is `min(#2s in s(n), #5s in s(n))`.
---
The above algorithm (if implemented with a loop, or memoized recursion) is `O(n)`. Your attempt was exponential in `n`, which is why it takes a long time to run even for `n = 30`. I don't mean to bash your attempt, but it's good to understand these mistakes -- your code is slow for two main reasons:
First, multiplying very large integers with complete precision (as you're doing with `BigInteger`) is extremely slow, since the number of digits can double with each multiplication. If you only care about the number of trailing zeros, complete precision isn't necessary.
Second, ignoring the cost of multiplication, your recursive implementation of `s` is still exponential-time, but it doesn't have to be. Notice that you're computing the same values many times -- `s(n-2)` is computed separately for both `s(n)` and `s(n-1)`, but the value of `s(n-2)` is clearly the same. The trick is to [memoize the recursion](https://stackoverflow.com/questions/7875380/recursive-fibonacci-memoization) by remembering previously-computed results, to avoid recomputation. Alternatively, you can compute Fibonacci-like sequences with a loop:
```
// Computes the n-th Fibonacci number in O(n) time
int[] fib = new int[n + 1];
fib[0] = 0;
fib[1] = 1;
for (int i = 2; i <= n; i++)
fib[i] = fib[i-1] + fib[i-2];
return fib[n];
```
This is a much simpler approach than memoized recursion, at least for this problem. | ```
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int s0 = Integer.parseInt(br.readLine());
int s1 = Integer.parseInt(br.readLine());
int num21 = findNumberOf2s(s0);
int num22 = findNumberOf2s(s1);
int num51 = findNumberOf5s(s0);
int num52 = findNumberOf5s(s1);
int arr2[] = new int[n + 1];
arr2[0] = num21;
arr2[1] = num22;
for (int i = 2; i <= n; i++)
arr2[i] = arr2[i - 1] + arr2[i - 2];
int arr5[] = new int[n + 1];
arr5[0] = num51;
arr5[1] = num52;
for (int i = 2; i <= n; i++)
arr5[i] = arr5[i - 1] + arr5[i - 2];
System.out.println(Math.min(arr2[n], arr5[n]));
}
static int findNumberOf2s(int num) {
int num2 = 0;
while (num % 2 == 0) {
num = num / 2;
num2++;
}
return num2;
}
static int findNumberOf5s(int num) {
int num5 = 0;
while (num % 5 == 0) {
num = num / 5;
num5++;
}
return num5;
}
``` |
72,467,770 | I am trying to scrape and sort articles with a body, headline, and date column. However, when pulling the date, I’m running into an error with the time zone:
```
ValueError: time data 'Jun 1, 2022 2:49PM EDT' does not match format '%b %d, %Y %H:%M%p %z'
```
My code is as follows:
```
def get_info(url):
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text)
news = soup.find('div', attrs={'class': 'body__content'}).text
headline = soup.find('h1').text
date = datetime.datetime.strptime(soup.find('time').text, "%b %d, %Y %H:%M%p %z")
columns = [news, headline, date]
column_names = ['News','Headline','Date']
return dict(zip(column_names, columns))
```
Is there a way to grab the time zone in a similar method or just drop it overall? | 2022/06/01 | [
"https://Stackoverflow.com/questions/72467770",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19251626/"
]
| Note %z in strptime() is for timezone offsets not names and %Z only accepts certain values for time zones. For details see [API docs](https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior).
Simplest option is to use [dateparser](https://dateutil.readthedocs.io/en/stable/parser.html) module to parse dates with time zone names (e.g. EDT).
```python
import dateparser
s = "Jun 1, 2022 2:49PM EDT"
d = dateparser.parse(s)
print(d)
```
**Output:**
```
2022-06-01 14:49:00-04:00
```
Many of the date modules (e.g. [dateutil](https://dateutil.readthedocs.io/en/stable/) and [pytz](https://pypi.org/project/pytz/)) have timezone offsets defined for "EST", "PST", etc. but "EDT" is less common. These modules would need you to define the timezone with the offset as UTC-04:00.
```python
import dateutil.parser
s = "Jun 1, 2022 2:49PM EDT"
tzinfos = {"EDT": -14400}
d = dateutil.parser.parse(s, tzinfos=tzinfos)
print(d)
```
**Output:**
```
2022-06-01 14:49:00-04:00
``` | As alternate to @CodeMonkey solution, you may also try it by pandas :
```
pd.to_datetime('Jun 1, 2022 2:49PM EDT').tz_localize('US/Eastern')
``` |
58,693,786 | I am working on an RL problem and I created a class to initialize the model and other parameters. The code is as follows:
```
class Agent:
def __init__(self, state_size, is_eval=False, model_name=""):
self.state_size = state_size
self.action_size = 20 # measurement, CNOT, bit-flip
self.memory = deque(maxlen=1000)
self.inventory = []
self.model_name = model_name
self.is_eval = is_eval
self.done = False
self.gamma = 0.95
self.epsilon = 1.0
self.epsilon_min = 0.01
self.epsilon_decay = 0.995
def model(self):
model = Sequential()
model.add(Dense(units=16, input_dim=self.state_size, activation="relu"))
model.add(Dense(units=32, activation="relu"))
model.add(Dense(units=8, activation="relu"))
model.add(Dense(self.action_size, activation="softmax"))
model.compile(loss="categorical_crossentropy", optimizer=Adam(lr=0.003))
return model
def act(self, state):
options = self.model.predict(state)
return np.argmax(options[0]), options
```
I want to run it for only one iteration, hence I create an object and I pass a vector of length `16` like this:
```
agent = Agent(density.flatten().shape)
state = density.flatten()
action, probs = agent.act(state)
```
However, I get the following error:
```
AttributeError Traceback (most recent call last) <ipython-input-14-4f0ff0c40f49> in <module>
----> 1 action, probs = agent.act(state)
<ipython-input-10-562aaf040521> in act(self, state)
39 # return random.randrange(self.action_size)
40 # model = self.model()
---> 41 options = self.model.predict(state)
42 return np.argmax(options[0]), options
43
AttributeError: 'function' object has no attribute 'predict'
```
What's the issue? I checked some other people's codes as well, like [this](https://github.com/Alexander-H-Liu/Policy-Gradient-and-Actor-Critic-Keras/blob/master/agent_dir/agent_pg.py) and I think mine is also very similar.
Let me know.
**EDIT:**
I changed the argument in `Dense` from `input_dim` to `input_shape` and `self.model.predict(state)` to `self.model().predict(state)`.
Now when I run the NN for one input data of shape `(16,1)`, I get the following error:
>
> ValueError: Error when checking input: expected dense\_1\_input to have
> 3 dimensions, but got array with shape (16, 1)
>
>
>
And when I run it with shape `(1,16)`, I get the following error:
>
> ValueError: Error when checking input: expected dense\_1\_input to have
> 3 dimensions, but got array with shape (1, 16)
>
>
>
What should I do in this case? | 2019/11/04 | [
"https://Stackoverflow.com/questions/58693786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4595522/"
]
| in last code block,
```
def act(self, state):
options = self.model.predict(state)
return np.argmax(options[0]), options
```
self.model is a function which is returning a model, it should be self.model().predict(state) | I used `np.reshape`. So in this case, I did
`density_test = np.reshape(density.flatten(), (1,1,16))`
and the network gave the output. |
2,870,686 | I use TAB and Shift-Tab in Visual Studio to indent an entire selection. This does nothing in Eclipse, and I can't seem to find another way to do it.
Update: I wasn't really paying all that much attention to this initially and did not ask the question correctly.
I now realized that it is in XML files where TAB still does not indent a selection. I did not find a setting for this in the properties, so I assume it is not possible. | 2010/05/20 | [
"https://Stackoverflow.com/questions/2870686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/58880/"
]
| `Tab` and `Shift`+`Tab` are the normal ways to do this in Eclipse, just like in Visual Studio.
In addition to the keyboard shortcuts, you can also do this from the Source menu. Source -> Shift Left, and Source -> Shift Right.
Have you checked to make sure tab/shift tabbing is working as you expect in other applications? Is there a stuck key on your keyboard preventing the shortcuts from working? Could another application be stealing the keyboard shortcuts? (as odd as that sounds...)
Also, try restarting Eclipse. | Go to Window Menu -> Preferences -> Java -> Editor -> Typing and make sure the `'Tab key adjusts the indentation of the current line' checkbox is ticked. |
2,870,686 | I use TAB and Shift-Tab in Visual Studio to indent an entire selection. This does nothing in Eclipse, and I can't seem to find another way to do it.
Update: I wasn't really paying all that much attention to this initially and did not ask the question correctly.
I now realized that it is in XML files where TAB still does not indent a selection. I did not find a setting for this in the properties, so I assume it is not possible. | 2010/05/20 | [
"https://Stackoverflow.com/questions/2870686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/58880/"
]
| `Tab` and `Shift`+`Tab` are the normal ways to do this in Eclipse, just like in Visual Studio.
In addition to the keyboard shortcuts, you can also do this from the Source menu. Source -> Shift Left, and Source -> Shift Right.
Have you checked to make sure tab/shift tabbing is working as you expect in other applications? Is there a stuck key on your keyboard preventing the shortcuts from working? Could another application be stealing the keyboard shortcuts? (as odd as that sounds...)
Also, try restarting Eclipse. | ctrl + i ---> it is for making accurate indentation to a block of source code. |
2,870,686 | I use TAB and Shift-Tab in Visual Studio to indent an entire selection. This does nothing in Eclipse, and I can't seem to find another way to do it.
Update: I wasn't really paying all that much attention to this initially and did not ask the question correctly.
I now realized that it is in XML files where TAB still does not indent a selection. I did not find a setting for this in the properties, so I assume it is not possible. | 2010/05/20 | [
"https://Stackoverflow.com/questions/2870686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/58880/"
]
| ctrl + i ---> it is for making accurate indentation to a block of source code. | Go to Window Menu -> Preferences -> Java -> Editor -> Typing and make sure the `'Tab key adjusts the indentation of the current line' checkbox is ticked. |
217,667 | I tried every solution from [How to run Dropbox daemon in background?](https://unix.stackexchange.com/questions/35624/how-to-run-dropbox-daemon-in-background) and nothing solves my problem:
Basically, I already installed dropbox on my Ubuntu 12.04LTS headless server. I got init.d setup but the problem is that right now I cannot restart the server (other users are using it actively).
So I am trying to start dropbox via SSH which works and dropbox starts to sync, but as soon as I disconnect from SSH dropbox stops runnning. I tried running it on a detached screen, using `($HOME/.dropbox-dist/dropboxd &)&` and they all stop when I log out from SSH.
I tried doing service start but it seems not to work and I don't know why..?
```
$ sudo service dropbox start
[sudo] password:
Starting dropbox...
$ dropbox status
Dropbox isn't running!
```
I followed the instructions:
```
sudo chmod +x /etc/init.d/dropbox
sudo update-rc.d dropbox defaults
```
from <http://www.dropboxwiki.com/tips-and-tricks/install-dropbox-in-an-entirely-text-based-linux-environment#debianubuntu> and I got no error messages. Please help.
I don't care as much about starting the process at server restart, as long as I can launch dropbox via ssh and keep it runnning after i log out.
Thank you
UPDATE & ANSWER: thanks a lot for all your answers. Thanks to user [Nixgrrrl](https://unix.stackexchange.com/users/146799/nixgrrrl)'s comment, I realize that it was because I was using ssh -X (the default on my system). As soon as I did normal ssh, trying the humble `dropbox start &` worked :) | 2015/07/22 | [
"https://unix.stackexchange.com/questions/217667",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/34550/"
]
| Have a look here:
<https://community.spiceworks.com/topic/131973-dropbox-headless-workstation?page=1#entry-6076539>
A user mentioned:
>
> Just thought I'd mention:
>
>
> (a) the latest distributions seem to make this fairly straightfoward,
> just run `dropbox start` from the command line, BUT (b) watch out for
> logging in and out with X11 forwarded.
>
>
> I've set up a lot of Bash aliases for connecting to various machines,
> and they all include the `-X` option to forward X11 packets. Because
> of this, Dropbox kept dying on my on logout, even running it under
> `screen` and with `nohup`. Apparently, having X11 forwarded was causing
> Dropbox to connect the dbus process on my local machine rather than on
> the remote machine; so, when I broke the connection, Dropbox was
> seeing dbus as having terminated and thus was terminating itself.
>
>
> Just FYI, as this stumped me for a bit. The key was that I was having
> to press `Ctrl`-`C` even after logging out / running `exit`
> on the remote machine. Apparently, SSH was keeping the session open, even
> though I had exited Bash, because of the remaining open connection.
>
>
>
The solution is simple even if one (for some reason) wants to keep ssh-ing with the `-X`: before launching Dropbox you should "break" the forwarding for example doing:
```
$ unset DISPLAY
```
If this is done in a Bash script the forwarding is "broken" just inside the script but once this is executed the 'terminal' is still forwarding. | Best solution would be to find the problem that avoids server starting from `service dropbox start`. Check your logs to see what's happened.
But in the mean time, you can start your daemon with `nohup`, that will keep it running after you logout.
`nohup $HOME/.dropbox-dist/dropboxd &` |
217,667 | I tried every solution from [How to run Dropbox daemon in background?](https://unix.stackexchange.com/questions/35624/how-to-run-dropbox-daemon-in-background) and nothing solves my problem:
Basically, I already installed dropbox on my Ubuntu 12.04LTS headless server. I got init.d setup but the problem is that right now I cannot restart the server (other users are using it actively).
So I am trying to start dropbox via SSH which works and dropbox starts to sync, but as soon as I disconnect from SSH dropbox stops runnning. I tried running it on a detached screen, using `($HOME/.dropbox-dist/dropboxd &)&` and they all stop when I log out from SSH.
I tried doing service start but it seems not to work and I don't know why..?
```
$ sudo service dropbox start
[sudo] password:
Starting dropbox...
$ dropbox status
Dropbox isn't running!
```
I followed the instructions:
```
sudo chmod +x /etc/init.d/dropbox
sudo update-rc.d dropbox defaults
```
from <http://www.dropboxwiki.com/tips-and-tricks/install-dropbox-in-an-entirely-text-based-linux-environment#debianubuntu> and I got no error messages. Please help.
I don't care as much about starting the process at server restart, as long as I can launch dropbox via ssh and keep it runnning after i log out.
Thank you
UPDATE & ANSWER: thanks a lot for all your answers. Thanks to user [Nixgrrrl](https://unix.stackexchange.com/users/146799/nixgrrrl)'s comment, I realize that it was because I was using ssh -X (the default on my system). As soon as I did normal ssh, trying the humble `dropbox start &` worked :) | 2015/07/22 | [
"https://unix.stackexchange.com/questions/217667",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/34550/"
]
| Have a look here:
<https://community.spiceworks.com/topic/131973-dropbox-headless-workstation?page=1#entry-6076539>
A user mentioned:
>
> Just thought I'd mention:
>
>
> (a) the latest distributions seem to make this fairly straightfoward,
> just run `dropbox start` from the command line, BUT (b) watch out for
> logging in and out with X11 forwarded.
>
>
> I've set up a lot of Bash aliases for connecting to various machines,
> and they all include the `-X` option to forward X11 packets. Because
> of this, Dropbox kept dying on my on logout, even running it under
> `screen` and with `nohup`. Apparently, having X11 forwarded was causing
> Dropbox to connect the dbus process on my local machine rather than on
> the remote machine; so, when I broke the connection, Dropbox was
> seeing dbus as having terminated and thus was terminating itself.
>
>
> Just FYI, as this stumped me for a bit. The key was that I was having
> to press `Ctrl`-`C` even after logging out / running `exit`
> on the remote machine. Apparently, SSH was keeping the session open, even
> though I had exited Bash, because of the remaining open connection.
>
>
>
The solution is simple even if one (for some reason) wants to keep ssh-ing with the `-X`: before launching Dropbox you should "break" the forwarding for example doing:
```
$ unset DISPLAY
```
If this is done in a Bash script the forwarding is "broken" just inside the script but once this is executed the 'terminal' is still forwarding. | thanks a lot for all your answers. Thanks to user [Nixgrrrl](https://unix.stackexchange.com/users/146799/nixgrrrl)'s comment, I realize that it was because I was using ssh -X (the default on my system). As soon as I did normal ssh, trying the humble `dropbox start &` worked :) |
58,390,962 | I have a ad banner integrate in swiftUI with UIViewControllerRepresentable but i doesn't know to add event like adViewDidReceiveAd(). I have learn on <https://developer.apple.com/tutorials/swiftui/interfacing-with-uikit> but the event adViewDidReceiveAd never start
```
struct GADBannerViewController: UIViewControllerRepresentable {
func makeCoordinator() -> GADBannerViewController.Coordinator {
GADBannerViewController.Coordinator()
}
func makeUIViewController(context: Context) -> UIViewController {
let view = GADBannerView(adSize: kGADAdSizeBanner)
let viewController = UIViewController()
view.adUnitID = "ca-app-pub-3940256099942544/2934735716"
view.rootViewController = viewController
viewController.view.addSubview(view)
viewController.view.frame = CGRect(origin: .zero, size: kGADAdSizeBanner.size)
view.load(GADRequest())
return viewController
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
class Coordinator: NSObject, GADBannerViewDelegate {
func adViewDidReceiveAd(_ bannerView: GADBannerView){
print("AAAAAAAAA")
}
func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError) {
print(error)
}
}
}
``` | 2019/10/15 | [
"https://Stackoverflow.com/questions/58390962",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11876189/"
]
| ```
import SwiftUI
import UIKit
import GoogleMobileAds
final class GADBannerViewController: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
let view = GADBannerView(adSize: kGADAdSizeBanner)
let viewController = UIViewController()
view.adUnitID = "ca-app-pub-3940256099942544/2934735713"
view.rootViewController = viewController
view.delegate = viewController
viewController.view.addSubview(view)
viewController.view.frame = CGRect(origin: .zero, size: kGADAdSizeBanner.size)
view.load(GADRequest())
return viewController
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
extension UIViewController: GADBannerViewDelegate {
public func adViewDidReceiveAd(_ bannerView: GADBannerView) {
print("ok ad")
}
public func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError) {
print("fail ad")
print(error)
}
}
``` | I find the solution, I post here for others :
```
import SwiftUI
import UIKit
import GoogleMobileAds
final class GADBannerViewController: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
let view = GADBannerView(adSize: kGADAdSizeBanner)
let viewController = UIViewController()
view.adUnitID = "ca-app-pub-3940256099942544/2934735713"
view.rootViewController = viewController
view.delegate = viewController
viewController.view.addSubview(view)
viewController.view.frame = CGRect(origin: .zero, size: kGADAdSizeBanner.size)
view.load(GADRequest())
return viewController
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
extension UIViewController: GADBannerViewDelegate {
public func adViewDidReceiveAd(_ bannerView: GADBannerView) {
print("ok ad")
}
public func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError) {
print("fail ad")
print(error)
}
}
``` |
600,645 | I have a unity gain differential op amp, using a grounded dual supply, with both inputs AC coupled.
Does the inverting input need a dedicated path to ground or can the DC bias current find its way to ground via the power supply?
[](https://i.stack.imgur.com/N8nUx.gif)
I've searched around and haven't been able to find much regarding this particular configuration. Most of the information I've found talks about single supplies and/or op amps with only one input AC coupled.
If it matters, the op-amp I'll be using is a TL07X. | 2021/12/16 | [
"https://electronics.stackexchange.com/questions/600645",
"https://electronics.stackexchange.com",
"https://electronics.stackexchange.com/users/303305/"
]
| >
> *Does the inverting input need a dedicated path to ground or can the DC
> bias current find its way to ground via the power supply?*
>
>
>
If the bias current is (say) 10 nA then that flows through R3 and creates a DC error at the input to the device of 470 μV. That will also appear at the output because the DC gain of your circuit is unity due to using input capacitors.
However, because you have a net resistance of 47 kΩ in the non-inverting input, the effect of this bias-induced offset voltage is much reduced (see offset current below).
You should also ideally consider the offset current (usually about ten times lower on this type of op-amp than bias current). This adds another 10% worst case to the numbers above.
But, those offsets all pale to insignificance given the typical input offset voltage (3 mV) that a TL07x produces. | You're fine, the inverting input has a path for bias current through the feedback resistor, and of course the non-inverting input has the resistor to ground.
Both inputs have a dc path to ground, which is the important consideration. |
600,645 | I have a unity gain differential op amp, using a grounded dual supply, with both inputs AC coupled.
Does the inverting input need a dedicated path to ground or can the DC bias current find its way to ground via the power supply?
[](https://i.stack.imgur.com/N8nUx.gif)
I've searched around and haven't been able to find much regarding this particular configuration. Most of the information I've found talks about single supplies and/or op amps with only one input AC coupled.
If it matters, the op-amp I'll be using is a TL07X. | 2021/12/16 | [
"https://electronics.stackexchange.com/questions/600645",
"https://electronics.stackexchange.com",
"https://electronics.stackexchange.com/users/303305/"
]
| You're fine, the inverting input has a path for bias current through the feedback resistor, and of course the non-inverting input has the resistor to ground.
Both inputs have a dc path to ground, which is the important consideration. | The best way to understand and explain circuits in an intuitive way is to show where currents flow (see [my Codidact paper 1](https://electrical.codidact.com/posts/284816)) and what voltages are in circuits ([my Codidact paper 2](https://electrical.codidact.com/posts/284860)).
Here the OP is interested in where the input bias currents flow. That is why I have shown in my Fig. 1 only their paths on a simplified conceptual circuit diagram of a part of an internal op-amp structure.
[](https://i.stack.imgur.com/s13f5.jpg)
Fig. 1. A conceptual op-amp circuit diagram with input bias currents visualized.
It can be supplemented with (thicker) loops representing the collector currents flowing in the input and output stage (see my Fig. 2).
[](https://i.stack.imgur.com/OoAEc.jpg)
Fig. 2. A conceptual op-amp circuit diagram with all currents visualized.
It is interesting to see that the input bias current I- entering the inverting op-amp input is provided by both the positive power supply V+ and negative V- (connected in series) while the input bias current I+ entering the non-inverting input is provided only by the negative power supply V-. |
600,645 | I have a unity gain differential op amp, using a grounded dual supply, with both inputs AC coupled.
Does the inverting input need a dedicated path to ground or can the DC bias current find its way to ground via the power supply?
[](https://i.stack.imgur.com/N8nUx.gif)
I've searched around and haven't been able to find much regarding this particular configuration. Most of the information I've found talks about single supplies and/or op amps with only one input AC coupled.
If it matters, the op-amp I'll be using is a TL07X. | 2021/12/16 | [
"https://electronics.stackexchange.com/questions/600645",
"https://electronics.stackexchange.com",
"https://electronics.stackexchange.com/users/303305/"
]
| >
> *Does the inverting input need a dedicated path to ground or can the DC
> bias current find its way to ground via the power supply?*
>
>
>
If the bias current is (say) 10 nA then that flows through R3 and creates a DC error at the input to the device of 470 μV. That will also appear at the output because the DC gain of your circuit is unity due to using input capacitors.
However, because you have a net resistance of 47 kΩ in the non-inverting input, the effect of this bias-induced offset voltage is much reduced (see offset current below).
You should also ideally consider the offset current (usually about ten times lower on this type of op-amp than bias current). This adds another 10% worst case to the numbers above.
But, those offsets all pale to insignificance given the typical input offset voltage (3 mV) that a TL07x produces. | The best way to understand and explain circuits in an intuitive way is to show where currents flow (see [my Codidact paper 1](https://electrical.codidact.com/posts/284816)) and what voltages are in circuits ([my Codidact paper 2](https://electrical.codidact.com/posts/284860)).
Here the OP is interested in where the input bias currents flow. That is why I have shown in my Fig. 1 only their paths on a simplified conceptual circuit diagram of a part of an internal op-amp structure.
[](https://i.stack.imgur.com/s13f5.jpg)
Fig. 1. A conceptual op-amp circuit diagram with input bias currents visualized.
It can be supplemented with (thicker) loops representing the collector currents flowing in the input and output stage (see my Fig. 2).
[](https://i.stack.imgur.com/OoAEc.jpg)
Fig. 2. A conceptual op-amp circuit diagram with all currents visualized.
It is interesting to see that the input bias current I- entering the inverting op-amp input is provided by both the positive power supply V+ and negative V- (connected in series) while the input bias current I+ entering the non-inverting input is provided only by the negative power supply V-. |
24,643,258 | I am trying to increment an array of 5 in Java by 100 starting at 0(to get the output of: 0,100,200,300,400). For some reason my for loop will not add 100 and when I run the program, it just prints 0,0,0,0,0. Any help would be appreciated.
```
public class Integers {
void createIntegers(int[] arr) {
for (int n = 0; n < arr.length; n += 100);
}
void printIntegers(int[] arr) {
int index;
for (index = 0; index < arr.length; index++) {
System.out.println(arr[index]);
}
}
public static void main(String[] args) {
int[] arr = new int[5];
Integers createIntegers = new Integers();
createIntegers.createIntegers(arr);
createIntegers.printIntegers(arr);
}
}
``` | 2014/07/08 | [
"https://Stackoverflow.com/questions/24643258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3818410/"
]
| It is very easy, you need only slight change :
```
public class Integers {
void createIntegers(int[] arr) {
for (int n = 0; n < arr.length; n++){
arr[n] = 100*n;
}
}
void printIntegers(int[] arr) {
for (int index = 0; index < arr.length; index++) {
System.out.println(arr[index]);
}
}
public static void main(String[] args) {
int[] arr = new int[5];
Integers createIntegers = new Integers();
createIntegers.createIntegers(arr);
createIntegers.printIntegers(arr);
}
}
```
The problem was in your `createIntegers` method. You did not do anything with array, you were just incrementing variable `n`
---
What does this `for (int n = 0; n < arr.length; n += 100);` do:
`int n = 0` ->This is executed only once on the beggining of the whole for construct. You declare variable `n` and set its value to zero.
`n < arr.length` ->As long as this condition is true on the beggining of new cycle, the cycle is running.
`n += 100` -> This is executed at the end of each cycle. However incrementing variable n by 100 does not change anything in array. | Two things:
1. You're not setting the integers in your first method
2. You're incrementing by too large a number in the for loop in your first method
Try something more along the lines of multiplying by 100 inside the for loop and storing the result in the index location
```
for(int i = 0; i < arr.length; i++){
arr[i] = i * 100;
}
```
Here we're incrementing by one each time and the multiplying then assigning |
24,643,258 | I am trying to increment an array of 5 in Java by 100 starting at 0(to get the output of: 0,100,200,300,400). For some reason my for loop will not add 100 and when I run the program, it just prints 0,0,0,0,0. Any help would be appreciated.
```
public class Integers {
void createIntegers(int[] arr) {
for (int n = 0; n < arr.length; n += 100);
}
void printIntegers(int[] arr) {
int index;
for (index = 0; index < arr.length; index++) {
System.out.println(arr[index]);
}
}
public static void main(String[] args) {
int[] arr = new int[5];
Integers createIntegers = new Integers();
createIntegers.createIntegers(arr);
createIntegers.printIntegers(arr);
}
}
``` | 2014/07/08 | [
"https://Stackoverflow.com/questions/24643258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3818410/"
]
| Two things:
1. You're not setting the integers in your first method
2. You're incrementing by too large a number in the for loop in your first method
Try something more along the lines of multiplying by 100 inside the for loop and storing the result in the index location
```
for(int i = 0; i < arr.length; i++){
arr[i] = i * 100;
}
```
Here we're incrementing by one each time and the multiplying then assigning | Looks like you need to read up a bit on the basics, here's some sample code to help you achieve what your trying to do. Your code is not doing as expected since your for condition is just looping but not actually assigning anything.
```
public class Test {
private static int[] myIntegers = new int[5];
private static int incrementor = 100;
public static void main(String args[]) {
// Add values to the array
for (int i = 0; i < myIntegers.length; i++) {
myIntegers[i] = incrementor;
incrementor += 100;
}
// Print out the array
for (int i = 0; i < myIntegers.length; i++) {
System.out.println(myIntegers[i]);
}
}
}
``` |
24,643,258 | I am trying to increment an array of 5 in Java by 100 starting at 0(to get the output of: 0,100,200,300,400). For some reason my for loop will not add 100 and when I run the program, it just prints 0,0,0,0,0. Any help would be appreciated.
```
public class Integers {
void createIntegers(int[] arr) {
for (int n = 0; n < arr.length; n += 100);
}
void printIntegers(int[] arr) {
int index;
for (index = 0; index < arr.length; index++) {
System.out.println(arr[index]);
}
}
public static void main(String[] args) {
int[] arr = new int[5];
Integers createIntegers = new Integers();
createIntegers.createIntegers(arr);
createIntegers.printIntegers(arr);
}
}
``` | 2014/07/08 | [
"https://Stackoverflow.com/questions/24643258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3818410/"
]
| It is very easy, you need only slight change :
```
public class Integers {
void createIntegers(int[] arr) {
for (int n = 0; n < arr.length; n++){
arr[n] = 100*n;
}
}
void printIntegers(int[] arr) {
for (int index = 0; index < arr.length; index++) {
System.out.println(arr[index]);
}
}
public static void main(String[] args) {
int[] arr = new int[5];
Integers createIntegers = new Integers();
createIntegers.createIntegers(arr);
createIntegers.printIntegers(arr);
}
}
```
The problem was in your `createIntegers` method. You did not do anything with array, you were just incrementing variable `n`
---
What does this `for (int n = 0; n < arr.length; n += 100);` do:
`int n = 0` ->This is executed only once on the beggining of the whole for construct. You declare variable `n` and set its value to zero.
`n < arr.length` ->As long as this condition is true on the beggining of new cycle, the cycle is running.
`n += 100` -> This is executed at the end of each cycle. However incrementing variable n by 100 does not change anything in array. | The body of your for loop inside createIntegers() is empty, and therefore isn't doing anything, as well as the fact that it will only run once, as after it does, n will be 100, and 100 > 5. You need to use a separate variable to increment the list integers, and a separate variable to keep track of the iterations, like so:
```
n = 0
for (int i = 0; i < arr.length; i++) {
arr[i] = n;
n += 100;
}
``` |
24,643,258 | I am trying to increment an array of 5 in Java by 100 starting at 0(to get the output of: 0,100,200,300,400). For some reason my for loop will not add 100 and when I run the program, it just prints 0,0,0,0,0. Any help would be appreciated.
```
public class Integers {
void createIntegers(int[] arr) {
for (int n = 0; n < arr.length; n += 100);
}
void printIntegers(int[] arr) {
int index;
for (index = 0; index < arr.length; index++) {
System.out.println(arr[index]);
}
}
public static void main(String[] args) {
int[] arr = new int[5];
Integers createIntegers = new Integers();
createIntegers.createIntegers(arr);
createIntegers.printIntegers(arr);
}
}
``` | 2014/07/08 | [
"https://Stackoverflow.com/questions/24643258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3818410/"
]
| It is very easy, you need only slight change :
```
public class Integers {
void createIntegers(int[] arr) {
for (int n = 0; n < arr.length; n++){
arr[n] = 100*n;
}
}
void printIntegers(int[] arr) {
for (int index = 0; index < arr.length; index++) {
System.out.println(arr[index]);
}
}
public static void main(String[] args) {
int[] arr = new int[5];
Integers createIntegers = new Integers();
createIntegers.createIntegers(arr);
createIntegers.printIntegers(arr);
}
}
```
The problem was in your `createIntegers` method. You did not do anything with array, you were just incrementing variable `n`
---
What does this `for (int n = 0; n < arr.length; n += 100);` do:
`int n = 0` ->This is executed only once on the beggining of the whole for construct. You declare variable `n` and set its value to zero.
`n < arr.length` ->As long as this condition is true on the beggining of new cycle, the cycle is running.
`n += 100` -> This is executed at the end of each cycle. However incrementing variable n by 100 does not change anything in array. | Looks like you need to read up a bit on the basics, here's some sample code to help you achieve what your trying to do. Your code is not doing as expected since your for condition is just looping but not actually assigning anything.
```
public class Test {
private static int[] myIntegers = new int[5];
private static int incrementor = 100;
public static void main(String args[]) {
// Add values to the array
for (int i = 0; i < myIntegers.length; i++) {
myIntegers[i] = incrementor;
incrementor += 100;
}
// Print out the array
for (int i = 0; i < myIntegers.length; i++) {
System.out.println(myIntegers[i]);
}
}
}
``` |
24,643,258 | I am trying to increment an array of 5 in Java by 100 starting at 0(to get the output of: 0,100,200,300,400). For some reason my for loop will not add 100 and when I run the program, it just prints 0,0,0,0,0. Any help would be appreciated.
```
public class Integers {
void createIntegers(int[] arr) {
for (int n = 0; n < arr.length; n += 100);
}
void printIntegers(int[] arr) {
int index;
for (index = 0; index < arr.length; index++) {
System.out.println(arr[index]);
}
}
public static void main(String[] args) {
int[] arr = new int[5];
Integers createIntegers = new Integers();
createIntegers.createIntegers(arr);
createIntegers.printIntegers(arr);
}
}
``` | 2014/07/08 | [
"https://Stackoverflow.com/questions/24643258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3818410/"
]
| The body of your for loop inside createIntegers() is empty, and therefore isn't doing anything, as well as the fact that it will only run once, as after it does, n will be 100, and 100 > 5. You need to use a separate variable to increment the list integers, and a separate variable to keep track of the iterations, like so:
```
n = 0
for (int i = 0; i < arr.length; i++) {
arr[i] = n;
n += 100;
}
``` | Looks like you need to read up a bit on the basics, here's some sample code to help you achieve what your trying to do. Your code is not doing as expected since your for condition is just looping but not actually assigning anything.
```
public class Test {
private static int[] myIntegers = new int[5];
private static int incrementor = 100;
public static void main(String args[]) {
// Add values to the array
for (int i = 0; i < myIntegers.length; i++) {
myIntegers[i] = incrementor;
incrementor += 100;
}
// Print out the array
for (int i = 0; i < myIntegers.length; i++) {
System.out.println(myIntegers[i]);
}
}
}
``` |
36,906,719 | The offending line in my index.html file reads
```
<script src="main.dart" type="application/dart"></script>
```
The error report is:
```
Build error:
Transform polymer (PolymerBootstrapTransformer) on myproj_frontend|web/index.html threw error: Invalid argument(s): Illegal character in path
dart:core/uri.dart 855 Uri._checkWindowsPathReservedCharacters
dart:core/uri.dart 956 Uri._makeWindowsFileUrl
```
The entire path to the project is
`D:\Projects\MyProj\MyProj_Project`
I'm building from command line on Windows 7 using Dart VM version: 1.16.0
I honestly have no idea how to continue diagnosing or fixing this. *Any* help would be greatly appreciated. | 2016/04/28 | [
"https://Stackoverflow.com/questions/36906719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1321279/"
]
| I have the same problem. Looks like it is an issue with the `analyzer` package `0.27.0` and later.
I solved it by pinning the version in `pubspec.yaml` to `<0.27.0`. | I found that analyzer 0.27.2 is ok, but analyzer 0.27.3 will cause exception “Invalid argument(s): Illegal character in path” on my Win 10.
ps. I use Dart 1.16.0 |
405,341 | I saw a user who asked this question [i wanna know more this Fibonacci's operating Principles](https://stackoverflow.com/questions/66270493/i-wanna-know-more-this-fibonaccis-operating-principles#66270493) who then voted to close his own question.
What results from a person closing their own question rather than just deleting it? Are there some question/answer rep points possibly awarded on such question (Not a case here... but potentially...) Why would a person vote to close their own question?
Are the impacts on the close vote queue and re-open queue review negligible?
I wonder about that particular use case... Should it instead automatically trigger a delete of the question?
I think if a user wants to close its own question... It is equal to delete it. But I may miss some aspects too. | 2021/02/19 | [
"https://meta.stackoverflow.com/questions/405341",
"https://meta.stackoverflow.com",
"https://meta.stackoverflow.com/users/2159528/"
]
| This post has an answer [When is it OK to delete your own question?](https://meta.stackoverflow.com/questions/281849/when-is-it-ok-to-delete-your-own-question) that has some good points about not deleting a question.
Rather than automatically trigger a delete instead offer that as an option should a person try to close their own question. That way a person gets to make the decision as to whether to just close the question or to actually delete it.
What would be interesting would be to allow a person who creates a question to also be able to close it themselves just as a person can also delete it by themselves. For instance if someone finds out their post is a duplicate, they could just go ahead and close as duplicate. [Why do you have the option to vote to close your own question? Why would you ever do that?](https://meta.stackoverflow.com/questions/345429/why-do-you-have-the-option-to-vote-to-close-your-own-question-why-would-you-eve)
If a question is closed, it can still be seen by anyone, anyone can edit it, and anyone can ask for it to be reopened.
Closing a question can discourage voting on the question, giving the person asking it breathing space to think and edit the question. At the same time people can give feedback through comments.
However Owner Hold has been proposed in the past as an alternative to deleting a question. See this discussion [Putting your own question on Owner-Hold](https://meta.stackoverflow.com/questions/284262/putting-your-own-question-on-owner-hold) with an answer that begins
>
> There is already a feature for this, it is called delete. You can edit
> when a post is deleted, all comments, voting, and answers are locked,
> and it does not show up anywhere.
>
>
> | Guiding users to delete content sounds like a bad idea.
I don't think there is serious misunderstanding of what "close" and "delete" mean even for new users and I'm pretty sure number of "self-close" vote is very small to deserve any additional work even if there is some value in it (I'm not interested in the exact numbers as I don't think it should be implemented even if there is enough close votes, but the feature request can be improved by actual usage numbers).
At least half of close reasons are not about "this is not suitable for SO ever" but either "need to be improved by OP" or "resolved in a way that answers should not be added to this post". Only "belongs to another SE site" and blatant recommendations requests deserve deletion (and many recommendation requests actually fine if reworded to follow rules).
Guiding users toward removal of the content imply that it is something that SO/SE actually encourages. This is not the case as it is generally preferable to improve content rather than remove.
And guiding new users toward deletion of the content may push them toward question ban, especially if that was for a question that was "resolved in a way unlikely to help future users" with an answer.
Overall I would prefer users to be guided toward close, improve and re-open rather than delete and re-ask. |
405,341 | I saw a user who asked this question [i wanna know more this Fibonacci's operating Principles](https://stackoverflow.com/questions/66270493/i-wanna-know-more-this-fibonaccis-operating-principles#66270493) who then voted to close his own question.
What results from a person closing their own question rather than just deleting it? Are there some question/answer rep points possibly awarded on such question (Not a case here... but potentially...) Why would a person vote to close their own question?
Are the impacts on the close vote queue and re-open queue review negligible?
I wonder about that particular use case... Should it instead automatically trigger a delete of the question?
I think if a user wants to close its own question... It is equal to delete it. But I may miss some aspects too. | 2021/02/19 | [
"https://meta.stackoverflow.com/questions/405341",
"https://meta.stackoverflow.com",
"https://meta.stackoverflow.com/users/2159528/"
]
| This post has an answer [When is it OK to delete your own question?](https://meta.stackoverflow.com/questions/281849/when-is-it-ok-to-delete-your-own-question) that has some good points about not deleting a question.
Rather than automatically trigger a delete instead offer that as an option should a person try to close their own question. That way a person gets to make the decision as to whether to just close the question or to actually delete it.
What would be interesting would be to allow a person who creates a question to also be able to close it themselves just as a person can also delete it by themselves. For instance if someone finds out their post is a duplicate, they could just go ahead and close as duplicate. [Why do you have the option to vote to close your own question? Why would you ever do that?](https://meta.stackoverflow.com/questions/345429/why-do-you-have-the-option-to-vote-to-close-your-own-question-why-would-you-eve)
If a question is closed, it can still be seen by anyone, anyone can edit it, and anyone can ask for it to be reopened.
Closing a question can discourage voting on the question, giving the person asking it breathing space to think and edit the question. At the same time people can give feedback through comments.
However Owner Hold has been proposed in the past as an alternative to deleting a question. See this discussion [Putting your own question on Owner-Hold](https://meta.stackoverflow.com/questions/284262/putting-your-own-question-on-owner-hold) with an answer that begins
>
> There is already a feature for this, it is called delete. You can edit
> when a post is deleted, all comments, voting, and answers are locked,
> and it does not show up anywhere.
>
>
> | I think, no - if the user has the intent to delete the question, but he can not, it has a reason (mostly, to not lose the work of the answerers). If the user has no intent to delete his question, but wants to close it on some reason, then he gets his vote to close it.
I think, what could be done better:
1. Users might get decisive close votes to their own questions, if they want to close it on some reason.
2. The most likely cause of the intent that the user wants to delete his own question, is that it was deeply downvoted. Currently, deeply downvoted questions can be disassociated from the user's profile, but it requires the /contact form (i.e. a CM can do it manually). This process could (should) be automatized. |
405,341 | I saw a user who asked this question [i wanna know more this Fibonacci's operating Principles](https://stackoverflow.com/questions/66270493/i-wanna-know-more-this-fibonaccis-operating-principles#66270493) who then voted to close his own question.
What results from a person closing their own question rather than just deleting it? Are there some question/answer rep points possibly awarded on such question (Not a case here... but potentially...) Why would a person vote to close their own question?
Are the impacts on the close vote queue and re-open queue review negligible?
I wonder about that particular use case... Should it instead automatically trigger a delete of the question?
I think if a user wants to close its own question... It is equal to delete it. But I may miss some aspects too. | 2021/02/19 | [
"https://meta.stackoverflow.com/questions/405341",
"https://meta.stackoverflow.com",
"https://meta.stackoverflow.com/users/2159528/"
]
| Guiding users to delete content sounds like a bad idea.
I don't think there is serious misunderstanding of what "close" and "delete" mean even for new users and I'm pretty sure number of "self-close" vote is very small to deserve any additional work even if there is some value in it (I'm not interested in the exact numbers as I don't think it should be implemented even if there is enough close votes, but the feature request can be improved by actual usage numbers).
At least half of close reasons are not about "this is not suitable for SO ever" but either "need to be improved by OP" or "resolved in a way that answers should not be added to this post". Only "belongs to another SE site" and blatant recommendations requests deserve deletion (and many recommendation requests actually fine if reworded to follow rules).
Guiding users toward removal of the content imply that it is something that SO/SE actually encourages. This is not the case as it is generally preferable to improve content rather than remove.
And guiding new users toward deletion of the content may push them toward question ban, especially if that was for a question that was "resolved in a way unlikely to help future users" with an answer.
Overall I would prefer users to be guided toward close, improve and re-open rather than delete and re-ask. | I think, no - if the user has the intent to delete the question, but he can not, it has a reason (mostly, to not lose the work of the answerers). If the user has no intent to delete his question, but wants to close it on some reason, then he gets his vote to close it.
I think, what could be done better:
1. Users might get decisive close votes to their own questions, if they want to close it on some reason.
2. The most likely cause of the intent that the user wants to delete his own question, is that it was deeply downvoted. Currently, deeply downvoted questions can be disassociated from the user's profile, but it requires the /contact form (i.e. a CM can do it manually). This process could (should) be automatized. |
23,014,043 | is there a way to track using google analytics what radio in a radio group is being selected? Our issue is that if a user tabs through the radio group (for accessibility concerns) it will fire off an event for each option.
Not sure how to get around this besides adding a button to for the user to say i've made my selection' and then firing the select event off then. This is not desired though..
**UPDATE - EXAMPLE**
See here: <http://jsfiddle.net/DU6s3/3/>
**Example code**
```
$(document).ready(function () {
$(this).focus(function () {
alert("fire tracking");
});
});
```
Thanks, | 2014/04/11 | [
"https://Stackoverflow.com/questions/23014043",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/982439/"
]
| If you don't have JDK you should probably install it. Find it [here](http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html)
**JDK/Java SDK** = Java Development Kit/Java Software Development Kit - what you need to write programs that require Java or use libraries written in Java. For example, if you were to write your own word-processing tool in Java.
**JRE** = Java Runtime Environment - what you need to run programs/software that require Java or use libraries written in Java. For example, OpenOffice requires the Java Runtime Environment
JRE allows you to run Java, whereas JDK allows you to program with it. | You need to install JDK from here <http://www.oracle.com/technetwork/java/javase/downloads/index.html>. what you are having is JRE, but you dont have jdk. remove existing JRE and install JDK from the site. |
23,014,043 | is there a way to track using google analytics what radio in a radio group is being selected? Our issue is that if a user tabs through the radio group (for accessibility concerns) it will fire off an event for each option.
Not sure how to get around this besides adding a button to for the user to say i've made my selection' and then firing the select event off then. This is not desired though..
**UPDATE - EXAMPLE**
See here: <http://jsfiddle.net/DU6s3/3/>
**Example code**
```
$(document).ready(function () {
$(this).focus(function () {
alert("fire tracking");
});
});
```
Thanks, | 2014/04/11 | [
"https://Stackoverflow.com/questions/23014043",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/982439/"
]
| If you don't have JDK you should probably install it. Find it [here](http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html)
**JDK/Java SDK** = Java Development Kit/Java Software Development Kit - what you need to write programs that require Java or use libraries written in Java. For example, if you were to write your own word-processing tool in Java.
**JRE** = Java Runtime Environment - what you need to run programs/software that require Java or use libraries written in Java. For example, OpenOffice requires the Java Runtime Environment
JRE allows you to run Java, whereas JDK allows you to program with it. | What is the Fully qualified name for Database class ?
You need to install JDK from
<http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html>
Then from JDK folder u will find file called src.zip which is include all the source code of the standard class's . But i believe
this will not show the source for this Database class since its not standard class if you can get the fully qualified name of the class you can find its jar from
<http://www.findjar.com> |
23,014,043 | is there a way to track using google analytics what radio in a radio group is being selected? Our issue is that if a user tabs through the radio group (for accessibility concerns) it will fire off an event for each option.
Not sure how to get around this besides adding a button to for the user to say i've made my selection' and then firing the select event off then. This is not desired though..
**UPDATE - EXAMPLE**
See here: <http://jsfiddle.net/DU6s3/3/>
**Example code**
```
$(document).ready(function () {
$(this).focus(function () {
alert("fire tracking");
});
});
```
Thanks, | 2014/04/11 | [
"https://Stackoverflow.com/questions/23014043",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/982439/"
]
| You need to install JDK from here <http://www.oracle.com/technetwork/java/javase/downloads/index.html>. what you are having is JRE, but you dont have jdk. remove existing JRE and install JDK from the site. | What is the Fully qualified name for Database class ?
You need to install JDK from
<http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html>
Then from JDK folder u will find file called src.zip which is include all the source code of the standard class's . But i believe
this will not show the source for this Database class since its not standard class if you can get the fully qualified name of the class you can find its jar from
<http://www.findjar.com> |
31,469,681 | I am working on a huge android project with tons of classes. Until now we are compiling with Android 3.2 and giving support to Android 2.3.
Now I am testing to compile with Android 5.1.1, but still giving support to Android 2.3. My surprise was that a lot of code is deprecated now... (`getWith(), getDrawable(), setBackgroundDrawable(), HttpRequest, ActivityGroup`, etc...). Those deprecated functions does not give compile error, but it gives deprecated warning.
I know that I can duplicate code and make special calls to deprecated methods if SDK\_INT is lower than XX and calls to new methods if SDK\_INT is newer than XX, but this is a huge patch, that will need a lot of duplicate code in a lot of functions in a ton of classes and packages, so, if it is possible, we prefeer to wait until we don't need to give support to oldest versions of android. It means to continue using deprecated methods until for example we only need to give support from 4.4, that will means munch less duplicated code and functions will be needed.
**The question is:** If i compile with Android 5.1.1 but still use those deprecated functions, this huge project will continue to work on all devices (from 2.3 to 5.1.1)? Now it's working compiling with Android 3.2.
I understand that Deprecated means that they are likely to be removed in a future version of the platform and so you should begin looking at replacing their use in your code, but if it is still supported and does not give a compile error, it will work well as until now. It is what I understand of deprecation. **It is right?**
Thanks. | 2015/07/17 | [
"https://Stackoverflow.com/questions/31469681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/479886/"
]
| Deprecated means two things:
1. There is another (maybe better) solution
2. It isn't fully support anymore
That means that your code `could` be run fine. But Google/Android don't guarantee that.
According to [Java documentation](https://docs.oracle.com/javase/tutorial/java/annotations/predefined.html) the `@Deprecated` annotation says:
>
> @Deprecated annotation indicates that the marked element is deprecated and **should no longer be used**. The compiler generates a warning whenever a program uses a method, class, or field with the @Deprecated annotation. [...]
>
>
>
So please stop using deprecated methods. :)
Have you looked or do you know that there are [support-libraries](https://developer.android.com/tools/support-library/index.html) to help you with backward compatibility? | Yes it should work fine. But you really should use the latest methods instead of deprecated ones and use support libraries to make it compatible to the previous versions.
All the deprecated methods that I have used have worked fine, but Google does not guarantee that they will. |
31,469,681 | I am working on a huge android project with tons of classes. Until now we are compiling with Android 3.2 and giving support to Android 2.3.
Now I am testing to compile with Android 5.1.1, but still giving support to Android 2.3. My surprise was that a lot of code is deprecated now... (`getWith(), getDrawable(), setBackgroundDrawable(), HttpRequest, ActivityGroup`, etc...). Those deprecated functions does not give compile error, but it gives deprecated warning.
I know that I can duplicate code and make special calls to deprecated methods if SDK\_INT is lower than XX and calls to new methods if SDK\_INT is newer than XX, but this is a huge patch, that will need a lot of duplicate code in a lot of functions in a ton of classes and packages, so, if it is possible, we prefeer to wait until we don't need to give support to oldest versions of android. It means to continue using deprecated methods until for example we only need to give support from 4.4, that will means munch less duplicated code and functions will be needed.
**The question is:** If i compile with Android 5.1.1 but still use those deprecated functions, this huge project will continue to work on all devices (from 2.3 to 5.1.1)? Now it's working compiling with Android 3.2.
I understand that Deprecated means that they are likely to be removed in a future version of the platform and so you should begin looking at replacing their use in your code, but if it is still supported and does not give a compile error, it will work well as until now. It is what I understand of deprecation. **It is right?**
Thanks. | 2015/07/17 | [
"https://Stackoverflow.com/questions/31469681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/479886/"
]
| Deprecated means two things:
1. There is another (maybe better) solution
2. It isn't fully support anymore
That means that your code `could` be run fine. But Google/Android don't guarantee that.
According to [Java documentation](https://docs.oracle.com/javase/tutorial/java/annotations/predefined.html) the `@Deprecated` annotation says:
>
> @Deprecated annotation indicates that the marked element is deprecated and **should no longer be used**. The compiler generates a warning whenever a program uses a method, class, or field with the @Deprecated annotation. [...]
>
>
>
So please stop using deprecated methods. :)
Have you looked or do you know that there are [support-libraries](https://developer.android.com/tools/support-library/index.html) to help you with backward compatibility? | You can continue using deprecated methods, they should still work as intended. But you have to be careful, because they could be removed in future versions.
As mentioned in the documention over [developer.android.com](https://developer.android.com/reference/java/lang/Deprecated)
>
> A program element annotated @Deprecated is one that programmers are
> discouraged from using, typically because it is dangerous, or because
> a better alternative exists. Compilers warn when a deprecated program
> element is used or overridden in non-deprecated code.
>
>
> |
31,469,681 | I am working on a huge android project with tons of classes. Until now we are compiling with Android 3.2 and giving support to Android 2.3.
Now I am testing to compile with Android 5.1.1, but still giving support to Android 2.3. My surprise was that a lot of code is deprecated now... (`getWith(), getDrawable(), setBackgroundDrawable(), HttpRequest, ActivityGroup`, etc...). Those deprecated functions does not give compile error, but it gives deprecated warning.
I know that I can duplicate code and make special calls to deprecated methods if SDK\_INT is lower than XX and calls to new methods if SDK\_INT is newer than XX, but this is a huge patch, that will need a lot of duplicate code in a lot of functions in a ton of classes and packages, so, if it is possible, we prefeer to wait until we don't need to give support to oldest versions of android. It means to continue using deprecated methods until for example we only need to give support from 4.4, that will means munch less duplicated code and functions will be needed.
**The question is:** If i compile with Android 5.1.1 but still use those deprecated functions, this huge project will continue to work on all devices (from 2.3 to 5.1.1)? Now it's working compiling with Android 3.2.
I understand that Deprecated means that they are likely to be removed in a future version of the platform and so you should begin looking at replacing their use in your code, but if it is still supported and does not give a compile error, it will work well as until now. It is what I understand of deprecation. **It is right?**
Thanks. | 2015/07/17 | [
"https://Stackoverflow.com/questions/31469681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/479886/"
]
| Deprecated means two things:
1. There is another (maybe better) solution
2. It isn't fully support anymore
That means that your code `could` be run fine. But Google/Android don't guarantee that.
According to [Java documentation](https://docs.oracle.com/javase/tutorial/java/annotations/predefined.html) the `@Deprecated` annotation says:
>
> @Deprecated annotation indicates that the marked element is deprecated and **should no longer be used**. The compiler generates a warning whenever a program uses a method, class, or field with the @Deprecated annotation. [...]
>
>
>
So please stop using deprecated methods. :)
Have you looked or do you know that there are [support-libraries](https://developer.android.com/tools/support-library/index.html) to help you with backward compatibility? | It may stop working with new version.
Example: LocationManager.addNmeaListener(GpsStatus.NmeaListener listener)
Deprecated from API 24.
Stop Working in API 29 (Android 10). No implementation inside (returns false).
In documentation: No-op method to keep backward-compatibility.
Had trouble to find why old code stop working. |
44,150,266 | I have a quick question how can I loop over an NSMutable array starting from a certain index.
For Example I have these double loops I want k to start from the same index as l.
```
for (Line *l in L)
{
for (Line *k in L)
{
............
}
}
```
To elaborate further, lets say L has 10 object so l start from 0-10 and k from 0 -10. What I want is if l is equal 1 k should start from 1-10 rather than 0 - 10 and when l is equal 2 k should start from 2- 10 rather than 0. Any help is Appreciated | 2017/05/24 | [
"https://Stackoverflow.com/questions/44150266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7438106/"
]
| Objective-C is an extension of C, lookup the C `for` loop and you'll have your answer. HTH
**Addendum**
I was going to let you benefit from the learning experience of looking up the C `for` yourself, however at the time of writing all other answers since added give the code but it is not complete, so here is what you need to produce the `l` and `k` values in the order you wish:
```
for(NSInteger lIndex = 0; lIndex < L.count; lIndex++)
{
Line *l = L[lIndex]; // index into your array to get the element
for(NSInteger kIndex = lIndex; kIndex < L.count; kIndex++)
{
Line *k = L[kIndex];
// process your l and k
}
}
```
As you can see the `for` has three sub-parts which are the *initialisation*, *condition*, and *increment*. The *initialisation* is performed first, then the *condition* to determine whether to execute the `for` body, and the *increment* is executed after the statements in the body and before the *condition* is tested to determine if another iteration should be performed. A `for` loop is roughly (there are some differences that are unimportant here) to the `while` loop:
```
initialisation;
while(condition)
{
body statements;
increment;
}
``` | You have to use an indexed (ordinary) `for` loop instead of fast enumeration (`for-in`):
```
int l;
for (l=startValue; l<=endValue; l++)
{
int i;
for (int i=l; i<=endValue; i++)
{
…
}
}
``` |
44,150,266 | I have a quick question how can I loop over an NSMutable array starting from a certain index.
For Example I have these double loops I want k to start from the same index as l.
```
for (Line *l in L)
{
for (Line *k in L)
{
............
}
}
```
To elaborate further, lets say L has 10 object so l start from 0-10 and k from 0 -10. What I want is if l is equal 1 k should start from 1-10 rather than 0 - 10 and when l is equal 2 k should start from 2- 10 rather than 0. Any help is Appreciated | 2017/05/24 | [
"https://Stackoverflow.com/questions/44150266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7438106/"
]
| You simply need to modify for-statement.
```
NSInteger indexYouNeed;
NSInteger iterationCount;
for (int i = indexYouNeed; i < iterationCount; i++) {
/* Your code here */
}
```
You may find [this link](https://stackoverflow.com/questions/7476541/for-in-statement-objective-c) helpfulll. | You have to use an indexed (ordinary) `for` loop instead of fast enumeration (`for-in`):
```
int l;
for (l=startValue; l<=endValue; l++)
{
int i;
for (int i=l; i<=endValue; i++)
{
…
}
}
``` |
3,530,949 | I have to solve the equation:
$$\sin x + \cos x = \sin x \cos x$$
This is what I tried:
$$\hspace{1cm} \sin x + \cos x = \sin x \cos x \hspace{1cm} ()^2$$
$$\sin^2 x + 2\sin x \cos x + \cos^2 x = \sin^2 x \cos^2x$$
$$1 + \sin(2x) = \dfrac{4 \sin^2 x \cos^2x}{4}$$
$$1 + \sin(2x) = \dfrac{\sin^2(2x)}{4}$$
$$\sin^2(2x) - 4 \sin(2x) -4 = 0$$
Here we can use the notation $t = \sin(2x)$ with the condition that $t \in [-1,1]$.
$$t^2-4t-4=0$$
Solving this quadratic equation we get the solutions:
$$t\_1 = 2+ 2\sqrt{2} \hspace{3cm} t\_2 = 2 - 2\sqrt{2}$$
I managed to prove that $t\_1 \notin [-1, 1]$ and that $t\_2 \in [-1, 1]$. So the only solution is $t\_2 = 2 - \sqrt{2}$. So we have:
$$\sin(2x) = 2 - 2\sqrt{2}$$
From this, we get:
$$2x = \arcsin(2-2\sqrt{2}) + 2 k \pi \hspace{3cm} 2x = \pi - \arcsin(2-2\sqrt{2}) + 2 k \pi$$
$$x = \dfrac{1}{2} \arcsin(2-2\sqrt{2}) + k \pi \hspace{3cm} x = \dfrac{\pi}{2} - \dfrac{1}{2}\arcsin(2 - 2\sqrt{2}) + k \pi$$
Is this solution correct? It's such an ungly answer, that I kind of feel like it can't be right. Did I do something wrong? | 2020/02/01 | [
"https://math.stackexchange.com/questions/3530949",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/-1/"
]
| Note that when you square the equation
$$(\sin x + \cos x)^2 = (\sin x \cos x)^2$$
which can be factorized as
$$(\sin x + \cos x - \sin x \cos x)(\sin x + \cos x + \sin x \cos x)=0$$
you effectively introduced another equation $\sin x + \cos x =- \sin x \cos x$ in the process beside the original one $\sin x + \cos x = \sin x \cos x$. The solutions obtained include those for the extra equation as well.
Normally, you should plug the solutions into the original equation to check and exclude those that belong to the other equation. However, given the complexity of the solutions, it may not be straightforward to do so. Therefore, the preferred approach is to avoid the square operation.
Here is one such approach. Rewrite the equation $\sin x + \cos x = \sin x \cos x$ as
$$\sqrt2 \cos(x-\frac\pi4 ) = \frac12 \sin 2x = \frac12 \cos (2x-\frac\pi2 ) $$
Use the identity $\cos 2t = 2\cos^2 t -1$ on the RHS to get the quadratic equation below
$$\sqrt2 \cos(x-\frac\pi4) = \cos^2 (x-\frac\pi4 ) -\frac12$$
or
$$\left( \cos(x-\frac\pi4) - \frac{\sqrt2-2}2\right)\left( \cos(x-\frac\pi4) - \frac{\sqrt2+2}2\right)=0$$
Only the first factor yields real roots
$$x = 2n\pi + \frac\pi4 \pm \cos^{-1}\frac{\sqrt2-2}2$$ | As your error has been pointed out, I am providing a different way to tackle the problem without introducing extra solutions.
From the given equation, we have $1=(1-\sin x)(1-\cos x)$, which is equivalent to
$$1=\Biggl(1-\cos\left(\frac{\pi}2-x\right)\Biggr)\left(2\sin^2 \frac{x}{2}\right)=4\sin^2\left(\frac{\pi}{4}-\frac{x}{2}\right)\sin^2\frac{x}{2}$$
That is
$$2\sin\left(\frac{\pi}{4}-\frac{x}{2}\right)\sin\frac{x}{2}=\pm 1.\tag{1}$$
This means
$$\cos\left(\frac{\pi}{4}-x\right)-\cos\frac{\pi}{4}=\pm 1.$$
Therefore
$$\cos\left(\frac{\pi}{4}-x\right)=\frac{1\pm\sqrt{2}}{\sqrt{2}}.$$
But $\frac{1+\sqrt2}{\sqrt2}>1$, so
$$\cos\left(\frac{\pi}{4}-x\right)=\frac{1-\sqrt 2}{\sqrt2}.\tag{2}$$
Therefore
$$2n\pi+\left(\frac{\pi}{4}-x\right) = \pm \arccos \frac{1-\sqrt 2}{\sqrt2}$$
for some integer $n$. This gives us
$$x=\left(2n+\frac14\right)\pi \pm \arccos \frac{1-\sqrt 2}{\sqrt2}.\tag{3}$$
In fact there are also complex solutions to $(1)$, and they are given by
$$x=\left(2n+\frac{1}{4}\right)\pi\pm i\operatorname{arccosh} \frac{1+\sqrt 2}{\sqrt2}.\tag{4}$$
Note that $$\operatorname{arccosh} \frac{1+\sqrt 2}{\sqrt2}=\ln\left(\frac{1+\sqrt2+\sqrt{1+2\sqrt2}}{\sqrt2}\right).$$
All real and complex solutions to the original equation are given by $(3)$ and $(4)$.
Note that
$$\frac\pi4 + \arccos \frac{1-\sqrt 2}{\sqrt2}=\frac12\arcsin(2-2\sqrt2)+\pi$$
and
$$\frac\pi4 -\arccos \frac{1-\sqrt 2}{\sqrt2}=\frac{\pi}{2}-\frac12\arcsin(2-2\sqrt2)-\pi.$$
So your solutions only work for odd $k$. Even values of $k$ do not give solutions. |
3,530,949 | I have to solve the equation:
$$\sin x + \cos x = \sin x \cos x$$
This is what I tried:
$$\hspace{1cm} \sin x + \cos x = \sin x \cos x \hspace{1cm} ()^2$$
$$\sin^2 x + 2\sin x \cos x + \cos^2 x = \sin^2 x \cos^2x$$
$$1 + \sin(2x) = \dfrac{4 \sin^2 x \cos^2x}{4}$$
$$1 + \sin(2x) = \dfrac{\sin^2(2x)}{4}$$
$$\sin^2(2x) - 4 \sin(2x) -4 = 0$$
Here we can use the notation $t = \sin(2x)$ with the condition that $t \in [-1,1]$.
$$t^2-4t-4=0$$
Solving this quadratic equation we get the solutions:
$$t\_1 = 2+ 2\sqrt{2} \hspace{3cm} t\_2 = 2 - 2\sqrt{2}$$
I managed to prove that $t\_1 \notin [-1, 1]$ and that $t\_2 \in [-1, 1]$. So the only solution is $t\_2 = 2 - \sqrt{2}$. So we have:
$$\sin(2x) = 2 - 2\sqrt{2}$$
From this, we get:
$$2x = \arcsin(2-2\sqrt{2}) + 2 k \pi \hspace{3cm} 2x = \pi - \arcsin(2-2\sqrt{2}) + 2 k \pi$$
$$x = \dfrac{1}{2} \arcsin(2-2\sqrt{2}) + k \pi \hspace{3cm} x = \dfrac{\pi}{2} - \dfrac{1}{2}\arcsin(2 - 2\sqrt{2}) + k \pi$$
Is this solution correct? It's such an ungly answer, that I kind of feel like it can't be right. Did I do something wrong? | 2020/02/01 | [
"https://math.stackexchange.com/questions/3530949",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/-1/"
]
| As your error has been pointed out, I am providing a different way to tackle the problem without introducing extra solutions.
From the given equation, we have $1=(1-\sin x)(1-\cos x)$, which is equivalent to
$$1=\Biggl(1-\cos\left(\frac{\pi}2-x\right)\Biggr)\left(2\sin^2 \frac{x}{2}\right)=4\sin^2\left(\frac{\pi}{4}-\frac{x}{2}\right)\sin^2\frac{x}{2}$$
That is
$$2\sin\left(\frac{\pi}{4}-\frac{x}{2}\right)\sin\frac{x}{2}=\pm 1.\tag{1}$$
This means
$$\cos\left(\frac{\pi}{4}-x\right)-\cos\frac{\pi}{4}=\pm 1.$$
Therefore
$$\cos\left(\frac{\pi}{4}-x\right)=\frac{1\pm\sqrt{2}}{\sqrt{2}}.$$
But $\frac{1+\sqrt2}{\sqrt2}>1$, so
$$\cos\left(\frac{\pi}{4}-x\right)=\frac{1-\sqrt 2}{\sqrt2}.\tag{2}$$
Therefore
$$2n\pi+\left(\frac{\pi}{4}-x\right) = \pm \arccos \frac{1-\sqrt 2}{\sqrt2}$$
for some integer $n$. This gives us
$$x=\left(2n+\frac14\right)\pi \pm \arccos \frac{1-\sqrt 2}{\sqrt2}.\tag{3}$$
In fact there are also complex solutions to $(1)$, and they are given by
$$x=\left(2n+\frac{1}{4}\right)\pi\pm i\operatorname{arccosh} \frac{1+\sqrt 2}{\sqrt2}.\tag{4}$$
Note that $$\operatorname{arccosh} \frac{1+\sqrt 2}{\sqrt2}=\ln\left(\frac{1+\sqrt2+\sqrt{1+2\sqrt2}}{\sqrt2}\right).$$
All real and complex solutions to the original equation are given by $(3)$ and $(4)$.
Note that
$$\frac\pi4 + \arccos \frac{1-\sqrt 2}{\sqrt2}=\frac12\arcsin(2-2\sqrt2)+\pi$$
and
$$\frac\pi4 -\arccos \frac{1-\sqrt 2}{\sqrt2}=\frac{\pi}{2}-\frac12\arcsin(2-2\sqrt2)-\pi.$$
So your solutions only work for odd $k$. Even values of $k$ do not give solutions. | There is a subtle way to get rid of the extra solutions that uses the work you've done.
When you render
$\sin 2x=2\sin x\cos x =2-2\sqrt{2}$
you then have with $u=\sin x, v=\cos x$:
$uv=1-\sqrt{2}$
$\color{blue}{u+v=uv=1-\sqrt{2}}$
where the blue equation reimposes the original requirement and it's goodbye extraneous roots. Using the Vieta formulas for a quadratic polynomial this is solved by rendering $u$ and $v$ as the two roots of the quadratic equation
$w^2-(1-\sqrt2)w+(1-\sqrt2)=0$
The roots of this equation are obtained by the usual methods, and because of the symmetry of the original equation between $\sin x$ and $\cos x$ you may take either root as the sine and the other as the cosine. Note that with the negative product the values must be oppositely signed which informs us of quadrant location.
$\sin x=\dfrac{1-\sqrt2+\sqrt{2\sqrt2-1}}{2},\cos x=\dfrac{1-\sqrt2-\sqrt{2\sqrt2-1}}{2}$ ($x$ in 2nd quadrant)
$\sin x=\dfrac{1-\sqrt2-\sqrt{2\sqrt2-1}}{2},\cos x=\dfrac{1-\sqrt2+\sqrt{2\sqrt2-1}}{2}$ ($x$ in 4th quadrant)
Then with the quadrant information above we may render the correct roots for $x$:
$x=\pi-\arcsin(\dfrac{1-\sqrt2+\sqrt{2\sqrt2-1}}{2})+2n\pi$
$x=\arcsin(\dfrac{1-\sqrt2-\sqrt{2\sqrt2-1}}{2})+2n\pi$ |
3,530,949 | I have to solve the equation:
$$\sin x + \cos x = \sin x \cos x$$
This is what I tried:
$$\hspace{1cm} \sin x + \cos x = \sin x \cos x \hspace{1cm} ()^2$$
$$\sin^2 x + 2\sin x \cos x + \cos^2 x = \sin^2 x \cos^2x$$
$$1 + \sin(2x) = \dfrac{4 \sin^2 x \cos^2x}{4}$$
$$1 + \sin(2x) = \dfrac{\sin^2(2x)}{4}$$
$$\sin^2(2x) - 4 \sin(2x) -4 = 0$$
Here we can use the notation $t = \sin(2x)$ with the condition that $t \in [-1,1]$.
$$t^2-4t-4=0$$
Solving this quadratic equation we get the solutions:
$$t\_1 = 2+ 2\sqrt{2} \hspace{3cm} t\_2 = 2 - 2\sqrt{2}$$
I managed to prove that $t\_1 \notin [-1, 1]$ and that $t\_2 \in [-1, 1]$. So the only solution is $t\_2 = 2 - \sqrt{2}$. So we have:
$$\sin(2x) = 2 - 2\sqrt{2}$$
From this, we get:
$$2x = \arcsin(2-2\sqrt{2}) + 2 k \pi \hspace{3cm} 2x = \pi - \arcsin(2-2\sqrt{2}) + 2 k \pi$$
$$x = \dfrac{1}{2} \arcsin(2-2\sqrt{2}) + k \pi \hspace{3cm} x = \dfrac{\pi}{2} - \dfrac{1}{2}\arcsin(2 - 2\sqrt{2}) + k \pi$$
Is this solution correct? It's such an ungly answer, that I kind of feel like it can't be right. Did I do something wrong? | 2020/02/01 | [
"https://math.stackexchange.com/questions/3530949",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/-1/"
]
| As your error has been pointed out, I am providing a different way to tackle the problem without introducing extra solutions.
From the given equation, we have $1=(1-\sin x)(1-\cos x)$, which is equivalent to
$$1=\Biggl(1-\cos\left(\frac{\pi}2-x\right)\Biggr)\left(2\sin^2 \frac{x}{2}\right)=4\sin^2\left(\frac{\pi}{4}-\frac{x}{2}\right)\sin^2\frac{x}{2}$$
That is
$$2\sin\left(\frac{\pi}{4}-\frac{x}{2}\right)\sin\frac{x}{2}=\pm 1.\tag{1}$$
This means
$$\cos\left(\frac{\pi}{4}-x\right)-\cos\frac{\pi}{4}=\pm 1.$$
Therefore
$$\cos\left(\frac{\pi}{4}-x\right)=\frac{1\pm\sqrt{2}}{\sqrt{2}}.$$
But $\frac{1+\sqrt2}{\sqrt2}>1$, so
$$\cos\left(\frac{\pi}{4}-x\right)=\frac{1-\sqrt 2}{\sqrt2}.\tag{2}$$
Therefore
$$2n\pi+\left(\frac{\pi}{4}-x\right) = \pm \arccos \frac{1-\sqrt 2}{\sqrt2}$$
for some integer $n$. This gives us
$$x=\left(2n+\frac14\right)\pi \pm \arccos \frac{1-\sqrt 2}{\sqrt2}.\tag{3}$$
In fact there are also complex solutions to $(1)$, and they are given by
$$x=\left(2n+\frac{1}{4}\right)\pi\pm i\operatorname{arccosh} \frac{1+\sqrt 2}{\sqrt2}.\tag{4}$$
Note that $$\operatorname{arccosh} \frac{1+\sqrt 2}{\sqrt2}=\ln\left(\frac{1+\sqrt2+\sqrt{1+2\sqrt2}}{\sqrt2}\right).$$
All real and complex solutions to the original equation are given by $(3)$ and $(4)$.
Note that
$$\frac\pi4 + \arccos \frac{1-\sqrt 2}{\sqrt2}=\frac12\arcsin(2-2\sqrt2)+\pi$$
and
$$\frac\pi4 -\arccos \frac{1-\sqrt 2}{\sqrt2}=\frac{\pi}{2}-\frac12\arcsin(2-2\sqrt2)-\pi.$$
So your solutions only work for odd $k$. Even values of $k$ do not give solutions. | Using auxiliary angle, we first change the equation
$$
\sin x+\cos x=\sin x \cos x \tag\*{(\*)}
$$
equivalently to
$$
\sqrt{2} \cos \left(x-\frac{\pi}{4}\right)= \frac{\sin 2 x}{2}
$$
Putting $y=x-\dfrac{\pi}{4} $ gives a quadratic equation in $\cos y $
$$
\sqrt{2} \cos y=\frac{1}{2}\left(2 \cos ^{2} y-1\right)
$$
Solving the quadratic equation yields
$$
\cos y=\frac{\sqrt{2}-2}{2} \text { or } \frac{\sqrt{2}+2}{2} \text { (rejected) }
$$
Plugging the general solution for $(\*)$ is
$$
x=\frac{(8 n+1) \pi}{4} \pm \cos ^{-1}\left(\frac{\sqrt{2}-2}{2}\right),
$$
where $n\in Z.$ |
3,530,949 | I have to solve the equation:
$$\sin x + \cos x = \sin x \cos x$$
This is what I tried:
$$\hspace{1cm} \sin x + \cos x = \sin x \cos x \hspace{1cm} ()^2$$
$$\sin^2 x + 2\sin x \cos x + \cos^2 x = \sin^2 x \cos^2x$$
$$1 + \sin(2x) = \dfrac{4 \sin^2 x \cos^2x}{4}$$
$$1 + \sin(2x) = \dfrac{\sin^2(2x)}{4}$$
$$\sin^2(2x) - 4 \sin(2x) -4 = 0$$
Here we can use the notation $t = \sin(2x)$ with the condition that $t \in [-1,1]$.
$$t^2-4t-4=0$$
Solving this quadratic equation we get the solutions:
$$t\_1 = 2+ 2\sqrt{2} \hspace{3cm} t\_2 = 2 - 2\sqrt{2}$$
I managed to prove that $t\_1 \notin [-1, 1]$ and that $t\_2 \in [-1, 1]$. So the only solution is $t\_2 = 2 - \sqrt{2}$. So we have:
$$\sin(2x) = 2 - 2\sqrt{2}$$
From this, we get:
$$2x = \arcsin(2-2\sqrt{2}) + 2 k \pi \hspace{3cm} 2x = \pi - \arcsin(2-2\sqrt{2}) + 2 k \pi$$
$$x = \dfrac{1}{2} \arcsin(2-2\sqrt{2}) + k \pi \hspace{3cm} x = \dfrac{\pi}{2} - \dfrac{1}{2}\arcsin(2 - 2\sqrt{2}) + k \pi$$
Is this solution correct? It's such an ungly answer, that I kind of feel like it can't be right. Did I do something wrong? | 2020/02/01 | [
"https://math.stackexchange.com/questions/3530949",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/-1/"
]
| Note that when you square the equation
$$(\sin x + \cos x)^2 = (\sin x \cos x)^2$$
which can be factorized as
$$(\sin x + \cos x - \sin x \cos x)(\sin x + \cos x + \sin x \cos x)=0$$
you effectively introduced another equation $\sin x + \cos x =- \sin x \cos x$ in the process beside the original one $\sin x + \cos x = \sin x \cos x$. The solutions obtained include those for the extra equation as well.
Normally, you should plug the solutions into the original equation to check and exclude those that belong to the other equation. However, given the complexity of the solutions, it may not be straightforward to do so. Therefore, the preferred approach is to avoid the square operation.
Here is one such approach. Rewrite the equation $\sin x + \cos x = \sin x \cos x$ as
$$\sqrt2 \cos(x-\frac\pi4 ) = \frac12 \sin 2x = \frac12 \cos (2x-\frac\pi2 ) $$
Use the identity $\cos 2t = 2\cos^2 t -1$ on the RHS to get the quadratic equation below
$$\sqrt2 \cos(x-\frac\pi4) = \cos^2 (x-\frac\pi4 ) -\frac12$$
or
$$\left( \cos(x-\frac\pi4) - \frac{\sqrt2-2}2\right)\left( \cos(x-\frac\pi4) - \frac{\sqrt2+2}2\right)=0$$
Only the first factor yields real roots
$$x = 2n\pi + \frac\pi4 \pm \cos^{-1}\frac{\sqrt2-2}2$$ | There is a subtle way to get rid of the extra solutions that uses the work you've done.
When you render
$\sin 2x=2\sin x\cos x =2-2\sqrt{2}$
you then have with $u=\sin x, v=\cos x$:
$uv=1-\sqrt{2}$
$\color{blue}{u+v=uv=1-\sqrt{2}}$
where the blue equation reimposes the original requirement and it's goodbye extraneous roots. Using the Vieta formulas for a quadratic polynomial this is solved by rendering $u$ and $v$ as the two roots of the quadratic equation
$w^2-(1-\sqrt2)w+(1-\sqrt2)=0$
The roots of this equation are obtained by the usual methods, and because of the symmetry of the original equation between $\sin x$ and $\cos x$ you may take either root as the sine and the other as the cosine. Note that with the negative product the values must be oppositely signed which informs us of quadrant location.
$\sin x=\dfrac{1-\sqrt2+\sqrt{2\sqrt2-1}}{2},\cos x=\dfrac{1-\sqrt2-\sqrt{2\sqrt2-1}}{2}$ ($x$ in 2nd quadrant)
$\sin x=\dfrac{1-\sqrt2-\sqrt{2\sqrt2-1}}{2},\cos x=\dfrac{1-\sqrt2+\sqrt{2\sqrt2-1}}{2}$ ($x$ in 4th quadrant)
Then with the quadrant information above we may render the correct roots for $x$:
$x=\pi-\arcsin(\dfrac{1-\sqrt2+\sqrt{2\sqrt2-1}}{2})+2n\pi$
$x=\arcsin(\dfrac{1-\sqrt2-\sqrt{2\sqrt2-1}}{2})+2n\pi$ |
3,530,949 | I have to solve the equation:
$$\sin x + \cos x = \sin x \cos x$$
This is what I tried:
$$\hspace{1cm} \sin x + \cos x = \sin x \cos x \hspace{1cm} ()^2$$
$$\sin^2 x + 2\sin x \cos x + \cos^2 x = \sin^2 x \cos^2x$$
$$1 + \sin(2x) = \dfrac{4 \sin^2 x \cos^2x}{4}$$
$$1 + \sin(2x) = \dfrac{\sin^2(2x)}{4}$$
$$\sin^2(2x) - 4 \sin(2x) -4 = 0$$
Here we can use the notation $t = \sin(2x)$ with the condition that $t \in [-1,1]$.
$$t^2-4t-4=0$$
Solving this quadratic equation we get the solutions:
$$t\_1 = 2+ 2\sqrt{2} \hspace{3cm} t\_2 = 2 - 2\sqrt{2}$$
I managed to prove that $t\_1 \notin [-1, 1]$ and that $t\_2 \in [-1, 1]$. So the only solution is $t\_2 = 2 - \sqrt{2}$. So we have:
$$\sin(2x) = 2 - 2\sqrt{2}$$
From this, we get:
$$2x = \arcsin(2-2\sqrt{2}) + 2 k \pi \hspace{3cm} 2x = \pi - \arcsin(2-2\sqrt{2}) + 2 k \pi$$
$$x = \dfrac{1}{2} \arcsin(2-2\sqrt{2}) + k \pi \hspace{3cm} x = \dfrac{\pi}{2} - \dfrac{1}{2}\arcsin(2 - 2\sqrt{2}) + k \pi$$
Is this solution correct? It's such an ungly answer, that I kind of feel like it can't be right. Did I do something wrong? | 2020/02/01 | [
"https://math.stackexchange.com/questions/3530949",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/-1/"
]
| Note that when you square the equation
$$(\sin x + \cos x)^2 = (\sin x \cos x)^2$$
which can be factorized as
$$(\sin x + \cos x - \sin x \cos x)(\sin x + \cos x + \sin x \cos x)=0$$
you effectively introduced another equation $\sin x + \cos x =- \sin x \cos x$ in the process beside the original one $\sin x + \cos x = \sin x \cos x$. The solutions obtained include those for the extra equation as well.
Normally, you should plug the solutions into the original equation to check and exclude those that belong to the other equation. However, given the complexity of the solutions, it may not be straightforward to do so. Therefore, the preferred approach is to avoid the square operation.
Here is one such approach. Rewrite the equation $\sin x + \cos x = \sin x \cos x$ as
$$\sqrt2 \cos(x-\frac\pi4 ) = \frac12 \sin 2x = \frac12 \cos (2x-\frac\pi2 ) $$
Use the identity $\cos 2t = 2\cos^2 t -1$ on the RHS to get the quadratic equation below
$$\sqrt2 \cos(x-\frac\pi4) = \cos^2 (x-\frac\pi4 ) -\frac12$$
or
$$\left( \cos(x-\frac\pi4) - \frac{\sqrt2-2}2\right)\left( \cos(x-\frac\pi4) - \frac{\sqrt2+2}2\right)=0$$
Only the first factor yields real roots
$$x = 2n\pi + \frac\pi4 \pm \cos^{-1}\frac{\sqrt2-2}2$$ | Using auxiliary angle, we first change the equation
$$
\sin x+\cos x=\sin x \cos x \tag\*{(\*)}
$$
equivalently to
$$
\sqrt{2} \cos \left(x-\frac{\pi}{4}\right)= \frac{\sin 2 x}{2}
$$
Putting $y=x-\dfrac{\pi}{4} $ gives a quadratic equation in $\cos y $
$$
\sqrt{2} \cos y=\frac{1}{2}\left(2 \cos ^{2} y-1\right)
$$
Solving the quadratic equation yields
$$
\cos y=\frac{\sqrt{2}-2}{2} \text { or } \frac{\sqrt{2}+2}{2} \text { (rejected) }
$$
Plugging the general solution for $(\*)$ is
$$
x=\frac{(8 n+1) \pi}{4} \pm \cos ^{-1}\left(\frac{\sqrt{2}-2}{2}\right),
$$
where $n\in Z.$ |
2,153,266 | I have situation where in the regular expression is something like this:
`^b?A+b?$`
So `b` *may* match at the start of the string 0 or 1 times, and `A` *must* match one or more times. Again `b` *may* match at the end of the string 0 or 1 times.
Now I want to modify this regular expression in such way that it may match `b` either at the start or at the end of the string, but not both.
How do I do this? | 2010/01/28 | [
"https://Stackoverflow.com/questions/2153266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46279/"
]
| Try this:
```
^(bA+|A+b?)$
```
This allows a `b` at the start and then at least one `A`, or some `A`s at the start and optionally a `b` at the end. This covers all the possibilities and is slightly faster than the accepted answer in the case that it doesn't match as only one of the two options needs to be tested (assuming `A` cannot begin with `b`).
Just to be different from the other answers here, if the expression A is quite complex but b is simple, then you might want to do it using a negative lookahead to avoid repeating the entire expression for `A` in your regular expression:
```
^(b(?!.*b$))?A+b?$
```
The second might be more readable if your A is complex, but if performance is an issue I'd recommend the first method. | ```
^(b+A+b?|b?A+b+)$
```
why doesn't that work? |
2,153,266 | I have situation where in the regular expression is something like this:
`^b?A+b?$`
So `b` *may* match at the start of the string 0 or 1 times, and `A` *must* match one or more times. Again `b` *may* match at the end of the string 0 or 1 times.
Now I want to modify this regular expression in such way that it may match `b` either at the start or at the end of the string, but not both.
How do I do this? | 2010/01/28 | [
"https://Stackoverflow.com/questions/2153266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46279/"
]
| Theres a nice "or" operator in regexps you can use.
```
^(b?A+|A+b?)$
``` | ```
^(b+A+b?|b?A+b+)$
```
why doesn't that work? |
2,153,266 | I have situation where in the regular expression is something like this:
`^b?A+b?$`
So `b` *may* match at the start of the string 0 or 1 times, and `A` *must* match one or more times. Again `b` *may* match at the end of the string 0 or 1 times.
Now I want to modify this regular expression in such way that it may match `b` either at the start or at the end of the string, but not both.
How do I do this? | 2010/01/28 | [
"https://Stackoverflow.com/questions/2153266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46279/"
]
| Theres a nice "or" operator in regexps you can use.
```
^(b?A+|A+b?)$
``` | Try this:
```
^(bA+|A+b?)$
```
This allows a `b` at the start and then at least one `A`, or some `A`s at the start and optionally a `b` at the end. This covers all the possibilities and is slightly faster than the accepted answer in the case that it doesn't match as only one of the two options needs to be tested (assuming `A` cannot begin with `b`).
Just to be different from the other answers here, if the expression A is quite complex but b is simple, then you might want to do it using a negative lookahead to avoid repeating the entire expression for `A` in your regular expression:
```
^(b(?!.*b$))?A+b?$
```
The second might be more readable if your A is complex, but if performance is an issue I'd recommend the first method. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.