2024 React Trends

2024 React Trends

# 2024 React Trends

With the rapid development of technology, React, as a leading front-end framework, has won widespread recognition and application worldwide. Looking ahead to 2024, how will the development trend of React evolve? This article will analyze the potential changes of React in future technology dynamics, application areas, and community ecology, in order to provide valuable reference and inspiration.

# React 19 is coming

After more than 600 days of suspension, React revealed in its blog that it will release React 19 in 2024. The article also mentioned that the React team is developing a new compiler that will automate all caches in React applications. This means that the process of manually caching functions ( useCallback ), values ( useMemo ), and components ( memo ) in the past is expected to be eliminated in the future. React will be responsible for handling these caches, thus avoiding recalculating everything every time it is rendered.

After the release of React 19, these APIs may no longer be needed.

  • useMemo , useCallback , memo → React Compiler: React’s new compiler will replace these hooks for optimization and caching.
  • forwardRef ref as a prop : ref will be passed directly as a property, no longer forwardRef .
  • React.lazy → RSC, promise as child element: The lazy loading function of React will be replaced by RSC or components with child element Promise.
  • useContext use (Context) : (Using Context will become more concise, possibly through a new use function.
  • Throw promise → use (promise) : There will be a new use function for handling exceptions thrown in Promises.
  • < Context. Provider > < Context > : Providing Context will become more concise and may be implemented directly through the Context component.

# Astro + React

Last year, Astro emerged as a strong competitor to Gatsby, initially targeting static website design. However, due to its rapidly accumulating popularity and growing functionality, Astro began actively exploring the possibilities of web applications and API endpoints. Although Astro remains an ideal choice for high-performance websites, web developers have also begun to consider applying it to a wider range of use cases beyond its original scope.

Astro-built websites have high performance by default because they avoid unnecessary JavaScript from scratch and transfer high-cost rendering work to the server. Although static site generation (SSG) is the default option, server-side rendering (SSR) can still be selected.

Astro is not limited to React. You can directly use Astro’s native way to build UI components in the “.astro” file without the need for a UI framework. At the same time, Astro is also compatible with various component frameworks, such as React, allowing you to fully utilize your rich experience to create rich and exquisite UI components.

Even when used in conjunction with frameworks like React, Astro does not introduce JavaScript and only transmits HTML and CSS to the browser. Only when components need to interact, the server will send necessary JavaScript to the client on demand. All of this is closely related to Astro’s “default high performance” concept, driven by its rendering mode called Island architecture.

img

With the help of Astro, the achieved projects not only demonstrate excellent performance and SEO scores, but also feature beautiful themes and convenient document functions provided by Astro Starlight. In the future, this advanced method will gradually become the mainstream standard for website construction. Looking forward to Astro continuing to bring me unprecedented innovation and infinite possibilities in the future.

# Build tools: Vite vs Turbopack

Turbopack was jointly created by the founders of Vercel and Webpack, aiming to be the successor to Webpack. Although it has not yet been fully put into production, it has shown its potential in the local Development Environment of Next.js. Turbopack not only brings together the experience accumulated by Webpack for many years, but also achieves a qualitative leap through a new architecture based on Rust. For example, Tree Shaking and caching functions that were once overlooked in Webpack have received key support in Turbopack.

img

With the development of technology, the role of building tools has become increasingly important. The interweaving of client and server level components, intelligent caching of application entry points, and the demand for component-level data acquisition have all put forward higher requirements for building tools. Therefore, Vercel deeply feels the need for a new type of building tool to cope with these challenges.

Personally, I had hoped that Vite and its powerful server-level capabilities could be integrated into Next.js. However, despite Vite being favored by many meta-frameworks (such as Remix) and Single Page Applications in the past year, the Vercel/Next team chose to develop Turbopack as their solution. This decision undoubtedly demonstrates their pursuit of technological innovation and unique insights into future packaging technology.

# React state management

Although React state management has been a long-standing topic, with the emergence of new solutions (such as Signals, Zustand, and Recoil), they handle state management in a different way from traditional methods (such as Redux and React Hooks), making it still a hot topic in the React developer community. Let’s briefly review the two main competitors below.

  • Redux, as a state container for JS applications, is closely integrated with React through React-Redux. However, developers have different opinions on the utility of Redux. Some believe that it is still a powerful tool for state management, while others believe that although it is effective, it is not always necessary, especially in small and medium-sized applications. With the continuous development of the React ecosystem, there seems to be a consensus forming: Redux is more suitable for large and complex applications.
  • React Hooks (such as useState and ReactContext ) provide a neat solution for sharing state across applications. However, there are certain rules to follow when using Hooks, which can be confusing for beginners and even difficult for experienced developers to achieve perfect state management.

Due to these complexities and potential limitations, more and more developers are looking for lighter and more concise state management solutions. For example, Zustand is a library worth paying attention to, which solves problems in a similar way to Redux, but with less code and easier understanding and use. In fact, Zustand topped the list of state management libraries in this year’s JavaScript Rising Stars Report, which fully demonstrates its popularity and potential.

img

Besides Zustand, there are other high-profile state management libraries such as Recoil, MobX, and Jotai. These libraries each have unique features and advantages, providing React developers with more choices and possibilities.

img

Signals, a state management pattern that has been around for several years, has still sparked heated discussions in the React community. Through the Preact library, Signals now supports React, aiming to solve the pain points of Hooks and complex state management libraries such as Redux. It simplifies the process of storing and updating values across applications, and only renders components that have changed, improving efficiency.

In 2024, React state management may evolve towards lightweight, integration and compatibility, better developer experience, customization and flexibility, and integration with other technologies.

# React Server Components and Next.js

React Server Components (RSCs) is a new specification launched by the React team, including its underlying implementation. It was implemented and first adopted by the community through version 13.4 of Next.js last year. Regardless of external discussions and challenges, RSCs undoubtedly brought a huge paradigm shift to web development.

img

Compared to React Hooks, RSCs may bring more profound changes because they encourage developers to rethink how to use React components in large applications. In Next.js and its new App Router, RSCs have become the new standard for every React developer. As more and more frameworks (even beyond the boundaries of React) explore the adoption (and implementation) of Server Components, emerging small frameworks such as Waku have taken the lead in implementing this technology.

This new architecture brings many advantages. Although it is difficult to list them one by one, an example can be given to illustrate: RSCs allow developers to perform component-level data acquisition on the server before sending components to the browser (or through streaming). This means that the once troublesome client-to-server network waterfall requests have become history. Nowadays, these requests (if they exist) are completed more quickly on the server, significantly improving performance.

Emphasizing the advantage of RSCs is crucial because it reveals how the React ecosystem must adapt to it. Tools such as tRPC and react-query play a key role in client-server communication. However, in a world without APIs, what role these tools will play when RSCs perform most data retrieval on servers has become a key issue. Although some Proof of Concept have emerged, we still look forward to how this field will continue to develop in 2024.

# Biome

Although ESLint and Prettier play a crucial role in web development, their setup and collaboration processes often make developers feel tricky. Nevertheless, these tools are still essential for daily work. Biome (formerly known as Rome) is committed to breaking new ground in this field by providing fast and comprehensive toolchain solutions. Another highly anticipated all-in-one toolchain is oxc.

Biome won a $20,000 prize from Prettier for its ability to create more efficient formatters in Rust. However, it remains to be seen whether developers will adopt this new tool. Meanwhile, discussions about getting rid of the strict dependence on ESLint and allowing the use of other linters are raging on multiple platforms, such as the Next.js GitHub discussion area.

img

I am looking forward to this project. If it succeeds, it may become an efficient toolchain that drives all the necessary functions of modern web application development.

# TanStack Router Helps Build Single Page Applications

Despite the increasing popularity of React Server Components, Tanner Linsley, the main promoter of popular React libraries such as react-query and r eact-table, believes that Single Page Application (SPA) is not outdated. Recently, he has released a new library: TanStack Router.

img

The release timing of TanStack Router is just right, filling an important gap in the React ecosystem. Although many developers have adopted meta-frameworks such as Next.js and Remix (which have built-in routers and focus on implementing RSCs), so far, no one has created type-safe routes for React.

With TypeScript becoming an industry standard in the past few years, I am excited about this new router in the React ecosystem because it provides excellent TypeScript support. For example, it will allow developers to read and write URL states in a type-safe manner. Perhaps this new router will also push other mature routers to meet these top TypeScript standards.

# React Authentication

With multiple startups and open source projects entering the identity verification field, the identity verification function in React has ushered in new vitality. For a long time, solutions such as Firebase Authentication, Auth0, Passport.js, and NextAuth have been firmly in the mainstream position, but now we have ushered in a new cost-effective alternative driven by User Interface.

Supabase, as an open-source alternative to Google Firebase, not only provides comprehensive authentication capabilities, but also integrates diverse tools such as PostgreSQL database, real-time subscription, storage, and serverless functions. It can be self-hosted or used as a paid service. Although many developers use Supabase for authentication, in other fields, they may choose more suitable services, such as PlanetScale as a serverless database.

img

Clerk focuses on the field of identity verification, making the user registration and login process easy and convenient through the Plug and Play component provided for React. In addition, Clerk also provides user management and role assignment functions, supporting single or multiple organizations. For startups, Clerk is undoubtedly an ideal choice for building Minimum Viable Products (MVP).

Finally, we cannot ignore the power of Lucia. Although it is popular due to its combination with Astro, it can also play a role in other frameworks. Lucia’s open source nature, community support, and clear abstraction layer between applications and databases are impressive. Especially its ability to manage users in its own database is undoubtedly a huge advantage compared to other authentication services.

# React Headless UI Library

The React community’s choice of UI libraries has been changing year by year. From Material UI a few years ago, to Semantic UI/Ant Design, to Chakra UI and Mantine UI, and finally last year, the focus was on shadcn/UI. Although these choices are based on design and usability considerations, shadcn/UI has shown its uniqueness.

Shadcn/UI has become a popular UI library, innovatively using Tailwind as a core component (alongside CSS variables) for theme customization to achieve highly customizable design goals. Unlike conventional installation methods, shadcn/UI is not installed as a Node package, but directly copied and pasted into the project, allowing developers to freely adjust components to meet unique needs.

img

The trend of this headless UI library did not originate from shadcn/UI, but from developers’ desire for unique design and User Experience. When relying on popular UI libraries, achieving unique designs often faces challenges.

It is worth mentioning that in order to improve performance and User Experience, more and more components are being rendered on the server side. This trend limits the use of CSS-in-JS solutions (such as Styled Components and Emotion), as these solutions rely on the Client/Browser to execute JavaScript to generate CSS, increasing the performance burden. In contrast, emerging CSS-in-JS solutions (such as StyleX) effectively solve this problem by compiling CSS as a practical priority.

With the development of this trend, we look forward to seeing more innovative UI libraries and CSS paradigms emerge. Currently, headless UI libraries (such as Radix and shadcn/UI) and practical CSS (such as Tailwind) have emerged, and in the future, there may be more alternatives such as vanilla-extract, PandaCSS, CVA, etc., providing more choices and possibilities for web developers.

Rust is fully invading the front-end

Rust is fully invading the front-end

# Rust is fully invading the front-end

I have studied the basics of Rust and some ecological technical solutions solidly and systematically. The original intention of learning it is because Rust can support the native-level development of HarmonyOS applications and provide technical reserves for advanced HarmonyOS developers.

But if you don’t learn, you won’t know, and you’ll be shocked when you learn. Only then did you realize that the Rust ecosystem is invading all aspects of front-end development with an unstoppable momentum, all-round and no dead ends . The most critical thing is that due to the latecomer advantage, these technical solutions are often more advanced, more scientific, and have higher performance than existing front-end solutions…

# Farm

img

Farm is an extremely fast build engine written in Rust. In its promotional documentation, it claims to be more than 10 times faster than Webpack and 5 times faster than Vite. Obviously, this is a front-end project build tool that wants to accurately target Vite.

Due to Vite adopting a compile-on-request strategy for modules in the project and not bundling the source code, according to the experience of the Byte Architecture team, when the project is huge, the first page loading time of Vite may be as long as tens of seconds “when the page is first loaded, a large number of modules are loaded”, it is extremely slow when refreshing, and the huge request volume may cause the browser to crash, affecting the development experience.

And vite in the Development Environment using esbuild pre-compile, in the generation environment using bundler rollup, the processing is different, occasionally there may be Development Environment and online behavior inconsistent situation , once inconsistent, it means a huge troubleshooting cost.

In response to the pain points of Vite, Farm uses Rust to re-implement the compile capability of CSS/TS/JS/Sass , which can achieve millisecond-level project launch. For most cases, it can control the HMR time within 10ms.

# Turbopack

img

Compared to Farm, Turbopack is more trustworthy and has received more attention due to the support of next.js.

img

Turbopack is also a front-end project building tool based on Rust. Turbopack is built on a new incremental architecture, and only focuses on the minimum resources required for development when packaging, so whether it is startup speed or HMR speed, it has far better performance than Vite.

On an application with 3000 modules, Turbopack only takes 1.8 seconds, while Vite takes 11.4 seconds.

img

Turbopack is provided by the Vercel team, focusing on improving the speed of Next.js packaging tool. And the future goal is to replace webpack and become the new generation of front-end packaging tool. Therefore, the maturity and popularity of Next.js will also drive Turbopack to become a more reliable packaging tool.

# Rspack

img

Rspack is a project packaging tool provided by the Byte team. Like Turbopack, it fully utilizes the performance advantages of the Rust language and has significantly improved packaging speed.

However, unlike Turbopack, Rspack has chosen a route that prioritizes compatibility with the webpack ecosystem. On the one hand, these compatibility may bring certain performance overhead, but in actual business implementation, this performance overhead is acceptable. On the other hand, these compatibility also enable Rspack to better integrate with upper-level frameworks and ecosystems, enabling gradual business migration.

Currently, the development team of Rspack is also actively recruiting. Obviously, they have a very clear plan for future development.

img

# Vite is refactoring with rust

Vite, as a new generation of high-performance packaging tool, really amazed everyone when it first appeared. But it couldn’t resist the various crazy roll kings using Rust to overtake. Instead, Vite became the background board, being pressed on the ground and rubbed crazily. Therefore, in order not to be suppressed too much in performance, the Vite team is developing various alternative solutions based on Rust to solve Vite’s current pain points.

Rolldown

img

The Vite team is developing Rolldown and has open-sourced it. It is an alternative to Rollup developed using Rust. Its focus will be on local-level performance while maintaining compatibility with Rollup. The ultimate goal is to quietly switch to Rolldown in Vite with minimal impact on Vite users.

However, at present, there is a lot of pressure for Vite to achieve the goal of rust refactoring. Therefore, the Vite team has planned four stages to promote this

\1. Replace esbuild 2. Replace Rollup 3. Use Rust to achieve built-in conversion of common requirements, such as compile ts , JSX, etc 4. Refactor Vite completely with Rust

# Leptos

img

Leptos is a Rust-based React/Solid framework. It also implements fine grain-level reactive updates based on signal.

The basic grammar is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
#[component]
fn App() -> impl IntoView {
let (count, set_count) = create_signal(0); view! {
<button
on:click=move |_| set_count.update(|n| *n += 1)
>
"click me"
</button> <p>
<strong>"Reactive"</strong>
{count}
</p>
}
}

It is very similar to Solid in terms of grammar. However, in terms of grammar details, it is designed more reasonably than Solid. It has more intuitive thinking in semantics. This means that Leptos does a better job of compiling based on rust.

1
2
3
4
5
6
7
8
9
10
11
#[component]
fn ProgressBar(
#[prop(default = 100)]
max: u16,
#[prop(into)]
progress: Signal<i32>
) -> impl IntoView {
view! {
<progress max=max value=progress />
}
}

Although Leptos is designed to be advanced and has strong performance, it is based on Rust and has a very high cost to get started, so it may encounter a lot of difficulties in promotion. However, this still cannot stop the enthusiasm of many programmers for it.

I am also one of the developers who really like Leptos, and I regard it as one of the main projects to familiarize myself with Rust syntax learning. Because this is a field that we front-end developers are more familiar with, mastering Rust through it can achieve twice the result with half the effort.

Of course, there is still a lot of potential in the tool that I have not fully explored, such as the official documentation claiming to be a full Stack framework, but because I have not yet digested it, I need to further learn to understand it.

# dioxus

img

Dioxus is a more ambitious cross-platform client development framework, and at the same time, it can achieve full stack development. It has some similarities with Leptos in implementation principles and syntax design, but it is completely different in UI syntax performance

A simple example can be seen

1
2
3
4
5
6
7
fn app() -> Element {
let mut count = use_signal(|| 0); rsx! {
h1 { "High-Five counter: {count}" }
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
}
}

From this grammar design, it can be seen that it aims to unify the world. It attempts to cover all scenarios such as web development, mobile end app development, and desktop app development.

img

The simple and practical feeling is that the framework has the suspicion of over-imitating React, so that I, who is familiar with React, can learn it more easily than Leptos.

# Tauri

img

Tauri is an alternative to Electron.

Electron has two main pain points, one is that the package size is too large, and the other is that memory consumption is severe. Therefore, its alternative solutions are endless. Unlike the several Rust frameworks introduced earlier, Tauri’s development has become mature and has been applied in many commercial projects.

Most importantly, I have started to let my students learn it and use it as a core project highlight to cope with the increasingly competitive interview scene. And the effect is not bad. Judging from the interview results in the past six months, many domestic companies have begun to pay attention to the benefits brought by Tauri.

Due to Rust abandoning the huge size of Chromiun and Node.js, for the same project, the packaging size can be reduced from 60M in Electron to 4M, and memory consumption can also be reduced from 500M to around 150M.

# Servo

img

This is a browser project based on Rust development and aimed at replacing Chrome. The project was an experimental project developed by Mozilla in the early days. Due to limited funds, it was put on hold for a long time. Now, with Rust becoming popular, it is ready to step up its efforts and the recent version iteration is very fast. At this time, Servo has been taken over by the Linux Foundation.

Servo attempts to create a large-scale parallel computing page rendering mode to accelerate rendering, layout, HTML parsing, image decoding, etc. Tests on the Arm architecture show that Servo’s performance is significantly better than Chromium.

Then I downloaded this browser to play with it, but found out that it was still a rudimentary version. Basic UI functions had not been developed yet, and many page layouts still had problems with disorder.

It can only be said that it is temporarily worth paying attention to and has great development potential. If used, it may still be early.

# Deno

img

Deno is a JavaScript runtime built on Rust. It comes from the same boss as Node.js. The latest version of Deno is also developed on Rust.

Personally, the biggest charm of Deno lies in its direct native support for TypeScript and support for JSX/TSX. Therefore, I am very optimistic about the future development of Deno, which is getting better and better, although the current ecosystem is not yet sufficient to compete with Node.

# Summary

It is obvious that Rust is invading every aspect of the front-end. Although it is not mature enough in some aspects, it has shown potential, and in some aspects, it has already established clear advantages.

I think front-end development can no longer ignore the existence of Rust . Due to its ultra-high performance and security, Rust has been highly recognized in various fields such as “operating system level, AI, game development, server level, Inter-App communications solutions, high-performance web applications…” The community has a very high active level and the ecological development is very rapid.

Therefore, from the end of last year until now, I have been immersed in learning Rust. Overall, I feel that learning Rust from the perspective of front-end development is relatively easy. It takes about a day to learn all the basic syntax, but we need to have a very accurate understanding of memory. If you are confused about memory, it may be difficult to learn Rust.

Then we need to spend more time learning the development mindset and ecosystem of Rust. For front-end development, Leptos is a good learning and practice project.

13 Interesting Python Scripts

13 Interesting Python Scripts

Every day we face many programming challenges that require advanced coding. You can’t solve these problems with simple basic Python syntax. In this article, I will share 13 advanced Python scripts that can become easy-to-use tools in your project. If you don’t currently use these scripts, you can add them to your favorites for retention.

# Make web robots

This script will help you automate websites using Python. You can build a web robot that can control any website. Check out the code below. This script is very convenient in web crawling and web automation.

1
2
3
4
5
6
7
8
9
10
11
# pip install selenium
import time
from selenium import webdriver
from selenium.webdriver.common.keys
import Keysbot = webdriver.Chrome("chromedriver.exe")
bot.get('http://www.google.com')
search = bot.find_element_by_name('q')
search.send_keys("@codedev101")
search.send_keys(Keys.RETURN)
time.sleep(5)
bot.quit()

# Python Image Enhancement

Enhance your photos with the Python Pillow library to make them look better. In the code below, I’ve implemented four ways to enhance any photo.

1
2
3
4
5
6
7
8
9
10
11
# pip install pillow
from PIL import Image,ImageFilter
from PIL import ImageEnhance
im = Image.open('img.jpg')
# Choose your filter
# add Hastag at start if you don't want to any filter below
en = ImageEnhance.Color(im)
en = ImageEnhance.Contrast(im)
en = ImageEnhance.Brightness(im)
en = ImageEnhance.Sharpness(im)# result
en.enhance(1.5).show("enhanced")

# Get song lyrics

This advanced script will show you how to get lyrics from any song. First, you must get a free API key from the Lyricsgenius website, and then, you must follow the following code. This advanced script will show you how to get lyrics from any song. First, you must get a free API key from the Lyricsgenius website, and then, you must follow the following code.

1
2
3
4
5
6
7
8
# pip install lyricsgenius
import lyricsgenius
api_key = "xxxxxxxxxxxxxxxxxxxxx"
genius = lyricsgenius.Genius(api_key)
artist = genius.search_artist("Pop Smoke",
max_songs=5,sort="title")
song = artist.song("100k On a Coupe")
print(song.lyrics)

# Get Exif data for photos

Use the Python Pillow module to get the Exif data of any photo. Check out the code mentioned below. I provide two methods to extract the Exif data of photos.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Get Exif of Photo
# Method 1
# pip install pillow
import PIL.Image
import PIL.ExifTags
img = PIL.Image.open("Img.jpg")
exif_data =
{
PIL.ExifTags.TAGS[i]: j
for i, j in img._getexif().items()
if i in PIL.ExifTags.TAGS
}
print(exif_data)
# Method 2
# pip install ExifRead
import exifread
filename = open(path_name, 'rb')
tags = exifread.process_file(filename)
print(tags)

# Search on google

You can extract Retargeting URL from Google search engine , install the following mention module and follow the code.

1
2
3
4
5
# pip install google
from googlesearch import search
query = "Medium.com"
for url in search(query):
print(url)

# Conversion: hexadecimal to RGB

The script will simply convert Hex to RGB . Check out the sample code below.

1
2
3
4
5
6
# Conversion: Hex to RGB
def Hex_to_Rgb(hex):
h = hex.lstrip('#')
return tuple(int(h[i:i+2], 16) for i in (0, 2, 4))
print(Hex_to_Rgb('#c96d9d')) # (201, 109, 157)
print(Hex_to_Rgb('#fa0515')) # (250, 5, 21)

# Convert photos to Cartonize

This simple advanced script will convert your photos to Cartonize format. Check out the sample code below and give it a try.

1
2
3
4
5
6
7
8
9
10
# pip install opencv-python
import cv2
img = cv2.imread('img.jpg')
grayimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
grayimg = cv2.medianBlur(grayimg, 5)
edges = cv2.Laplacian(grayimg , cv2.CV_8U, ksize=5)
r,mask =cv2.threshold(edges,100,255,cv2.THRESH_BINARY_INV)
img2 = cv2.bitwise_and(img, img, mask=mask)
img2 = cv2.medianBlur(img2, 5)
cv2.imwrite("cartooned.jpg", mask)

# Speed Testing with Python

This advanced script helps you test your internet speed using Python. Just install the speed test module and run the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# pip install pyspeedtest
# pip install speedtest
# pip install speedtest-cli
#method 1
import speedtest
speedTest = speedtest.Speedtest()
print(speedTest.get_best_server())
#Check download speed
print(speedTest.download())
#Check upload speed
print(speedTest.upload())
# Method 2
import pyspeedtest
st = pyspeedtest.SpeedTest()
st.ping()
st.download()
st.upload()

# Site Status

You can use Python to check if the website is running normally. Check the following code, it displays 200, which means the website is launched. If it displays 404, it means the website is closed.

1
2
3
4
5
6
7
8
9
10
# pip install requests
#method 1
import urllib.request
from urllib.request import Request, urlopenreq = Request('https://medium.com/@pythonians', headers={'User-Agent': 'Mozilla/5.0'})
webpage = urlopen(req).getcode()
print(webpage) # 200
# method 2
import requests
r = requests.get("https://medium.com/@pythonians")
print(r.status_code) # 200

# Extract OCR text from images

OCR is a method of recognizing text from numbers and scanned docs. Many developers use it to read handwritten data, and the following Python code can convert scanned images to OCR text format.

Note: You must download tesseract.exe from Github .

1
2
3
4
5
6
7
# pip install pytesseract
import pytesseract
from PIL import Image
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
t=Image.open("img.png")
text = pytesseract.image_to_string(t, config='')
print(text)

# Get Windows version

This simple script will help you get the full version of the window you are currently using.

1
2
3
4
5
# Window Versionimport wmi
data = wmi.WMI()
for os_name in data.Win32_OperatingSystem():
print(os_name.Caption)
# Microsoft Windows 11 Home

# Convert PDF to Image

Use the following code to convert all Pdf pages into images.

1
2
3
4
5
6
7
# PDF to Images
import fitz
pdf = 'sample_pdf.pdf'
doc = fitz.open(pdf)
for page in doc:
pix = page.getPixmap(alpha=False)
pix.writePNG('page-%i.png' % page.number)

# Empty Recycling Bin

This simple script allows you to empty your Recycle Bin with Python. Check out the code below to learn how.

1
2
3
4
5
6
7
# pip install winshell
import winshell
try:
winshell.recycle_bin().empty(confirm=False, /show_progress=False, sound=True)
print("Recycle bin is emptied Now")
except:
print("Recycle bin already empty")