Skip to content

Instantly share code, notes, and snippets.

@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
@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 / TestCatchException.py
Created December 13, 2018 14:18
How to catch an OSError for invalid directory path or file in UnitTest in Python 3.x
def testValidatePathFile(self):
with self.assertRaises(OSError) as cm:
# self.handle.__ValidatePathFile()
self.handle = exceptman.ExceptionListManager(path="/tm")
err = cm.exception
self.assertEqual(str(err), "[Errno 2] No such file or directory: '/tm'")
@Bas-Man
Bas-Man / plexDatabaseBackupScript.sh
Last active March 26, 2021 23:38 — forked from shnhrrsn/plexDatabaseBackupScript.sh
Plex Media Server database backup script of Mac OS
#!/usr/bin/env bash
# Backup a Plex database.
# Author Scott Smereka
# Ubuntu
# Version 1.0
# Modified by Shaun Harrison
# Ubuntu
# Version 1.1
@Bas-Man
Bas-Man / startAfterMount.scpt
Created January 17, 2019 01:52
AppleScript to launch applications only after external drive has been mounted.
set diskIsMounted to false
repeat until diskIsMounted is true
delay 30
tell application "Finder"
if (disk "Drobo" exists) then
set diskIsMounted to true
end if
end tell
end repeat
@Bas-Man
Bas-Man / ShutDownServer.scpt
Created January 22, 2019 12:45
Mac Shutdown AppleScript
# Current under Dev
#Drobo Dashboard does not appear to respond to quit command.
# Drobo is the name of the drive to be unmounted. This should be changed to
# your own needs.
tell application "NordVPN" to quit
tell application "Plex Media Server" to quit
tell application "Dropbox" to quit
tell application "Drobo Dashboard" to quit
@Bas-Man
Bas-Man / GetAllModules.txt
Last active February 6, 2019 13:03
Find all modules used in a Perl program
perl -MDevel::Modlist=options program.pl
@Bas-Man
Bas-Man / sleepwatcher.md
Created February 11, 2019 08:29
Run script on Mac OS on wake from lan event

Referenced from https://www.bernhard-baehr.de

use de.bernhard-baehr.sleepwatcher-20compatibility-localuser.plist from config folder follow instructions. Remember to chmod required files including the .wakeup in home directory.

@Bas-Man
Bas-Man / JSONWithComplexPythonObjects.md
Last active May 11, 2020 11:33
return json string for complex python objects

Link found here

example usage in my case

def json():
  return json.dumps(self.__dict__,default=lambda o: o.__dict__,
                    ensure_ascii=False,indent=4)
@Bas-Man
Bas-Man / mock_sys.version_info.py
Created April 22, 2020 13:31
One method of mocking the values for sys.version_info.major/minor
def test_python2TooLow():
with mock.patch.object(sys, 'version_info') as v_info:
v_info.major = 2
v_info.minor = 7
assert helper.system.meetsMinSpecs(3, 0) == False