samedi 26 décembre 2015
Taking the values inside a if condition to an int array - java
if (f.getFieldName().equals("checkboxVal")) {
Genres = f.getString();
}
This if condition will executes several times, there is no exact number.I want to assign each Genres values to an int array.How can this be done.
How to compare v-if with a value in Vue.js
I have the following data and I wish to check if the user has the Admin role.
{
"users": [
{
"id": 3,
"first_name": "Joe",
"last_name": "Blogs",
"roles": [
{
"id": 1,
"name": "Admin",
"created_at": "2015-12-25 15:58:28",
"updated_at": "2015-12-25 15:58:28",
"pivot": {
"user_id": 3,
"role_id": 1,
"created_at": "2015-12-25 16:03:09",
"updated_at": "2015-12-25 16:03:09"
}
},
{
"id": 2,
"name": "Member",
"created_at": "2015-12-25 15:58:28",
"updated_at": "2015-12-25 15:58:28",
"pivot": {
"user_id": 3,
"role_id": 2,
"created_at": "2015-12-25 16:03:09",
"updated_at": "2015-12-25 16:03:09"
}
}
],
}
]
}
In my html I have the following, but how can I use the v-if directive to check if the user has the Admin role? The other problem is that v-if directive below also generates unnecessary html markup if the condition is untrue.
<tr>
<th>User</th>
<th>Admin</th>
<th></th>
</tr>
<tr v-for="user in users">
<td>
@{{user.first_name}} @{{user.last_name}}
</td>
<td>
<span v-for="role in user.roles">
<span v-if="role.name" == 'Admin'>Yes</span>
<span v-else>-</span>
</span>
</td>
</tr>
vendredi 25 décembre 2015
Return value of ping [duplicate]
This question already has an answer here:
I have done a file named hosts.txt which includes some websites, to test the ping on each website with a script. What I want to do with my script is I want to loop through each line that includes different websites, and it should tell if the website is up or down (by measuring the ping command on each)
What my problem is that I don't really know how to get the return value of the ping command, so in case a website is up it should say "'website name' found" or not found. I have been researching, also tried out the ! command and different ways in the if-statement, but none of them seem to work.
My code:
#!/bin/bash
echo
echo "Monitoring hosts from file hosts.txt ..."
echo
echo
egrep -v '^(#|$)' hosts.txt | while read line; do #put the egrep value
#which is the lines in hosts.txt, and loop through each one of them
if [ ping $line ];then
echo "$line is up"
else
echo "$line is not up"
fi
done
echo
Call upon multiple animation events on player
If i have a player and lets say a red ball hits my player and the player goes on fire...ok easy enough i did that but now i wanna add to the code below under the IF statement that a blue ball hits my player and freezes or a black ball and causes death animation...but its just not working out to add multiple animation events to 1 player. I just started coding 4 months ago so im green but thanks to all who read and helped.
public GameObject GoneGo;
void OnTriggerEnter2D(Collider2D collisionObject)
{
if (collisionObject.gameObject.tag == "Orb")
{
PlayGone();
}
}
void PlayGone()
{
GameObject gone = (GameObject)Instantiate(GoneGo);
gone.transform.position = transform.position;
}
}
Else if and Else in JavaScript
I wrote a small javascript code, but it has a problem, the page can not show anything. I think the problem is in the line "else if..." or "else...", because if I comment these two lines, the code runs without any problem
<html>
<head>
<script language="javascript">
var var1 = window.prompt("please input");
var var2 = window.prompt("please input2");
var1 = parseFloat(var1);
var2 = parseFloat(var2);
if (var1< var2) {document.writeln("the second number is bigger")};
else if (var1> var2) {document.writeln("the first number is bigger")};
else {document.writeln("They are the same")};
</script>
</head>
<body>
</body>
</html>
Call function with selected parameter without using if...else statements
This s a scenario I was given and I can't think of how to do it without using conditional statements. I'm writing it in jQuery, but plain JS is fine too.
<form>
<input type="radio" name="number" value="9" checked>9
<br>
<input type="radio" name="number" value="24">24
<br>
<input type="radio" name="number" value="57">57
<br>
<button>submit</button>
</form>
A user can make a selection which will result in a function call where the single parameter is one of: 9, 24 or 57. Based on the user input the following instructions must be performed:
If the parameter is 9 then the following methods must be performed(in order):
alert('9 way to go');
// some other code i want to happen
If the parameter is 24 then the following methods must be performed(in order):
alert('24 way to go');
// some other code i want to happen
If the parameter is 57 then the following methods must be performed(in order):
alert('57 way to go');
// some other code i want to happen
usually i'd wait for the click. upon the click, check the condition and depending which one it is, fire the correct method. i feel like this is a trick question, but i'm sure i could be 100% wrong too. Any ideas how to do this without conditionals? I was thinking maybe a closure? I'm not super familiar with them though.