python – Employee directory – Code Review Stack Exchange

Starting with the last line:

menu()

Standard practice is to put this in a “main guard”, so that the file is usable from other programs:

if __name__ == '__main__':
    menu()

This bit looks fragile:

    key = str("0"*(6-len(str(x)))) + str(x)

There’s an assumption there that all employee ids are 6 digits (and that’s a convoluted way to format – much simpler would be key = f'{x:06u}').


Recursively calling menu() as the last action of each user function means that we constantly recurse into that function. Simply looping is more memory-efficient.


        os.system("clear")

That’s risky. We’re using whatever PATH we inherited, which might not include a clear command – or worse, it might include one that does something completely unexpected.


What’s the reset() function for? It seems to replace dict with a copy of itself, which seems like a waste of electricity.


if selection == "1":
    ⋮
if selection == "2":
    ⋮
if selection == "3":
    ⋮
if selection == "4":
    ⋮
if selection == "5":
    ⋮

This kind of switch/case is normally represented in Python using an action dictionary. If you really want to use if, it’s better to use elif to skip the conditions following the match.


for x in range(1, len(dict)+1):
    key = list(dict.keys())(x-1)

Why offset everything by 1? We could as easily write for x in range(0, len(dict) and then simply use x rather than x-1. But in any case for x in range() is a code smell; here we just want to iterate over all of dict‘s elements:

for key,value in dict:
    print(f" Name: {value(1)} {value(2)}n Position: {value(0)}n Employee ID: {key} n")

This is a partial review; I ran out of time here.

python – is this a good way of making a employee dictionary

Is this a efficient way of making this
I had this as a project last school year and decided to try and optimize it and was curious if this is a good way of doing this to see how much i have learned

import os
dict = {
#   "empId": ("title", name)
    "000001": ("ceo", "joe", "smith"),
    "000002": ("co", "bob", "konn"),
    "000003": ("lead designer", "koss", "klan"),
 
}
dict2 = {
    
}
 
def searchEmpId(empID):
    key = empID
    if key in dict:
        print(" Name: {} {}n Position: {}n Employee ID: {}".format(dict(key)(1), dict(key)(2), dict(key)(0), key))
    print("n")
    input("Press enter to return to main menu")
    menu()
 
def searchName(Name):
    for x in range(1, len(dict)):
        key = str("0"*(6-len(str(x)))) + str(x)
        if Name in dict(key):
            print(" Name: {} {}n Position: {}n Employee ID: {}".format(dict(key)(1), dict(key)(2), dict(key)(0), key))
    print("n")
    input("Press enter to return to main menu")
    menu()
 
def add(Position, First, Last):
    dict.update({str(str("0"*(6-len(str(len(dict)+1)))) + str(len(dict)+1)): (Position, First, Last)})
    print("n")
    input("Press enter to return to main menu")
    menu()
 
def reset():
    dict2.update(dict.copy())
    dict.clear()
    for x in range(0, len(dict2)):
        res = list(dict2.keys())(0)
        add(dict2(res)(0), dict2(res)(1), dict2(res)(2))
        dict2.pop(res)
 
def remove(empID):
    dict.pop(empID)
    reset()
    print("n")
    input("Press enter to return to main menu")
    menu()
 
def listDict():
    os.system("clear")
    for x in range(1, len(dict)+1):
        key = list(dict.keys())(x-1)
        print(" Name: {} {}n Position: {}n Employee ID: {} n".format(dict(key)(1), dict(key)(2), dict(key)(0), key))
    input("Press enter to return to main menu")
    menu()
 
def menu():
    os.system("clear")
    print("Welcome to the employee dictionary")
    print('n To search for an employee by id type "1" ')
    print(' To search for an employee by name type "2" ')
    print(' To add an employee type "3" ')
    print(' To remove an employee type "4" ')
    print(' To list the dictionary type "5" n')
    selection = input(">>  ")
    if selection == "1":
        os.system("clear")
        searchEmpId(str(input("Employee ID: ")))
    if selection == "2":
        os.system("clear")
        searchName(str(input("First name or last name(but not both): ")))
    if selection == "3":
        os.system("clear")
        add(str(input("Position: ")), str(input("First name: ")), str(input("Last Name: ")))
    if selection == "4":
        os.system("clear")
        remove(str(input("Employee ID: ")))
    if selection == "5":
        listDict()
menu()
```

macos – DLP + Employee monitoring on MAC systems

We are looking to implement Data Loss Prevention solution and employee monitoring in our system. In our network, we have many Macs which we want to secure. We want to protect ourselves from leaking data on a hard drive or on a cloud. We need to receive notification if someone tries to leak data, block it, and a way to check if the alert is real. Can anyone recommend a solution that he has experience with? We were recommended to use Teramind but it doesn’t work on MAC….

iphone – How I can add employee access card to IOS application?

I want to build an app for IOS specifically, where employee can see his/her digital access card ( image of the card )
and also, add the card to apple wallet so he can use it to access the office..

note: Currently each employee access card has long number written on it and can access either by scanning the card on the device Or entering the number.

I want to know if The thing I want to achieve is possible ? I have no idea how I can add the card which has an RFID chip to the app ^^
What I was thinking about..
when the employee login to the app, his access card number is already linked to his account, but how I can use that number to scan?

and when adding the card to apple wallet, what it will add exactly.. he employee card and save it’s card number to scan?

I don’t know ^^

user – SharePoint Online and Flows – how to remove quitted employee correctly?

I created flow that uses “Grant permissions” action, and it uses SharePoint Group with users. One of employees has left the company, and (as I understand) IT Team deleted this account. But this user was still in SharePoint Group so my flow got his email and crashed on “Grant permissions” step:

cannot resolve user jane.doe@company.com

So all my approval instances created yesterday crashed.
As I suppose IT Team should not delete user, but reset password and disable(?). Imho we need to keep users for audit/project management history..

What is correct procedure of removing resigned user in Microsoft 365? Do You have any best-practices or what do You use?

How do exchanges manage their bitcoin/crypto? It only takes 1 employee with private keys to steal it all

So hear me out. I understand exchanges have hot/cold wallets and mostly use their hot wallets. But at some point they need to send crypto from their cold wallet to their hot wallet.

Who does this? The CEO & only the CEO? Technically whoever holds the password to these keys could send it to any address and it not be retrievable. The person would be in a lot of trouble but the crypto would probably be unobtainable.

Even if that crypto is “insured” the insurance company would probably only be able to payout in fiat.

Basically, how do exchanges keep your crypto secure?

java – org.postgresql.util.PSQLException: ERROR: relation “employee” does not exist Position: 13

I am trying to change the database from mySQL to postgreSQL from the tutorial given on: https://javainspires.blogspot.com/2020/07/spring-boot-2-spring-data-jdbc-jdbc.html . I am constantly having the error shown in the title.

Employee.java

package com.example.demo;

import javax.persistence.Entity;
import javax.persistence.Table;

public class Employee {

    private String username;
    private String email;
    private String password;

    public Employee() {
        super();
        // TODO Auto-generated constructor stub
    }

    public Employee(String username, String email, String password) {
        super();
        this.username = username;
        this.email = email;
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

}

EmployeeController

package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

@Controller
public class EmployeeController {

    @Autowired
    JdbcTemplate jdbcTemplate;
    
    @PostMapping(path = "addUser")
    public String addUser(Employee user) {
        
        String insert_query = "INSERT INTO employee (username,email,password) VALUES(?,?,?)"; 
        
        int rows = jdbcTemplate.update(insert_query,
                user.getUsername(), 
                user.getEmail(),
                user.getPassword());
        
        if(rows == 1) {
            return "success"; 
        } else {
            return "error"; 
        }
                
    
    }
    
}

Html Files:
index.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="ISO-8859-1">
<title>Java Inspires</title>
</head>
<body>

 <form th:action="@{/addUser}" th:object="${user}" method="post" >
 
  <p>User Name :<input type="text" name="username" /></p>
  <p>Email :<input type="email" name="email" /></p>
  <p>Password :<input type="password" name="password" /></p>
  <p><input type="submit" value="Sign Up" /></p>
 </form>
</body>
</html>

Application.properties

spring.datasource.url=jdbc:postgresql://localhost:5432/database
spring.datasource.username=postgres
spring.datasource.password=admin
spring.datasource.driver-class-name=org.postgresql.Driver

schema.sql

CREATE TABLE employee
(
    username varchar(100) NOT NULL, 
    email varchar(100) NOT NULL,
    password varchar(100) NOT NULL
); 

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>JDBC</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>JDBC</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

c# – This code loops through a GlobalEmployeesList, eliminates duplicate email and phone records for the selected employee, and populates listboxes

I have a DataGridView which displays an employee list. I use the employee ID to filter my global employee list and display information about the selected employee in various listboxes. This is my first coding project, and I’m pleased that it’s working well, but I do feel like I’m repeating myself a lot. Is this an instance where an experienced coder would be able to abstract some underlying pattern and write a method which simplifies everything?

Also, after setting the datasources, I have a comment, “CREATE DATASOURCE LIST”. I’ve heard that comments shouldn’t say WHAT code does, but rather WHY it does something. But I find the green comments in caps makes it really easy to find sections of my code at a glance. I also have comments to separate the various Tabs on my Winform application. “INVENTORY TAB”, “EMPLOYEE TAB”, “VEHICLES TAB”, etc. Are those frowned upon?

  private void employeeGridView_CellClick(object sender, DataGridViewCellEventArgs e)
            {
                DataGridViewCell selectedEmployeeCell = employeeGridView.CurrentCell;
                int selectedEmployeeRow = selectedEmployeeCell.RowIndex;
                int selectedEmployeeID = (int)employeeGridView.Rows(selectedEmployeeRow).Cells(0).Value;

                certificationsListBox.DataSource = certificationListBoxString(id: selectedEmployeeID, employees: globalEmployeeList.ToList());
                citationsListBox.DataSource = citationsListBoxString(id: selectedEmployeeID, employees: globalEmployeeList.ToList());

                emailGridView.DataSource = null;
                emailGridView.DataSource = GetEmailRecordsList(SelectedEmployeeID: selectedEmployeeID);
                emailGridView.Columns(0).Visible = false;
                emailGridView.RowHeadersVisible = false;
                emailGridView.Columns(1).Width = 200;
                emailGridView.Columns(2).Width = 75;

                phoneGridView.DataSource = null;
                phoneGridView.DataSource = GetPhoneRecordsList(SelectedEmployeeID: selectedEmployeeID);
                phoneGridView.Columns(0).Visible = false;
                phoneGridView.RowHeadersVisible = false;
                phoneGridView.Columns(1).Width = 150;
                phoneGridView.Columns(2).Width = 75;

                DepartmentListBox.DataSource = null;
                DepartmentListBox.DataSource = GetDepartment(SelectedEmployeeID: selectedEmployeeID);
                DepartmentListBox.ClearSelected();

                StatusListBox.DataSource = null;
                StatusListBox.DataSource = GetStatus(SelectedEmployeeID: selectedEmployeeID);
                StatusListBox.ClearSelected();

                HireDateListBox.DataSource = null;
                HireDateListBox.DataSource = GetHireDate(SelectedEmployeeID: selectedEmployeeID);
                HireDateListBox.ClearSelected();
            }

        //CREATE DATASOURCE LISTS
        public static IList<EmployeeModel> globalEmployeeList = new List<EmployeeModel>();
        public static async Task<IList<EmployeeModel>> InitializeEmployeeList()
        {
            globalEmployeeList = await GlobalConfig.Connection.GetEmployeeList();

            foreach (EmployeeModel eModel in globalEmployeeList)
            {
                var groupedEmailList = new List<EmailModel>();
                var groupedPhoneList = new List<PhoneModel>();
                List<int> phoneIDs = new List<int>();
                List<int> emailIDs = new List<int>();
                foreach (EmailModel emailModel in eModel.EmailList)
                {
                    if (!emailIDs.Contains(emailModel.ID))
                    {
                        emailIDs.Add(emailModel.ID);
                        groupedEmailList.Add(emailModel);
                    }
                }
                eModel.EmailList = groupedEmailList;

                foreach (PhoneModel phoneModel in eModel.PhoneList)
                {
                    if (!phoneIDs.Contains(phoneModel.ID))
                    {
                        phoneIDs.Add(phoneModel.ID);
                        groupedPhoneList.Add(phoneModel);
                    }
                }
                eModel.EmailList = groupedEmailList;
                eModel.PhoneList = groupedPhoneList;
            }
            return globalEmployeeList;
        }
        //TURN THIS INTO A WHILE LOOP ONCE YOU LEARN HOW TO DO WHILE LOOPS   
        public IList<TitleModel> TitleList = new List<TitleModel>();
       
        public void GetJobTitleList()
        {
            foreach (EmployeeModel em in globalEmployeeList)
            {
                TitleList.Add(em.JobTitle);
            }
        }

        private IList<PhoneModel> phoneRecords = new List<PhoneModel>();
       
        private IList<PhoneModel> GetPhoneRecordsList(int SelectedEmployeeID)
        {
            if (phoneRecords != null)
            {
                phoneRecords.Clear();
            }
            foreach (EmployeeModel em in globalEmployeeList.Where(person => person.ID == SelectedEmployeeID))
            {
                foreach (PhoneModel pm in em.PhoneList)
                {
                    phoneRecords.Add(pm);
                }
            }
            return (IList<PhoneModel>)phoneRecords;
        }

        public IList<EmailModel> emailRecords = new List<EmailModel>();
        
        public IList<EmailModel> GetEmailRecordsList(int SelectedEmployeeID)
        {
            if (emailRecords != null)
            {
                emailRecords.Clear();
            }
            foreach (EmployeeModel em in globalEmployeeList.Where(person => person.ID == SelectedEmployeeID))
            {
                foreach (EmailModel emm in em.EmailList)
                {
                    emailRecords.Add(emm);
                }
            }
            return (IList<EmailModel>)emailRecords;
        }

        public IList<string> selectedStatus = new List<string>();
        public IList<string> GetStatus(int SelectedEmployeeID)
        {
            if (selectedStatus != null)
            {
                selectedStatus.Clear();
                foreach (EmployeeModel em in globalEmployeeList.Where(person => person.ID == SelectedEmployeeID))
                {
                    selectedStatus.Add(em.Status.Name);
                }
            }
            return (IList<string>)selectedStatus;
        }
                
        public IList<string> selectedDepartment = new List<string>();
        public IList<string> GetDepartment(int SelectedEmployeeID)
        {
            if (selectedDepartment != null)
            {
                selectedDepartment.Clear();
                foreach (EmployeeModel em in globalEmployeeList.Where(person => person.ID == SelectedEmployeeID))
                {
                    selectedDepartment.Add(em.Department.Name);
                }
            }
            return (IList<string>)selectedDepartment;
        }

        public IList<string> selectedHireDate = new List<string>();
        public IList<string> GetHireDate(int SelectedEmployeeID)
        {
            if (selectedHireDate != null)
            {
                selectedHireDate.Clear();
                foreach (EmployeeModel em in globalEmployeeList.Where(person => person.ID == SelectedEmployeeID))
                {
                    selectedHireDate.Add(em.HireDate.ToString() );
                }
            }
            return (IList<string>)selectedHireDate;
        }