## guacamole LDAP creation

0 likes • Nov 18, 2022
Python

## More Python Posts

### hex to rgb

CodeCatch
0 likes • Nov 19, 2022
Python
```def hex_to_rgb(hex):  return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
hex_to_rgb('FFA501') # (255, 165, 1)```
`""" Binary Search Algorithm ----------------------------------------"""#iterative implementation of binary search in Pythondef binary_search(a_list, item):    """Performs iterative binary search to find the position of an integer in a given, sorted, list.    a_list -- sorted list of integers    item -- integer you are searching for the position of    """    first = 0    last = len(a_list) - 1    while first <= last:        i = (first + last) / 2        if a_list[i] == item:            return ' found at position '.format(item=item, i=i)        elif a_list[i] > item:            last = i - 1        elif a_list[i] < item:            first = i + 1        else:            return ' not found in the list'.format(item=item)#recursive implementation of binary search in Pythondef binary_search_recursive(a_list, item):    """Performs recursive binary search of an integer in a given, sorted, list.    a_list -- sorted list of integers    item -- integer you are searching for the position of    """    first = 0    last = len(a_list) - 1    if len(a_list) == 0:        return ' was not found in the list'.format(item=item)    else:        i = (first + last) // 2        if item == a_list[i]:            return ' found'.format(item=item)        else:            if a_list[i] < item:                return binary_search_recursive(a_list[i+1:], item)            else:                return binary_search_recursive(a_list[:i], item)`
`bytes_data = b'Hello, World!'string_data = bytes_data.decode('utf-8')print("String:", string_data)`
`#You are given a two-digit integer n. Return the sum of its digits.#Example#For n = 29 the output should be solution (n) = 11def solution(n):    return (n//10 + n%10)`
```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['sAMAccountName']).replace("[b'", "").replace("']","")    return sAMAccountName```
`import copybegining = [False,False,False,False,False,None,True,True,True,True,True]#False = black True = whiteits = def swap(layout, step):    layoutCopy = copy.deepcopy(layout)    layoutCopy[(step+step)], layoutCopy[step] = layoutCopy[step], layoutCopy[(step+step)]    return layoutCopydef isSolved(layout):    for i in range(len(layout)):        if(layout[i] == False):            return (i >= (len(layout)/2))def recurse(layout, its, steps = []):    if isSolved(layout):        its += 1        print(layout,list(x for x in steps))        return    step = None    for i in range(len(layout)):        if(layout[i] == None):            if(i >= 1): #If the empty space could have something to the left                if(layout[i - 1] == False):                    step = [-1,i]                    recurse(swap(layout,step), its, (steps+[step]))                if(i > 1): #If the empty space could have something 2 to the left                    if(layout[i - 2] == False):                        step = [-2,i]                        recurse(swap(layout,step), its, (steps+[step]))            if(i < (len(layout)-1)): #If the empty space could have something to the right                if(layout[i + 1] == True):                    step = [1,i]                    recurse(swap(layout,step), its, (steps+[step]))                if(i < (len(layout)-2)): #If the empty space could have something to the right                    if(layout[i + 2] == True):                        step = [2,i]                        recurse(swap(layout,step), its, (steps+[step]))    its += 1    #return Nonerecurse(begining,its,[])print(its)`