Loading...
More Python Posts
import stringdef caesar(text, shift, alphabets):def shift_alphabet(alphabet):return alphabet[shift:] + alphabet[:shift]shifted_alphabets = tuple(map(shift_alphabet, alphabets))final_alphabet = "".join(alphabets)final_shifted_alphabet = "".join(shifted_alphabets)table = str.maketrans(final_alphabet, final_shifted_alphabet)return text.translate(table)plain_text = "Hey Skrome, welcome to CodeCatch"print(caesar(plain_text, 8, [string.ascii_lowercase, string.ascii_uppercase, string.punctuation]))
# Prompt user for a decimal numberdecimal = int(input("Enter a decimal number: "))# Convert decimal to binarybinary = bin(decimal)# Convert decimal to hexadecimalhexadecimal = hex(decimal)# Display the resultsprint("Binary:", binary)print("Hexadecimal:", hexadecimal)
#84 48 13 20 61 20 33 97 34 45 6 63 71 66 24 57 92 74 6 25 51 86 48 15 64 55 77 30 56 53 37 99 9 59 57 61 30 97 50 63 59 62 39 32 34 4 96 51 8 86 10 62 16 55 81 88 71 25 27 78 79 88 92 50 16 8 67 82 67 37 84 3 33 4 78 98 39 64 98 94 24 82 45 3 53 74 96 9 10 94 13 79 15 27 56 66 32 81 77# xor a list of integers to find the lonely integerres = a[0]for i in range(1,len(a)):res = res ^ a[i]
import subprocess #for the praat callsimport os #for ffmpeg and the pause call at the end#Even if we wanted all videos being rendered asynchronously, we couldn't see progress or errorsimport glob #for the ambiguous filesimport tempfileaudioFileDirectory = 'Audio Files'timeList = {}fileList = glob.glob(audioFileDirectory + '\\*.wav')pipeList = {}for fileName in fileList:arglist = ['Praat.exe', '--run', 'crosscorrelateMatch.praat', 'zeussound.wav', fileName, "0" , "300"]print(' '.join(arglist))pipe = subprocess.Popen(arglist, stdout=subprocess.PIPE)pipeList[fileName[len(audioFileDirectory)+1:-4]] = pipe #+1 because of back slash, -4 because .wav#for fileName, pipe in pipeList.items():# text = pipe.communicate()[0].decode('utf-8')# timeList[fileName] = float(text[::2])for fileName, pipe in pipeList.items():if float(pipe.communicate()[0].decode('utf-8')[::2]) > .0003: #.000166 is not a match, and .00073 is a perfect match. .00053 is a tested matcharglist = ['Praat.exe', '--run', 'crosscorrelate.praat', 'zeussound.wav', audioFileDirectory + '\\' + fileName + '.wav', "0" , "300"]print(' '.join(arglist))text = subprocess.Popen(arglist, stdout=subprocess.PIPE).communicate()[0].decode('utf-8')timeList[fileName] = float(text[::2])clipLength = 10for fileName, time in timeList.items():arglist = ['ffmpeg', '-i', '"'+fileName+'.mp4"', '-ss', str(time-clipLength), '-t', str(clipLength*2), '-acodec', 'copy' , '-vcodec', 'copy', '"ZEUS'+ fileName + '.mp4"']print(' '.join(arglist))os.system(' '.join(arglist))tempFile = tempfile.NamedTemporaryFile(delete=False)for fileName in glob.glob('ZEUS*.mp4'):tempFile.write(("file '" + os.path.realpath(fileName) + "'\n").encode());tempFile.seek(0)print(tempFile.read())tempFile.close()arglist = ['ffmpeg', '-safe', '0', '-f', 'concat', '-i', '"'+tempFile.name+'"', '-c', 'copy', 'ZeusMontage.mp4']print(' '.join(arglist))os.system(' '.join(arglist))os.unlink(tempFile.name) #Delete the temp file#print(timeList)os.system('PAUSE')
def get_ldap_user(member_cn, user, passwrd):'''Get an LDAP user and return the SAMAccountName'''#---- Setting up the Connection#account used for binding - Avoid putting these in version controlbindDN = str(user) + "@unt.ad.unt.edu"bindPass = passwrd#set some tuneables for the LDAP library.ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_ALLOW)#ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, CACERTFILE)conn = ldap.initialize('ldaps://unt.ad.unt.edu')conn.protocol_version = 3conn.set_option(ldap.OPT_REFERRALS, 0)#authenticate the connection so that you can make additional queriestry:result = conn.simple_bind_s(bindDN, bindPass)except ldap.INVALID_CREDENTIALS:result = "Invalid credentials for %s" % usersys.exit()#build query in the form of (uid=user)ldap_query = '(|(displayName=' + member_cn + ')(cn='+ member_cn + ')(name=' + member_cn + '))'ldap_info = conn.search_s('DC=unt,DC=ad,DC=unt,DC=edu', ldap.SCOPE_SUBTREE, filterstr=ldap_query)sAMAccountName = str(ldap_info[0][1]['sAMAccountName']).replace("[b'", "").replace("']","")return sAMAccountName
def generate_floyds_triangle(num_rows):triangle = []number = 1for row in range(num_rows):current_row = []for _ in range(row + 1):current_row.append(number)number += 1triangle.append(current_row)return triangledef display_floyds_triangle(triangle):for row in triangle:for number in row:print(number, end=" ")print()# Prompt the user for the number of rowsnum_rows = int(input("Enter the number of rows for Floyd's Triangle: "))# Generate Floyd's Trianglefloyds_triangle = generate_floyds_triangle(num_rows)# Display Floyd's Triangledisplay_floyds_triangle(floyds_triangle)