How to generate random IP with groovy [duplicate] - groovy

This question already has answers here:
How can I use random numbers in groovy?
(6 answers)
Closed 5 years ago.
How to generate random IP with groovy :
I can generate a string, but can't figure out a fast way to IP.
org.apache.commons.lang.RandomStringUtils.random

If you just need random IP addresses, why not just something simple like:
def random = new Random()
(0..3).collect { random.nextInt(255) }.join('.')
You will end up with something like:
10.222.40.74

Related

difference between « Michael » and « michael » [duplicate]

This question already has answers here:
How do I do a case-insensitive string comparison?
(15 answers)
Closed 7 months ago.
I’m new with Python. Just One question.
I try to create a mini quizz game and i want avoid this :
Answer = Input(« « «  Who sing : « Thriller » ? » » »)
If answer == « Michael Jackson »:
Print(« Good. »)
Else:
Print(« Wrong. »)
The problem is that if the user answer «michael jackson », the code run with wrong.
How can i fixed that?
Thanks
The way that this is usually done is to just turn all the input to lowercase. This can be done with the .lower() method on the input string. The corrector answer would then be "michael jackson".

Python print like function for converting *args to a string [duplicate]

This question already has answers here:
Python convert tuple to string
(5 answers)
Closed 2 years ago.
I would like to know how to convert an unknown number of arguments to a string. what I need to do is redirect the output of a function that is supposed to go to print() to a Qt QPlainTextEdit. since it only accepts strings, I need a way to convert the given arguments to a string.
basically what I am looking for is print() but instead of outputting to the terminal, the output is to a string.
If you have an array of elements you can do:
def print_foo(arr,count):
for i in range(0,int(count)):
print(str(arr[i]))
Basically, converting to string is - newstr = str(varriable)

Replacing every 'a' for '&' [duplicate]

This question already has answers here:
How to use string.replace() in python 3.x
(9 answers)
Closed 5 years ago.
I am trying to write a program that replaces every 'a' for '&'.I am currently stumped and was wondering if someone could write it for me to get an idea of what it would look like. Thanks.
strw = "kabhi kabhi mery dil main khyaal aata hy"
print (strw.replace("a", "&"))

Remove tweets with less than 3 retweets with Greasemonkey [duplicate]

This question already has an answer here:
How to convert a jQuery filter for use with waitForKeyElements?
(1 answer)
Closed 7 years ago.
So far i have this code:
$('.js-stream-item:has(span.ProfileTweet-action--retweet:has(span.ProfileTweet-actionCount[data-tweet-stat-count="0"]))').toggle();
It works fine but only remove tweets with 0 retweets, how can i use the attribute "data-tweet-stat-count" by condition ?
Thanks in advance.
I think you could do something like this:
$('div.stream-item-footer:has(span.action-retweet:has(span.actionCount))').filter(function() {
return parseInt($(this).find('span.actionCount').attr('data-tweet-stat-count')) >= 3;
}).toggle();

Split string in Lua, save in 2 variables [duplicate]

This question already has answers here:
Split string in Lua?
(18 answers)
Closed 9 years ago.
I have one string, that is = s = "Pedro Martinez, Defense"
I want to split the string before the comma and after the comma, store those cuts on 2 variables, for example:
I think that I need to use the string.gmatch function or string.sub
How can I do that?
The accepted answer at How to convert GPS coordinates to decimal in Lua? shows how to use string.match and patterns. Applying the same techniques as mentioned there, you could use
local name, expertise = string.match(s, "(.*),%s*(%a*)")
which would lead to name being "Pedro Martinez" and expertise being "Defense".

Resources