Skip to main content

radians to degrees

0 likes • Nov 19, 2022 • 0 views
Python
Loading...

More Python Posts

Dictionary Sort

0 likes • Nov 18, 2022 • 0 views
Python
mydict = {'carl':40, 'alan':2, 'bob':1, 'danny':0}
# How to sort a dict by value Python 3>
sort = {key:value for key, value in sorted(mydict.items(), key=lambda kv: (kv[1], kv[0]))}
print(sort)
# How to sort a dict by key Python 3>
sort = {key:mydict[key] for key in sorted(mydict.keys())}
print(sort)

Hello World

0 likes • Sep 9, 2023 • 11 views
Python
print("test")

CSCE 2100 Question 3

0 likes • Nov 18, 2022 • 3 views
Python
# question3.py
from itertools import product
V='∀'
E='∃'
def tt(f,n) :
xss=product((0,1),repeat=n)
print('function:',f.__name__)
for xs in xss : print(*xs,':',int(f(*xs)))
print('')
# this is the logic for part A (p\/q\/r) /\ (p\/q\/~r) /\ (p\/~q\/r) /\ (p\/~q\/~r) /\ (~p\/q\/r) /\ (~p\/q\/~r) /\ (~p\/~q\/r) /\ (~p\/~q\/~r)
def parta(p,q,r) :
a=(p or q or r) and (p or q or not r) and (p or not q or r)and (p or not q or not r)
b=(not p or q or r ) and (not p or q or not r) and (not p or not q or r) and (not p or not q or not r)
c= a and b
return c
def partb(p,q,r) :
a=(p or q and r) and (p or not q or not r) and (p or not q or not r)and (p or q or not r)
b=(not p or q or r ) and (not p or q or not r) and (not p or not q or r) and (not p or not q or not r)
c= a and b
return c
print("part A:")
tt(parta,3)
print("part B:")
tt(partb,3)

Append to a file

0 likes • Jun 1, 2023 • 0 views
Python
filename = "data.txt"
data = "Hello, World!"
with open(filename, "a") as file:
file.write(data)

Return Letter Combinations

0 likes • Nov 18, 2022 • 0 views
Python
# @return a list of strings, [s1, s2]
def letterCombinations(self, digits):
if '' == digits: return []
kvmaps = {
'2': 'abc',
'3': 'def',
'4': 'ghi',
'5': 'jkl',
'6': 'mno',
'7': 'pqrs',
'8': 'tuv',
'9': 'wxyz'
}
return reduce(lambda acc, digit: [x + y for x in acc for y in kvmaps[digit]], digits, [''])

guacamole LDAP creation

0 likes • Nov 18, 2022 • 0 views
Python
import os
import sys
import argparse
import json
import csv
import getpass
import string
import random
import re
from datetime import datetime
import ldap
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
from requests.auth import HTTPBasicAuth
import validators
def create_guac_connection(BASE_URL, auth_token, ldap_group, computer, guac_group_id):
'''
creates a guac connection
'''
json_header = {'Accept': 'application/json'}
query_parm_payload = { 'token': auth_token }
payload_data = {
"parentIdentifier":guac_group_id,
"name":computer,
"protocol":"vnc",
"parameters":{
"port":"5900",
"read-only":"",
"swap-red-blue":"",
"cursor":"",
"color-depth":"",
"clipboard-encoding":"",
"disable-copy":"",
"disable-paste":"",
"dest-port":"",
"recording-exclude-output":"",
"recording-exclude-mouse":"",
"recording-include-keys":"",
"create-recording-path":"",
"enable-sftp":"true",
"sftp-port":"",
"sftp-server-alive-interval":"",
"enable-audio":"",
"audio-servername":"",
"sftp-directory":"",
"sftp-root-directory":"",
"sftp-passphrase":"",
"sftp-private-key":"",
"sftp-username":"",
"sftp-password":"",
"sftp-host-key":"",
"sftp-hostname":"",
"recording-name":"",
"recording-path":"",
"dest-host":"",
"password":"asdasd",
"username":"asdasd",
"hostname":"nt72310.cvad.unt.edu"
},
"attributes":{
"max-connections":"",
"max-connections-per-user":"1",
"weight":"",
"failover-only":"",
"guacd-port":"",
"guacd-encryption":"",
"guacd-hostname":""
}
}
CREATE_CONNECTION_URL = BASE_URL + "/api/session/data/mysql/connections"
create_connection_request = requests.post(CREATE_CONNECTION_URL, headers=json_header, params=query_parm_payload, data=payload_data, verify=False)
create_connection_result = create_connection_request.status_code
if create_connection_result == "200":
print("Successfully created computer: " + computer)
else:
print(create_connection_request.json())
return create_connection_result