This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net" | |
) | |
func main() { | |
for i := 1; i <= 1024; i++ { | |
address := fmt.Sprintf("scanme.nmap.org:%d", i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net" | |
"sort" | |
) | |
func worker(ports, results chan int) { | |
for p := range ports { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def translate_animal_names( | |
animals: List[str], | |
translations: Dict[str, str] | |
) -> List[str]: | |
translated_animal_names = [] | |
for animal in animals: | |
if animal in translations: | |
translated_animal_names.append(translations[animal]) | |
else: | |
logging.warning( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_translate_animal_names(caplog): | |
animals_in_french = ["lapin", "grenouille", "cheval"] | |
french_english_translation = { | |
"lapin": "rabbit", | |
"cheval": "horse" | |
} | |
animals_in_english = translate_animal_names( | |
animals_in_french, | |
french_english_translation | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InvalidEmailAddressError(Exception): | |
pass | |
def validate_email_address(ctx, param, value): | |
regex = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" | |
if not re.search(regex, value): | |
raise InvalidEmailAddressError(f"Invalid email address: {value}") | |
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_email_validation(): | |
with pytest.raises(InvalidEmailAddressError): | |
assert validate_email_address(None, None, "invalid.com") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_time_since_subscription(subscription_date: datetime.datetime) -> int: | |
current_date = datetime.datetime.utcnow() | |
return (current_date - subscription_date).days |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@pytest.mark.freeze_time("2020-01-15 13:00:00") | |
def test_get_time_since_subscription(): | |
test_subscribtion_date = datetime.datetime(2020, 1, 10, 12) | |
assert get_time_since_subscription(test_subscribtion_date) == 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_valid_email_address(email: str) -> bool: | |
regex = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" | |
return re.search(regex, email) is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@pytest.mark.parametrize( | |
"test_input, expected", | |
[ | |
("correct@gmail.com", True), | |
("another.correct@custom.fr", True), | |
("and-another@custom.org", True), | |
("inavlid.com", False), | |
("veryb@d@.com", False), | |
("domain@too.long", False) | |
] |
OlderNewer