Git Guide 1: How to Apply Changes

Written by artwalker | Published 2024/02/22
Tech Story Tags: git | github | how-to-apply-changes-in-git | how-do-i-apply-changes-in-git | git-tutorial | git-for-beginners | appling-changes-in-git | git-apply-changes-guide

TLDRimport 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.via the TL;DR App

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")


Written by artwalker | Passionate about Crafting Intelligent OS & Pioneering TinyML Applications for Resource-Constrained Devices
Published by HackerNoon on 2024/02/22