Estou tentando colocar uma mascara para o rg, para permitir o X no final por exemplo: 20.656.233-X em PHP e nao estou conseguindo

function FormataRG($rg)
{
$result = $rg;
$rg = LIMPANUMERO($rg);
//
if (strlen($rg)==11)
{
$result=substr($rg,2,2).’.’.
substr($rg,4,3).’.’.
substr($rg,7,3).’-‘.
substr($rg,10,1)or(str_replace($rg,1,’X’,));
}
}

python – Cisco equipment troubleshooter tool

I am a network engineer and started playing with Python as a way to supplement some downtime in the job. We have no automation at the company so I was playing around with making a GUI to run simple commands to our equipment and give the output in a separate window. The main window (root) stays active the whole time so that you can change the connected device, credentials, IP, etc which makes it “faster” to scout issues.

I never took any Python classes and each part of the code was picked up on the fly from different sources, but I picked up enough to figure out what I needed.

I don’t really have a problem with the code other than scrollbars not working, but I know why so not a problem at the moment.

Since I have nobody on my team that can tell me if this code is good or bad I was curious to see if someone could just look at the code and tell me what they think.

#Imported packages. You may need to run "pip install <package>" where <package> is the package listed below. If you are
#unsure how to install Python packages then try looking at instructions here:
# https://packaging.python.org/tutorials/installing-packages/#
from netmiko import (
    ConnectHandler,
    NetmikoTimeoutException,
    NetmikoAuthenticationException,
)
from getpass import getpass
from tkinter import *

#Sets up the main window#
root = Tk()
root.title("Cisco Troubleshooter")
root.configure(background="black")
root.iconbitmap('cisco.ico')

def on_device_click(event):
    """function that gets called whenever entry is clicked"""
    if device.get() == "Enter the IP/Hostname you want to connect to":
        device.delete(0, "end")  # delete all the text in the entry
        device.insert(0, '')  # Insert blank for user input
        device.config(fg='black')


#Displays red text if the box is clicked on, not filled out, then exited#
def on_device_focusout(event):
    if device.get() == '':
        device.insert(0, "Enter the IP/Hostname you want to connect to")
        device.config(fg="red")


def on_UN_click(event):
    if UN.get() == "Enter your username":
        UN.delete(0, "end")  # delete all the text in the entry
        UN.insert(0, '')  # Insert blank for user input
        UN.config(fg='black')


#Displays red text if the box is clicked on, not filled out, then exited#
def on_UN_focusout(event):
    if UN.get() == '':
        UN.insert(0, "Enter your username")
        UN.config(fg="red")


def on_PW_click(event):
    if PW.get() == "*":
        PW.delete(0, "end")  # delete all the text in the entry
        PW.insert(0, '')  # Insert blank for user input
        PW.config(fg='black')

    elif PW.get() == "Enter your password":
        PW.delete(0, "end")  # delete all the text in the entry
        PW.insert(0, '')  # Insert blank for user input
        PW.config(fg='black')


#Displays red text if the box is clicked on, not filled out, then exited#
def on_PW_focusout(event):
    if PW.get() == '':
        PW.insert(0, "Enter your password")
        PW.config(fg="red")

def on_IP_click(event):
    if IP.get() == "Enter IP for commands":
        IP.delete(0, "end")  # delete all the text in the entry
        IP.insert(0, '')  # Insert blank for user input
        IP.config(fg='black')


#Displays red text if the box is clicked on, not filled out, then exited#
def on_IP_focusout(event):
    if IP.get() == '':
        IP.insert(0, "Enter IP for commands")
        IP.config(fg="green")

def on_INT_click(event):
    if INT.get() == "Enter Int/MAC/VLAN for commands":
        INT.delete(0, "end")  # delete all the text in the entry
        INT.insert(0, '')  # Insert blank for user input
        INT.config(fg='black')


#Displays red text if the box is clicked on, not filled out, then exited#
def on_INT_focusout(event):
    if INT.get() == '':
        INT.insert(0, "Enter Int/MAC/VLAN for commands")
        INT.config(fg="green")


#Sets up the "show active calls" button payload#
def active_click():
    try:
        # Sets up the SSH payload#
        cisco_payload = {
            "device_type": "cisco_ios",
            "host": device.get(),
            "username": UN.get(),
            "password": PW.get(),
            "port": 22,
        }

        # Sets the SSH payload to a variable to be used for running commands#
        ssh = ConnectHandler(**cisco_payload)

        # Commands section for this button#
        active = (ssh.send_command("sh call active voice comp"))

        # Binds the commands being run into a variable so that they can be printed neatly#
        results = (active)

        # Prints the output in the Python window for QA purposes#
        print(active)

        # Disconnects from the SSH session#
        ssh.disconnect()

        # Sets up the new window once the button is clicked#
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        # Creates the scrollbar#
        scroll = Scrollbar(output, orient=VERTICAL)
        scroll.grid(row=0, column=1, sticky="nsew")

        # Creates the section in the new window where the text will be printed then prints it#
        label = Label(output, text=results, relief=SUNKEN,  bg="black", fg="light green", justify=LEFT)
        label.grid(row=0, column=0, sticky=NS)

    # Handles error exceptions and prints out the error#
    except(KeyError, KeyboardInterrupt, IndexError, NetmikoTimeoutException, NetmikoAuthenticationException) as error:
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        label = Label(output, text=error, relief=SUNKEN, bg="black", fg="light green")
        label.grid(row=0, column=0, sticky=NSEW)


#Sets up the "show bgp summary" button payload#
def bgpsumm_click():
    try:
        # Sets up the SSH payload#
        cisco_payload = {
            "device_type": "cisco_ios",
            "host": device.get(),
            "username": UN.get(),
            "password": PW.get(),
            "port": 22,
        }

        # Sets the SSH payload to a variable to be used for running commands#
        ssh = ConnectHandler(**cisco_payload)

        # Commands section for this button#
        bgpsumm = (ssh.send_command("sh bgp summ | beg Neigh"))

        # Binds the commands being run into a variable so that they can be printed neatly#
        results = (bgpsumm)

        # Prints the output in the Python window for QA purposes#
        print(bgpsumm)

        # Disconnects from the SSH session#
        ssh.disconnect()

        # Sets up the new window once the button is clicked#
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        # Creates the scrollbar#
        scroll = Scrollbar(output, orient=VERTICAL)
        scroll.grid(row=0, column=1, sticky="nsew")

        # Creates the section in the new window where the text will be printed then prints it#
        label = Label(output, text=results, relief=SUNKEN,  bg="black", fg="light green", justify=LEFT)
        label.grid(row=0, column=0, sticky="nsew")

    #Handles error exceptions and prints out the error#
    except(KeyError, KeyboardInterrupt, IndexError, NetmikoTimeoutException, NetmikoAuthenticationException) as error:
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        label = Label(output, text=error, relief=SUNKEN, bg="black", fg="light green")
        label.grid(row=0, column=0, sticky="nsew")


#Sets up the "show cdp neighbors" button payload#
def  cdp_click():
    try:
        # Sets up the SSH payload#
        cisco_payload = {
            "device_type": "cisco_ios",
            "host": device.get(),
            "username": UN.get(),
            "password": PW.get(),
            "port": 22,
        }

        # Sets the SSH payload to a variable to be used for running commands#
        ssh = ConnectHandler(**cisco_payload)

        # Commands section for this button. Pulls any entries from the interface entry box#
        if INT.get() == "Enter interface for commands":
            cdp = (ssh.send_command("sh cdp neigh "))

        else:
            cd= ssh.send_command("sh cdp neigh " + INT.get())

        # Binds the commands being run into a variable so that they can be printed neatly#
        results = (cdp)

        # Prints the output in the Python window for QA purposes#
        print(cdp)

        # Disconnects from the SSH session#
        ssh.disconnect()

        # Sets up the new window once the button is clicked#
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        # Creates the scrollbar#
        scroll = Scrollbar(output, orient=VERTICAL)
        scroll.grid(row=0, column=1, sticky="nsew")

        # Creates the section in the new window where the text will be printed then prints it#
        label = Label(output, text=results, relief=SUNKEN,  bg="black", fg="#08bc08", justify=LEFT)
        label.grid(row=0, column=0)

    # Handles error exceptions and prints out the error#
    except(KeyError, KeyboardInterrupt, IndexError, NetmikoTimeoutException, NetmikoAuthenticationException) as error:
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        label = Label(output, text=error, relief=SUNKEN, bg="black", fg="light green")
        label.grid(row=0, column=0, sticky="nsew")


#Sets up the "show error-disabled" button payload#
def errdisable_click():
    try:
        # Sets up the SSH payload#
        cisco_payload = {
            "device_type": "cisco_ios",
            "host": device.get(),
            "username": UN.get(),
            "password": PW.get(),
            "port": 22,
        }

        # Sets the SSH payload to a variable to be used for running commands#
        ssh = ConnectHandler(**cisco_payload)

        # Commands section for this button#
        errdisabled = (ssh.send_command("sh int status | i err"))

        # Binds the commands being run into a variable so that they can be printed neatly#
        results = (errdisabled)

        # Prints the output in the Python window for QA purposes#
        print(errdisabled)

        # Disconnects from the SSH session#
        ssh.disconnect()

        # Sets up the new window once the button is clicked#
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        # Creates the scrollbar#
        scroll = Scrollbar(output, orient=VERTICAL)
        scroll.grid(row=0, column=1, sticky="nsew")

        # Creates the section in the new window where the text will be printed then prints it#
        label = Label(output, text=results, relief=SUNKEN,  bg="black", fg="light green", justify=LEFT)
        label.grid(row=0, column=0, sticky=NS)

    # Handles error exceptions and prints out the error#
    except(KeyError, KeyboardInterrupt, IndexError, NetmikoTimeoutException, NetmikoAuthenticationException) as error:
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        label = Label(output, text=error, relief=SUNKEN, bg="black", fg="light green")
        label.grid(row=0, column=0, sticky=NSEW)


#Sets up the "show interfaces" button payload#
def showint_click():

    try:
        #Sets up the SSH payload#
        cisco_payload = {
            "device_type": "cisco_ios",
            "host":device.get(),
            "username": UN.get(),
            "password": PW.get(),
            "port": 22,
        }

        #Sets the SSH payload to a variable to be used for running commands#
        ssh = ConnectHandler(**cisco_payload)

        #Commands section for this button#
        up = (ssh.send_command("sh ip int bri | i up"))
        down = (ssh.send_command("sh ip int bri | i down"))

        #Binds the commands being run into a variable so that they can be printed neatly#
        results= ("Up Interfacesnn" + up + "nnDown Interfacesnn" + down + "n")

        #Prints the output in the Python window for QA purposes#
        print("Up Interfacesnn" + up + "nnDown Interfacesnn" + down + "n")

        #Disconnects from the SSH session#
        ssh.disconnect()

        #Sets up the new window once the button is clicked#
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        #Creates the scrollbar#
        scroll = Scrollbar(output, orient=VERTICAL)
        scroll.grid(row=0, column=1, sticky="nsew")

        # Creates the section in the new window where the text will be printed then prints it#
        label = Label(output, text=results, relief=SUNKEN, bg="black", fg="light green", justify=LEFT)
        label.grid(row=0, column=0, sticky=NS)

    #Handles error exceptions and prints out the error#
    except(KeyError, KeyboardInterrupt, IndexError, NetmikoTimeoutException, NetmikoAuthenticationException) as error:
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        label = Label(output, text=error, relief=SUNKEN)
        label.grid(row=0, column=0, sticky=NSEW)


def iparp_click():

    try:
        #Sets up the SSH payload#
        cisco_payload = {
            "device_type": "cisco_ios",
            "host":device.get(),
            "username": UN.get(),
            "password": PW.get(),
            "port": 22,
        }

        #Sets the SSH payload to a variable to be used for running commands#
        ssh = ConnectHandler(**cisco_payload)

        #Commands section for this button#
        if IP.get() == "Enter IP for commands":
            iparp = (ssh.send_command("sh ip arp "))

        else:
            iparp = (ssh.send_command("sh ip arp " + IP.get()))

        #Binds the commands being run into a variable so that they can be printed neatly#
        results= (iparp)

        #Prints the output in the Python window for QA purposes#
        print(iparp)

        #Disconnects from the SSH session#
        ssh.disconnect()

        #Sets up the new window once the button is clicked#
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        #Creates the scrollbar#
        scroll = Scrollbar(output, orient=VERTICAL)
        scroll.grid(row=0, column=1, sticky="nsew")

        # Creates the section in the new window where the text will be printed then prints it#
        label = Label(output, text=results, relief=SUNKEN, bg="black", fg="light green", justify=LEFT)
        label.grid(row=0, column=0, sticky=NS)

    #Handles error exceptions and prints out the error#
    except(KeyError, KeyboardInterrupt, IndexError, NetmikoTimeoutException, NetmikoAuthenticationException) as error:
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        label = Label(output, text=error, relief=SUNKEN)
        label.grid(row=0, column=0, sticky=NSEW)


#Sets up the "show isdn status" button payload#
def isdn_click():
    try:
        # Sets up the SSH payload#
        cisco_payload = {
            "device_type": "cisco_ios",
            "host":device.get(),
            "username": UN.get(),
            "password": PW.get(),
            "port": 22,
        }

        # Sets the SSH payload to a variable to be used for running commands#
        ssh = ConnectHandler(**cisco_payload)

        # Commands section for this button#
        isdn = (ssh.send_command("sh isdn status"))

        # Binds the commands being run into a variable so that they can be printed neatly#
        results = (isdn)

        # Prints the output in the Python window for QA purposes#
        print(isdn)

        # Disconnects from the SSH session#
        ssh.disconnect()

        # Sets up the new window once the button is clicked#
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        # Creates the scrollbar#
        scroll = Scrollbar(output, orient=VERTICAL)
        scroll.grid(row=0, column=1, sticky="nsew")

        # Creates the section in the new window where the text will be printed then prints it#
        label = Label(output, text=results, relief=SUNKEN,  bg="black", fg="light green", justify=LEFT)
        label.grid(row=0, column=0, sticky=NS)

    #Handles error exceptions and prints out the error#
    except(KeyError, KeyboardInterrupt, IndexError, NetmikoTimeoutException, NetmikoAuthenticationException) as error:
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        label = Label(output, text=error, relief=SUNKEN, bg="black", fg="light green")
        label.grid(row=0, column=0, sticky="nsew")


#Sets up the "show mac address" button payload#
def mac_click():
    try:
        # Sets up the SSH payload#
        cisco_payload = {
            "device_type": "cisco_ios",
            "host": device.get(),
            "username": UN.get(),
            "password": PW.get(),
            "port": 22,
        }

        # Sets the SSH payload to a variable to be used for running commands#
        ssh = ConnectHandler(**cisco_payload)

        # Commands section for this button#
        if INT.get() == "Enter Int/MAC/VLAN for commands":
            mac = (ssh.send_command("show mac address-table"))

        else:
            mac = ssh.send_command("show mac address-table address " + INT.get())

        # Binds the commands being run into a variable so that they can be printed neatly#
        results = (mac)

        # Prints the output in the Python window for QA purposes#
        print(results)

        # Disconnects from the SSH session#
        ssh.disconnect()

        # Sets up the new window once the button is clicked#
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        # Creates the scrollbar#
        scroll = Scrollbar(output, orient=VERTICAL)
        scroll.grid(row=0, column=1, sticky="nsew")

        # Creates the section in the new window where the text will be printed then prints it#
        label = Label(output, text=results, relief=SUNKEN, bg="black", fg="#08bc08", justify=LEFT)
        label.grid(row=0, column=0)

    # Handles error exceptions and prints out the error#
    except(KeyError, KeyboardInterrupt, IndexError, NetmikoTimeoutException, NetmikoAuthenticationException) as error:
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        label = Label(output, text=error, relief=SUNKEN, bg="black", fg="light green")
        label.grid(row=0, column=0, sticky="nsew")


#Sets up the "show temperature" button payload#
def temp_click():
    try:
        # Sets up the SSH payload#
        cisco_payload = {
            "device_type": "cisco_ios",
            "host": device.get(),
            "username": UN.get(),
            "password": PW.get(),
            "port": 22,
        }

        # Sets the SSH payload to a variable to be used for running commands#
        ssh = ConnectHandler(**cisco_payload)

        # Commands section for this button#
        temp = (ssh.send_command("sh envi temp"))

        # Binds the commands being run into a variable so that they can be printed neatly#
        results = (temp)

        # Prints the output in the Python window for QA purposes#
        print(temp)

        # Disconnects from the SSH session#
        ssh.disconnect()

        # Sets up the new window once the button is clicked#
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        # Creates the scrollbar#
        scroll = Scrollbar(output, orient=VERTICAL)
        scroll.grid(row=0, column=1, sticky="ns")

        # Creates the section in the new window where the text will be printed then prints it#
        label = Label(output, text=results, relief=SUNKEN,  bg="black", fg="#08bc08", justify=LEFT)
        label.grid(row=0, column=0)

    # Handles error exceptions and prints out the error#
    except(KeyError, KeyboardInterrupt, IndexError, NetmikoTimeoutException, NetmikoAuthenticationException) as error:
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        label = Label(output, text=error, relief=SUNKEN, bg="black", fg="light green")
        label.grid(row=0, column=0, sticky="nsew")


#Sets up the "show uptime" button payload#
def uptime_click():
    try:
        # Sets up the SSH payload#
        cisco_payload = {
            "device_type": "cisco_ios",
            "host": device.get(),
            "username": UN.get(),
            "password": PW.get(),
            "port": 22,
        }

        # Sets the SSH payload to a variable to be used for running commands#
        ssh = ConnectHandler(**cisco_payload)

        # Commands section for this button#
        uptime = (ssh.send_command("sh ver | i uptime"))

        # Binds the commands being run into a variable so that they can be printed neatly#
        results = (uptime)

        # Prints the output in the Python window for QA purposes#
        print(uptime)

        # Disconnects from the SSH session#
        ssh.disconnect()

        # Sets up the new window once the button is clicked#
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        # Creates the scrollbar#
        scroll = Scrollbar(output, orient=VERTICAL)
        scroll.grid(row=0, column=1, sticky="ns")

        # Creates the section in the new window where the text will be printed then prints it#
        label = Label(output, text=results, relief=SUNKEN,  bg="black", fg="#08bc08", justify=LEFT)
        label.grid(row=0, column=0)

    # Handles error exceptions and prints out the error#
    except(KeyError, KeyboardInterrupt, IndexError, NetmikoTimeoutException, NetmikoAuthenticationException) as error:
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        label = Label(output, text=error, relief=SUNKEN, bg="black", fg="light green")
        label.grid(row=0, column=0, sticky="nsew")


#Sets up the "show vlan" button payload#
def vlan_click():
    try:
        # Sets up the SSH payload#
        cisco_payload = {
            "device_type": "cisco_ios",
            "host": device.get(),
            "username": UN.get(),
            "password": PW.get(),
            "port": 22,
        }

        # Sets the SSH payload to a variable to be used for running commands#
        ssh = ConnectHandler(**cisco_payload)

        # Commands section for this button#
        vlan = (ssh.send_command("sh vlan"))

        # Binds the commands being run into a variable so that they can be printed neatly#
        results = (vlan)

        # Prints the output in the Python window for QA purposes#
        print(vlan)

        # Disconnects from the SSH session#
        ssh.disconnect()

        # Sets up the new window once the button is clicked#
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        # Creates the scrollbar#
        scroll = Scrollbar(output, orient=VERTICAL)
        scroll.grid(row=0, column=1, sticky="nsew")

        # Creates the section in the new window where the text will be printed then prints it#
        label = Label(output, text=results, relief=SUNKEN, bg="black", fg="#08bc08", justify=LEFT)
        label.grid(row=0, column=0)

    # Handles error exceptions and prints out the error#
    except(KeyError, KeyboardInterrupt, IndexError, NetmikoTimeoutException, NetmikoAuthenticationException) as error:
        output = Toplevel(root)
        output.title("Output Window")
        output.iconbitmap('cisco.ico')

        label = Label(output, text=error, relief=SUNKEN, bg="black", fg="light green")
        label.grid(row=0, column=0, sticky="nsew")


#Sets up the command to exit the program on button click#
def quit_click():
    root.destroy()

#IP/Hostname entry field#
device = Entry(root, width=60, borderwidth=20, fg="black")
device.insert(0, "Enter the IP/Hostname you want to connect to")
device.bind("<FocusIn>", on_device_click)
device.bind("<FocusOut>", on_device_focusout)
device.grid(row=0, column=0, columnspan=2, sticky="nsew")

#Username entry field#
UN = Entry(root, width=60, borderwidth=20, fg="black")
UN.insert(0, "Enter your username")
UN.bind("<FocusIn>", on_UN_click)
UN.bind("<FocusOut>", on_UN_focusout)
UN.config(fg="gray")
UN.grid(row=1, column=0, columnspan=2, sticky="nsew")

#Password entry field#
PW = Entry(root, show="*", width=60, borderwidth=20, fg="black")
PW.insert(0, "*")
PW.bind("<FocusIn>", on_PW_click)
PW.bind("<FocusOut>", on_PW_focusout)
PW.config(fg="gray")
PW.grid(row=2, column=0, columnspan=2, sticky="nsew")

#IP for commands entry field#
IP = Entry(root, width=30, borderwidth=20, fg="black")
IP.insert(0, "Enter IP for commands")
IP.bind("<FocusIn>", on_IP_click)
IP.bind("<FocusOut>", on_IP_focusout)
IP.config(fg="gray")
IP.grid(row=3, column=0, sticky="nsew")

#Interface entry field#
INT = Entry(root, width=30, borderwidth=20, fg="black")
INT.insert(0, "Enter Int/MAC/VLAN for commands")
INT.bind("<FocusIn>", on_INT_click)
INT.bind("<FocusOut>", on_INT_focusout)
INT.config(fg="gray")
INT.grid(row=3, column=1, sticky="nsew")

#Creates the "show active calls" button#
active = Button(root, text="Show Active Calls", width=30, bg="#08bc08", pady=2, fg="black", borderwidth=10, command=active_click)
active.grid(row=4, column=0, sticky="nsew")

#Creates the "show bgp summary" button#
bgpsumm = Button(root, text="Show BGP Summary", width=30, bg="#08bc08", pady=2, fg="black", borderwidth=10, command=bgpsumm_click)
bgpsumm.grid(row=4, column=1, sticky="nsew")

#Creates the "show cdp neighbors" button#
cdp = Button(root, text="Show CDP neighbors", width=30, bg="#08bc08", pady=2, fg="black", borderwidth=10, command=cdp_click)
cdp.grid(row=5, column=0, sticky="nsew")

#Creates the "show error-disabled" button#
errdisable = Button(root, text="Show Err-Disabled Interfaces", width=30, bg="#08bc08", pady=2, fg="black", borderwidth=10, command=errdisable_click)
errdisable.grid(row=5, column=1, sticky="nsew")

#Creates the "show interfaces" button#
showint = Button(root, text="Show Interfaces", width=30, bg="#08bc08", pady=2, fg="black", borderwidth=10, command=showint_click)
showint.grid(row=6, column=0, sticky="nsew")

#"show ip arp" button"
isdn = Button(root, text="Show IP ARP", width=30, bg="#08bc08", pady=2, fg="black", borderwidth=10, command=iparp_click)
isdn.grid(row=6, column=1, sticky="nsew")

#"show isdn status" button"
isdn = Button(root, text="Show ISDN Status", width=30, bg="#08bc08", pady=2, fg="black", borderwidth=10, command=isdn_click)
isdn.grid(row=7, column=0, sticky="nsew")

#Creates the "show mac" button#
mac = Button(root, text="Show MAC Address", width=30, bg="#08bc08", pady=2, fg="black", borderwidth=10, command=mac_click)
mac.grid(row=7, column=1, sticky="nsew")

#Creates the "show temperature" button#
temp = Button(root, text="Show Temperature", width=30, bg="#08bc08", pady=2, fg="black", borderwidth=10, command=temp_click)
temp.grid(row=8, column=0, sticky="nsew")

#Creates the "show uptime" button#
uptime = Button(root, text="Show Uptime", width=30, bg="#08bc08", pady=2, fg="black", borderwidth=10, command=uptime_click)
uptime.grid(row=8, column=1, sticky="nsew")

#Creates the "show VLAN" button#
vlan = Button(root, text="Show VLAN", width=30, bg="#08bc08", pady=2, fg="black", borderwidth=10, command=vlan_click)
vlan.grid(row=9, column=0, sticky="nsew")

#Creates the "quit" button#
quit = Button(root, text="Quit", width=30, bg="red", fg="black", borderwidth=10, command=quit_click)
quit.grid(row=10, column=1, sticky="nsew")

#Row number buttons start at. Used for start of button auto re-size loop#
button_row_num = 4

#Creates button list#
button_list = (active, bgpsumm, cdp, errdisable, showint, isdn, temp, vlan, quit)

for button in button_list:
    Grid.rowconfigure(root, button_row_num, weight=1)
    Grid.columnconfigure(root, 0, weight=1)
    Grid.columnconfigure(root, 1, weight=1)
    button_row_num +=1

#Runs the app#
root.mainloop()

8 – Custom Module Show Block on Front Page or on All

I have a custom module, in Drupal 9, (showing a block in a region) that has an admin form with a checkbox for showing only on the “front page” or if unchecked on “all” pages.

In order for the block to show on the homepage or on all pages do I need some sort of preprocess function to run before the block loads? Does the build() only happen once and then is cached? If so, how do we let the block know what page it belongs on programmatically?

I have a simple build function to test this (build() is inside src/plugin/block), which doesn’t work:

 public function build(){
        $alert_front = Drupal::config('alert_front.settings')->get('front');
        $current_is_front = Drupal::service('path.matcher')->isFrontPage();
    
      if ($current_is_front) {
        return (
          '#markup' => $this->t("Yes, Front Page Only"),
        );
      }else{
       return (
        '#markup' => $this->t('@alert and @fp',(
          '@alert' => alertType($alert_type),
          '@fp' => $alert_front,
        )),
       );
     }
}

The Drupal block api isn’t giving me much here, but I’ll keep digging. Thanks for any ideas.

¿Cómo convertir o transformar un número a horas usando javascript?

cómo puedo hacer para convertir un valor decimal a horas usando JavaScript? estuve revisando Excel y tiene una forma muy fácil de hacerlo, pero esto quiero llevarlo a JS. Existe alguna forma de realizar el siguiente cálculo?
Imagen de referencia en Excel

Esa es la manera que Excel convierte un valor a horas. Intente pasarlo a minutos pero no tuve éxito, Gracias por el apoyo

Are there (small, pod) hotels for single people in Western countries?

While this doesn’t expressly address the “are there single traveler, pod-type hotels in the US?”, it does offer a solution that the pod-type hotel would – lower cost.

The cost of the hotel room in a particular city (in the US, at least) is dictated a couple of factors:

  1. The “chain” or brand of hotel you’re booking.

    Hilton is more expensive that Motel 6. Always and forever.

  2. The location of the hotel.

    Downtown is more expensive than the suburbs. Generally. Some suburbs have a large business sector and are more upscale than others.

The general concept is that business travelers aren’t paying for their own room, so they’re less cost sensitive (hey, the company’s paying, might as well have a nice place, right?), but they’re highly convenience sensitive (I don’t have time to travel from the work place to a cheap place in the ‘burbs, especially after wining & dining a potential client until late in the evening). Additionally, the business traveler may not have private transportation (a rental/hire car) and be fully dependent on public transport and/or simply walking from the work site to the hotel. (I was in that situation for a new job – working remote, but spent a week onsite to meet people – my hotel was literally across the street from the work site.)

However, individual travelers on vacation/visiting family/etc. are paying for their own room so they’re more price sensitive and less convenience sensitive.

If you need to visit NYC, consider staying across the river in NJ. Hotel rooms will be cheaper (even for the same brand) because location, location, location! You’ll pay for it, though, in additional travel time, cost and inconvenience in having to get in and out of the city each day you need to make the trip. This is exactly what my wife & I did when we visited my family in Manhattan with our young kids a decade or so ago. We stayed in Jersey and made an adventure of traveling into the city each day so it was fun for them. We took the tunnel, we took different bridges, etc. As a family on vacation, we could do that. As a business traveler, that would have been a nightmare.

Generally speaking, you’re going to get the same quality and amenities by choosing a suburb Hilton v a downtown Hilton (substitute Motel 6, if desired), but you’re going to pay less the further away from the city center you go.

accessibility – How to get out of RTT mode on Samsung S20FE during call

Anyone know how I can disable or just exit RTT mode during a call on my Samsung phone. I recently purchased it and never even saw this option on my old Pixel 3XL. I’m using the Google phone app. The button looks like this:

enter image description here

I’ve seen many solutions which revolves around turning it off in settings, but this isn’t an option on my phone. I can only turn it from “Always visible” to “Visible during calls” which doesn’t make any difference. I don’t mind the button being there during calls, but if I hit it by accident, I can find no way of getting out of the RTT mode which makes navigating my phone during calls cumbersome and awkward, especially when I’m trying to quickly switch to speaker or mute and I’m not expecting this screen; I end up missing part of the call. My job makes this particularly frustrating and obstructive.

It looks like this if I hit it, and the menu offers no way to close it:

enter image description here

enter image description here

ag.algebraic geometry – Contraction of some surfaces over a ring of algebraic integers

The situation:
Let $X$ be a 2 dimensional normal quasi-projective $mathcal{O}_K$-scheme, where $K$ is an algebraic number field. Assume the following conditions on $X$:

  1. $X$ is integral.
  2. $X_K$ is geometrically integral.
  3. $X to textrm{spec}(mathcal{O}_K)$ is surjective.

Let $Xto bar{X}$ an open immersion into a projective scheme. (this exist since $X$ is quasi-projective).

In particular, 1-dimensional irreducible closed subschemes of $bar{X}$ are either

  1. Horizontal: spectra of finite flat extensions of $mathcal{O}_K$
  2. Vertical: curves over $mathcal{O}_K/pmathcal{O}_K$, which is a finite field, for nonzero ideals $pin textrm{spec}(mathcal{O}_K)$.

The claim I want to prove:
Let $V$ be the vertical part of $bar{X}backslash X$. Theorem 2 of (Points entiers des variétés arithmétiques, Moret-Bailly) states (withouth proof) that there exists a “contraction” of $V$. i.e. a map $bar{X}to Y$ which is surjective, $bar{X}backslash Vto Y$ is an open immersion and the image in $V$ is a set of isolated points. I am looking for a proof of such a claim. If that helps, you may assume that $K=mathbb{Q}$. You may assume that $bar{X}$ is regular.

What I have already found:
The paper states states that this follows similarly from a paper of Artin, but I couldn’t understand how. I also found a paper of Moret-Bailly which uses the existance of integral points on $X$ to prove what I am surching for. But I am looking for a proof which does not rely on this fact, since I am trying to write the proof of theorem 1 of (Points entiers des variétés arithmétiques, Moret-Bailly) using theorem 2 of the same paper. Conditions of the existance of such a contraction can also be found in theorem 27.1 of this work , so you may just help me to find why these conditions apply to my case.

java – How can i fix my enemy movement, and collision?

I recently started a project with some friends, Its a simple java game and im having issue getting the Collision and enemy movement working properly.

Using this:

if(tempObject.getId() == ID.Block) {
            if (getBoundsBig().intersects(tempObject.getBounds())) {
                velX = -velX;
                velY = -velY;
            }
            else {
                velX = (jenny.nextInt(4 - -4) + -4);
                velY = (jenny.nextInt(4 - -4) + -4);
            }
        }

I can get basic enemy movement, however the collision doesn’t seem to work. Enemies often change velocity really fast but the enemies end up phasing through walls. I thought just setting the velocity to the negative counterpart would be enough. Its not.

In - Game footage of enemy phasing

As seen in the gif above the enemy still decides to run right through a wall. Any ideas on how i could fix this?