Analysis: China-US hacking accord is tall on rhetoric, short on substance

(credit: https://www.whitehouse.gov)

It’s always a good thing when governments, especially superpowers, strike agreements toward the goal of peace and prosperity.

The accord President Barack Obama and Chinese President Xi Jinping announced Friday—a “common understanding” to curb state-sponsored, corporate cyber espionage toward one another—inches us toward that goal if we assume both sides would uphold their end of the bargain.

Read 11 remaining paragraphs | Comments

Why a Washington Post Editor Left to Work With Starbucks

BrandJourno

Starbucks recently partnered with award-winning journalist Rajiv Chandrasekaran from The Washington Post to head up a new media venture. The collaboration between a seasoned journalist and a mega-brand points to an exciting new time for long-form storytelling. Can brands pull it off gracefully? Will consumers accept it?

Rajiv Chandrasekaran worked as a staff writer and editor for The Washington Post for more than two decades. He served as bureau chief in Baghdad in the early 2000s, then as a senior correspondent and associate editor for the paper.

read more

File handling in Python – Hello friends :D !!! Can you help me debugging this code please?

Well i made this script that its supouse to logg some keystrokes for a while save them in a file and then erase the file if the user want to however when the script tryes to delete the file i get this error.

Traceback (most recent call last):File “C:\Users\Tormentor\Desktop\S.D.A.K.L\pregunta.py”, line 34, in os.remove(path2+”\”+name)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:’C:\Users\Public\myfile.txt’

I made some research and i think that it cant be deleted because my “snp” function never closes the file where the keystrokes are logged so how can i close the file to delete it?
Thanks for your help :).

import os
import time
import pyHook, pythoncom, sys, logging

path="C:\\Users\\Public\\myfile.txt"

path2="C:\\Users\\Public"

name="myfile.txt"

TinM=10

def snp(event):    #<---------- Not closing file ???
    global path
    logging.basicConfig(filename=path, level=logging.DEBUG, format='%(message)s')
    chr(event.Ascii)
    logging.log(10,chr(event.Ascii))
    return True


timeout=time.time()+TinM
while timeout > time.time():
    hooks_manager = pyHook.HookManager()
    hooks_manager.KeyDown = snp
    hooks_manager.HookKeyboard()
    print("Logging keystrokes")
    pythoncom.PumpWaitingMessages()
else:
    hooks_manager.UnhookKeyboard()
    x=input("Keylogger stoped do you want to delete the archive? y / n")
    if x == "y":
        for(path2,dirs,files) in os.walk(path2):
            if name in files:
                os.remove(path2+"\\"+name) # <----- This line triggers the error.
                print("Archive deleted. Goodbye")
            else:
                print("Archive does not exist or cant be found goodbye! :D")
    else:
        print("Goodbye! :D")

read more

File handling in Python – Hello friends :D !!! Can you help me debugging this code please?

Well i made this script that its supouse to logg some keystrokes for a while save them in a file and then erase the file if the user want to however when the script tryes to delete the file i get this error.

Traceback (most recent call last):File “C:\Users\Tormentor\Desktop\S.D.A.K.L\pregunta.py”, line 34, in os.remove(path2+”\”+name)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:’C:\Users\Public\myfile.txt’

I made some research and i think that it cant be deleted because my “snp” function never closes the file where the keystrokes are logged so how can i close the file to delete it?
Thanks for your help :).

import os
import time
import pyHook, pythoncom, sys, logging

path="C:\\Users\\Public\\myfile.txt"

path2="C:\\Users\\Public"

name="myfile.txt"

TinM=10

def snp(event):    #<---------- Not closing file ???
    global path
    logging.basicConfig(filename=path, level=logging.DEBUG, format='%(message)s')
    chr(event.Ascii)
    logging.log(10,chr(event.Ascii))
    return True


timeout=time.time()+TinM
while timeout > time.time():
    hooks_manager = pyHook.HookManager()
    hooks_manager.KeyDown = snp
    hooks_manager.HookKeyboard()
    print("Logging keystrokes")
    pythoncom.PumpWaitingMessages()
else:
    hooks_manager.UnhookKeyboard()
    x=input("Keylogger stoped do you want to delete the archive? y / n")
    if x == "y":
        for(path2,dirs,files) in os.walk(path2):
            if name in files:
                os.remove(path2+"\\"+name) # <----- This line triggers the error.
                print("Archive deleted. Goodbye")
            else:
                print("Archive does not exist or cant be found goodbye! :D")
    else:
        print("Goodbye! :D")

read more

My program is about enrollment system using dev c language, how can i fix the switch statements break lines?

include

main(){
int stdnumber, units, yearlvl, cash, stat, semester, nunits, totaltui, miscell = 8586, totalfee, install, monthlyfee;

   printf("Welcome to MIT Enrollment System for Mechanical Engineering\n");
   printf("Which option will you choose:\n");
    printf("1) Old Student \n");
    printf("2) New Student \n");
    scanf("%d", &stat);
    system("cls");
    switch (stat)
    { 
        {case  1:
                printf("Old Student Registry\n");
                printf("Input Year Level: ");
                scanf("%d", &yearlvl);
                system("cls");
                switch (yearlvl)
                {case 2:
                            printf("Choose Semester\n");
                            printf("1) 1st Semester\n");
                            printf("3) 2nd Semester\n");
                            scanf("%d", &semester);
                            switch (semester)
                             {case 1: 
                                  printf("Choose 1st sem courses by inputing the total number of units you want to enroll.\n");
                                  printf("Course                                                    Units\n");
                                  printf("ENGL 003(Technical Writing)                               3.00\n");
                                  printf("MATH 007(Differntial Calculus)                            4.00\n");
                                  printf("MATH 013(MATHLAB w/ Linear Algebra)                       3.00\n");
                                  printf("SOCSC 002(Sociology w/ Family Planning)                   3.00\n");
                                  printf("SOCSC 003(Philippine History w/ Politics and Governance)  3.00\n");
                                  printf("HUM 002(Logic)                                            3.00\n");
                                  printf("PE 003(Individual/Dual Sports)                            2.00\n");
                                  printf("CS100 A(Fundamentals of Programming and Algorithm)        2.00\n");
                                  printf("                                              Total units: 23\n");
                                  printf("Enter the number of units you want to enroll: \n");
                                  scanf("%d", &nunits);
                                  system("cls");
                                  if(nunits<=23){
                                                 totaltui = nunits*1150;
                                                 printf("Your Tuition Fee is %d.00\n", totaltui);
                                   printf("Miscellaneous Fees         AMOUNT\n");
                                   printf("Laboratory Fee            1,250.00\n");
                                   printf("Athletics Fee               670.00\n");
                                   printf("Audio Visual Fee            115.00\n");
                                   printf("Computer Fee              2,300.00\n");
                                   printf("Cultural and Activity        50.00\n");
                                   printf("Development Fee             720.00\n");
                                   printf("Energy Fee                  760.00\n");
                                   printf("Guidance&Counselling        450.00\n");
                                   printf("Insurance Fee                11.00\n");
                                   printf("Internet Fee                 90.00\n");
                                   printf("Library Fee               1,315.00\n");
                                   printf("Medical/Dental Fee          450.00\n");
                                   printf("Red Cross Fee                 1.00\n");
                                   printf("Registration Fee            450.00\n");
                                   printf("Student Council Fee          35.00\n");
                                   printf("Student Development Fee     160.00\n");
                                   printf("Test Paper Fee              210.00\n");
                                   printf("              TOTAL MS FEE:8586.00\n");
                                   printf("*1 unit is equals to 1150.00 pesos*\n");
                                   printf("Enter any key to continue: ");
                                   scanf("%d", &units);
                                   system("cls");
                                   totalfee = miscell + totaltui;
                                   printf("Your TOTAL FEE FOR THIS SEMESTER IS %d.00\n", totalfee);
                                   printf("Enter any number to continue: ");
                                   scanf("%d", &units);
                                   system("cls");
                                    printf("Choose mode of payment\n");
                                   printf("1)CASH\n");
                                   printf("2)INSTALLMENT\n");
                                   printf("Enter the number of your choice: ");
                                   scanf("%d", &cash);
                                   system("cls");
                                   switch(cash)
                                   { case 1: printf("Your TOTAL FEE is %d.00\n", totalfee);
                                             printf("Please Proceed to the Treasure for the payment\n");
                                             printf("Thank you for using MIT enrollment system! :)");
                                             break;
                                     case 2: 
                                          install = totalfee + 2300;
                                     printf("Your TOTAL FEE for INSTALLMENT is %d.00\n", install);
                                     printf("*Installment payment has a charge of 2300.00 pesos\n");
                                     printf("Downpayment is 3500\n");
                                     printf("You must pay the balance during Prelims, Midterms and Finals.\n");
                                     monthlyfee = (install - 3500)/3;
                                     printf("In Every Term you must pay %d.00 in the treasury office.\n", monthlyfee);
                                     printf("Thank you for using MIT Enrollment System! :)");
                                     break;
                                     default:
                                             printf("INVALID INPUT");
                                             break;}
                                   }
                                   else{
                                   printf("You can't have more than 23 units\n");}
                                  break;

                                  }
                                  break;

                            {case 3: 

                                  printf("Choose 2nd sem courses by inputing the total number of units you want to enroll.\n");
                                  printf("Course                                                    Units\n");
                                  printf("PHYS 001(Calculus-Based Physics 1)                        4.00\n");
                                  printf("MATH 008(Integral Calculus)                               4.00\n");
                                  printf("MATH 009(Probability and Statistics)                      3.00\n");
                                  printf("SOCSC 004(General Phychology)                             3.00\n");
                                  printf("SOCSC 005(Life and Works of Rizal)                        3.00\n");
                                  printf("HUM 003(Ethics)                                           3.00\n");
                                  printf("PE 004(Sports and Games)                                  2.00\n");
                                  printf("CHEM 002(Environmental Engineering)                       3.00\n");
                                  printf("                                              Total units: 25\n");
                                  printf("Enter the number of units you want to enroll: \n");
                                  scanf("%d", &nunits);
                                  system("cls");
                                  if(nunits<=25){
                                                 totaltui = nunits*1150;
                                                 printf("Your Tuition Fee is %d.00\n", totaltui);
                                   printf("Miscellaneous Fees         AMOUNT\n");
                                   printf("Laboratory Fee            1,250.00\n");
                                   printf("Athletics Fee               670.00\n");
                                   printf("Audio Visual Fee            115.00\n");
                                   printf("Computer Fee              2,300.00\n");
                                   printf("Cultural and Activity        50.00\n");
                                   printf("Development Fee             720.00\n");
                                   printf("Energy Fee                  760.00\n");
                                   printf("Guidance&Counselling        450.00\n");
                                   printf("Insurance Fee                11.00\n");
                                   printf("Internet Fee                 90.00\n");
                                   printf("Library Fee               1,315.00\n");
                                   printf("Medical/Dental Fee          450.00\n");
                                   printf("Red Cross Fee                 1.00\n");
                                   printf("Registration Fee            450.00\n");
                                   printf("Student Council Fee          35.00\n");
                                   printf("Student Development Fee     160.00\n");
                                   printf("Test Paper Fee              210.00\n");
                                   printf("              TOTAL MS FEE:8586.00\n");
                                   printf("*1 unit is equals to 1150.00 pesos*\n");
                                   printf("Enter any key to continue: ");
                                   scanf("%d", &units);
                                   system("cls");
                                   totalfee = miscell + totaltui;
                                   printf("Your TOTAL FEE FOR THIS SEMESTER IS %d.00\n", totalfee);
                                   printf("Enter any number to continue: ");
                                   scanf("%d", &units);
                                   system("cls");
                                    printf("Choose mode of payment\n");
                                   printf("1)CASH\n");
                                   printf("2)INSTALLMENT\n");
                                   printf("Enter the number of your choice: ");
                                   scanf("%d", &cash);
                                   system("cls");
                                   switch(cash)
                                   { case 1: printf("Your TOTAL FEE is %d.00\n", totalfee);
                                             printf("Please Proceed to the Treasure for the payment\n");
                                             printf("Thank you for using MIT enrollment system! :)");
                                             break;
                                     case 2: 
                                          install = totalfee + 2300;
                                     printf("Your TOTAL FEE for INSTALLMENT is %d.00\n", install);
                                     printf("*Installment payment has a charge of 2300.00 pesos\n");
                                     printf("Downpayment is 3500\n");
                                     printf("You must pay the balance during Prelims, Midterms and Finals.\n");
                                     monthlyfee = (install - 3500)/3;
                                     printf("In Every Term you must pay %d.00 in the treasury office.\n", monthlyfee);
                                     printf("Thank you for using MIT Enrollment System! :)");
                                     break;
                                     default:
                                             printf("INVALID INPUT");}


                                                 }
                                                 else{
                                                      printf("You can't have more than 23 units\n");}}
                                     break;
                                     }
                                  break;   
                                  }


        case  2:
            {
                printf("New Student Registry\n");
                printf("Choose Semester\n");
                printf("1) 1st semester\n");
                printf("4) 2nd semester\n");
                scanf("%d", &semester);
                system("cls");
                switch (semester)
                {case 1: 
                      printf("Here are your 1st semester courses\n");
                      printf("Courses                                         Units\n");
                      printf("ENGL 001(Communication Arts 1)                  3.00\n");
                      printf("FIL 001(Komunikasyon sa Akademikong Filipino)   3.00\n");
                      printf("MATH 001(College Alegbra)                       3.00\n");
                      printf("MATH 002(Plane and Spherical Trigonometry)      3.00\n");
                      printf("NSTP 001(National Service Training Program)     3.00\n");
                      printf("CHEM 001(General Chemistry)                     4.00\n");
                      printf("COE 001(Engineering Orientation)                1.00\n");
                      printf("AR 001(Engineering Drawing)                     1.00\n");
                      printf("PE 001(Physical Fitness)                        2.00\n");
                      printf("                                    Total units: 20\n");
                      printf("Ready to register courses.\n");
                      printf("Enter any number to proceed: ");
                      scanf("%d", &units);
                      system("cls");
                      if(units>=0){
                                   printf("FEES                      AMOUNT\n");
                                   printf("Tuition Fee              23,000.00\n");
                                   printf("\n");
                                   printf("Miscellaneous Fees\n");
                                   printf("Laboratory Fee            1,250.00\n");
                                   printf("Athletics Fee               670.00\n");
                                   printf("Audio Visual Fee            115.00\n");
                                   printf("Computer Fee              2,300.00\n");
                                   printf("Cultural and Activity        50.00\n");
                                   printf("Development Fee             720.00\n");
                                   printf("Energy Fee                  760.00\n");
                                   printf("Guidance&Counselling        450.00\n");
                                   printf("Insurance Fee                11.00\n");
                                   printf("Internet Fee                 90.00\n");
                                   printf("Library Fee               1,315.00\n");
                                   printf("Medical/Dental Fee          450.00\n");
                                   printf("Red Cross Fee                 1.00\n");
                                   printf("Registration Fee            450.00\n");
                                   printf("Student Council Fee          35.00\n");
                                   printf("Student Development Fee     160.00\n");
                                   printf("Test Paper Fee              210.00\n");
                                   printf("                 TOTAL FEES:31,586.00\n");
                                   printf("*1 unit is equals to 1150.00 pesos*\n");
                                   printf("Enter any key to continue: ");
                                   scanf("%d", &units);
                                   system("cls");
                                   printf("Choose mode of payment\n");
                                   printf("1)CASH\n");
                                   printf("2)INSTALLMENT\n");
                                   printf("Enter the number of your choice: ");
                                   scanf("%d", &cash);
                                   system("cls");
                                   switch(cash)
                                   { case 1: printf("Your TOTAL FEE is 31,586.00\n");
                                             printf("Please Proceed to the Treasure for the payment\n");
                                             printf("Thank you for using MIT enrollment system! :)");
                                             break;
                                     case 2: printf("Your TOTAL FEE for INSTALLMENT is 33,886.00\n");
                                     printf("*Installment payment has a charge of 2300.00 pesos\n");
                                     printf("Downpayment is 3500\n");
                                     printf("You must pay the balance during Prelims, Midterms and Finals.\n");
                                     printf("In Every Term you must pay 10,128.00 in the treasury office.\n");
                                     printf("Thank you for using MIT Enrollment System! :)");
                                     break;
                                     default:
                                             printf("INVALID INPUT");}
                                   }

                                   else {
                                   printf("INVALID INPUT");}
                                   }
                                   break;





         case 4:
                    {printf("Here are your 2nd semester subjects\n");
                      printf("Courses                                              Units\n");
                      printf("ENGL 002(Communication Arts 2)                       3.00\n");
                      printf("FIL 002(Pagbasa at Pagsulat Tungo sa Pananaliksik)   3.00\n");
                      printf("MATH 003(Advance Alegbra)                            2.00\n");
                      printf("MATH 004(Analytic Geometry)                          3.00\n");
                      printf("MATH 005(Solid Mensuration)                          2.00\n");
                      printf("NSTP 002(National Service Training Program 2)        3.00\n");
                      printf("CPE 001(Computer Fundamentals)                       1.00\n");
                      printf("SOCSC 001(Economics, Agrarian Reform and Taxation)   3.00\n");
                      printf("HUM 001(Introduction to Philosophy)                  3.00\n");
                      printf("PE 002(Rhythmic Activities)                          2.00\n");
                      printf("                                          Total units: 22\n");
                      printf("Ready to register courses.\n");
                      printf("Enter any number to proceed: ");
                      scanf("%d", &units);
                      system("cls");
                      if(units>=0){
                                   printf("FEES                      AMOUNT\n");
                                   printf("Tuition Fee             25,300.00\n");
                                   printf("\n");
                                   printf("Miscellaneous Fees\n");
                                   printf("Laboratory Fee            1,250.00\n");
                                   printf("Athletics Fee               670.00\n");
                                   printf("Audio Visual Fee            115.00\n");
                                   printf("Computer Fee              2,300.00\n");
                                   printf("Cultural and Activity        50.00\n");
                                   printf("Development Fee             720.00\n");
                                   printf("Energy Fee                  760.00\n");
                                   printf("Guidance&Counselling        450.00\n");
                                   printf("Insurance Fee                11.00\n");
                                   printf("Internet Fee                 90.00\n");
                                   printf("Library Fee               1,315.00\n");
                                   printf("Medical/Dental Fee          450.00\n");
                                   printf("Red Cross Fee                 1.00\n");
                                   printf("Registration Fee            450.00\n");
                                   printf("Student Council Fee          35.00\n");
                                   printf("Student Development Fee     160.00\n");
                                   printf("Test Paper Fee              210.00\n");
                                   printf("                 TOTAL FEES:33,886.00\n");
                                   printf("*1 unit is equals to 1150.00 pesos*\n");
                                   printf("Enter any key to continue: ");
                                   scanf("%d", &units);
                                   system("cls");
                                   printf("Choose mode of payment\n");
                                   printf("1)CASH\n");
                                   printf("2)INSTALLMENT\n");
                                   printf("Enter the number of your choice: ");
                                   scanf("%d", &cash);
                                   system("cls");
                                   switch(cash)
                                   { case 1: printf("Your TOTAL FEE is 33,886.00\n");
                                             printf("Please Proceed to the Treasure for the payment\n");
                                             printf("Thank you for using MIT enrollment system! :)");
                                             break;
                                     case 2: printf("Your TOTAL FEE for INSTALLMENT is 36,186.00\n");
                                     printf("*Installment payment has a charge of 2300.00 pesos\n");
                                     printf("Downpayment is 3500\n");
                                     printf("You must pay the balance during Prelims, Midterms and Finals.\n");
                                     printf("In Every Term you must pay 10,895.00 in the treasury office.\n");
                                     printf("Thank you for using MIT Enrollment System! :)");
                                     break;
                                     default:
                                             printf("INVALID INPUT");}
                                   }
                                   else {
                                   printf("INVALID INPUT");}
                                   }
                                   }


                break;

        default:
                printf("Invalid choice\n");
                break;
    }

    getch();

read more