• Nov 19, 2022 •CodeCatch
0 likes • 2 views
def byte_size(s): return len(s.encode('utf-8')) byte_size('😀') # 4 byte_size('Hello World') # 11
• Nov 18, 2022 •AustinLeath
0 likes • 0 views
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 control bindDN = 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 = 3 conn.set_option(ldap.OPT_REFERRALS, 0) #authenticate the connection so that you can make additional queries try: result = conn.simple_bind_s(bindDN, bindPass) except ldap.INVALID_CREDENTIALS: result = "Invalid credentials for %s" % user sys.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
0 likes • 3 views
# Input for row and column R = int(input()) C = int(input()) # Using list comprehension for input matrix = [[int(input()) for x in range (C)] for y in range(R)]
0 likes • 1 view
def check_prop(fn, prop): return lambda obj: fn(obj[prop]) check_age = check_prop(lambda x: x >= 18, 'age') user = {'name': 'Mark', 'age': 18} check_age(user) # True
• Mar 10, 2021 •Skrome
color2 = (60, 74, 172) color1 = (19, 28, 87) percent = 1.0 for i in range(101): resultRed = round(color1[0] + percent * (color2[0] - color1[0])) resultGreen = round(color1[1] + percent * (color2[1] - color1[1])) resultBlue = round(color1[2] + percent * (color2[2] - color1[2])) print((resultRed, resultGreen, resultBlue)) percent -= 0.01
• Jul 24, 2024 •AustinLeath
from statistics import median, mean, mode def print_stats(array): print(array) print("median =", median(array)) print("mean =", mean(array)) print("mode =", mode(array)) print() print_stats([1, 2, 3, 3, 4]) print_stats([1, 2, 3, 3])