Skip to content

Instantly share code, notes, and snippets.

@Bas-Man
Bas-Man / RaiseOSError.py
Last active December 12, 2018 14:08
Python raise OSError for missing file or invalid path
if not os.path.exists(self.path):
raise OSError(
errno.ENOENT, os.strerror(errno.ENOENT), self.path
)
if not os.path.isfile(self.path + self.file):
raise OSError(
errno.ENOENT, os.strerror(errno.ENOENT), self.file
)
@Bas-Man
Bas-Man / asciiVowelCount.pl
Created October 21, 2018 13:05
Quick subroutine to return the number of vowels in a string. returns -1 if the string is not an ascii string.
sub asciiVowelCount {
my $str = shift;
# return error since this is not ascii character set
return -1 if $str =~ /[^[:ascii:]]/;
my $count = 0;
# Loop over each chracter in $str and increment counter if it is a vowel