paint-brush
Git Guide 1: How to Apply Changesby@artwalker
125 reads

Git Guide 1: How to Apply Changes

by Ethan WangFebruary 22nd, 2024
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

import psutildef check_cpu_ usage(percent): usage = psutil.cpu_percent() return usage < percent if not check_CPU_ Usage(75): print("ERROR CPU is overloaded") else: print("Everything ok") diff -u cpu_ usage.py cpu_usage.diff$ cat cpu_ Usage.py.
featured image - Git Guide 1: How to Apply Changes
Ethan Wang HackerNoon profile picture

Command:

$ cat cpu_usage.py 

Code output:

#!/usr/bin/env python3

import psutil

def check_cpu_usage(percent):

    usage = psutil.cpu_percent()

    return usage < percent

if not check_cpu_usage(75):

    print("ERROR! CPU is overloaded")

else:

    print("Everything ok")

Command:

$ diff -u cpu_usage.py cpu_usage_new.py > cpu_usage.diff
$ cat cpu_usage.diff 

Code output:

--- cpu_usage.py	2019-06-23 08:16:04.666457429 -0700

+++ cpu_usage_fixed.py	2019-06-23 08:15:37.534370071 -0700

@@ -2,7 +2,8 @@

 import psutil

 

 def check_cpu_usage(percent):

-    usage = psutil.cpu_percent()

+    usage = psutil.cpu_percent(1)

+    print("DEBUG: usage: {}".format(usage))

     return usage < percent

 

 if not check_cpu_usage(75):

Command:

$ patch cpu_usage.py < cpu_usage.diff

Code output:

patching file cpu_usage.py

Command:

$ cat cpu_usage.py

Code output:

#!/usr/bin/env python3

import psutil

def check_cpu_usage(percent):

    usage = psutil.cpu_percent(1)

    print("DEBUG: usage: {}".format(usage))

    return usage < percent

if not check_cpu_usage(75):

    print("ERROR! CPU is overloaded")

else:

    print("Everything ok")