Delete all files within current directory and all its subdirectories in Linux
find . -type f -name "*.vtt" -delete
find . -type f -name "*.vtt" -delete
sudo nano /etc/systemd/resolved.conf
[Resolve] DNS=1.1.1.1#cloudflare-dns.com 8.8.8.8#dns.google FallbackDNS=1.0.0.1#cloudflare-dns.com 8.8.4.4#dns.google DNSOverTLS=yes DNSSEC=yes
sudo systemctl restart systemd-resolved
resolvectl status
resolvectl query google.com
wget -qO - https://dl.xanmod.org/archive.key | sudo gpg --dearmor -vo /etc/apt/keyrings/xanmod-archive-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/xanmod-archive-keyring.gpg] http://deb.xanmod.org $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/xanmod-release.list
sudo apt update && sudo apt install linux-xanmod-x64v3
After installing XanMod, you should apply these sysctl settings specifically tuned for a high-performance VPN server:
sudo nano /etc/sysctl.conf
# Optimized for VPN Throughput net.core.default_qdisc = fq net.ipv4.tcp_congestion_control = bbr # Increase Buffer Sizes for High-Speed Tunnels net.core.rmem_max = 67108864 net.core.wmem_max = 67108864 net.ipv4.tcp_rmem = 4096 87380 67108864 net.ipv4.tcp_wmem = 4096 65536 67108864 # Improve Nginx/sing-box Connection Handling net.core.somaxconn = 65535 net.ipv4.tcp_max_syn_backlog = 65535 net.ipv4.tcp_fastopen = 3 net.ipv4.tcp_mtu_probing = 1
sudo sysctl -p
References
https://xanmod.org/
Open PowerShell as Administrator.
Click the Start Menu, type “PowerShell”, right-click on “Windows PowerShell” or “PowerShell,” and select “Run as administrator.”
Run the command: Enter the following command and press Enter:
Set-ExecutionPolicy Bypass -Scope LocalMachine
The useEffect Hook in React is a function that lets you perform side effects in functional components. A side effect is anything that affects something outside the scope of the function being executed, such as data fetching, subscriptions, or manually changing the DOM. Essentially, it’s a way to tell React that your component needs to do something after rendering.
The useEffect Hook is a great tool for managing the lifecycle of your components, allowing you to perform actions at specific points in time, like when the component first mounts, when it updates, or when it unmounts.
useEffect(setup, dependencies)
import React, { useState, useEffect } from 'react';
function MyComponent() {
const [count, setCount] = useState(0);
useEffect(() => {
// This effect runs on every render
console.log(`The count is: ${count}`);
});
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
import React, { useState, useEffect } from 'react';
function DataFetcher() {
const [data, setData] = useState(null);
useEffect(() => {
// This effect runs only once, when the component mounts
fetch('https://api.example.com/data')
.then(response => response.json())
.then(json => setData(json));
}, []); // The empty array ensures this effect runs only once
return (
<div>
{data ? <pre>{JSON.stringify(data, null, 2)}</pre> : <p>Loading...</p>}
</div>
);
}
import React, { useState, useEffect } from 'react';
function UserProfile({ userId }) {
const [user, setUser] = useState(null);
useEffect(() => {
// This effect runs whenever 'userId' changes
console.log('Fetching user data...');
fetch(`https://api.example.com/users/${userId}`)
.then(response => response.json())
.then(json => setUser(json));
}, [userId]); // The effect re-runs when userId changes
return (
<div>
{user ? <h1>User: {user.name}</h1> : <p>Select a user</p>}
</div>
);
}
import React, { useState, useEffect } from 'react';
function Timer() {
const [seconds, setSeconds] = useState(0);
useEffect(() => {
const intervalId = setInterval(() => {
setSeconds(prevSeconds => prevSeconds + 1);
}, 1000);
// This is the cleanup function
return () => {
clearInterval(intervalId);
console.log('Timer cleaned up!');
};
}, []); // Empty dependency array means this effect runs once on mount
return <h1>Seconds: {seconds}</h1>;
}
The useState hook allows a function component to have state. It returns a pair: the current state value and a function to update it.
import './App.css'
import {useState} from "react";
function App() {
// Simple numeric state for Counter 1
const [count, setCount] = useState(4);
// Object state for Counter 2 (represents a person with name and age)
const [person, setPerson] = useState({name: "John", age: 30});
// Decrement the numeric counter. Using the functional form of setState
// ensures we always operate on the latest state value.
function decrementCounter() {
setCount(prevState => prevState - 1);
}
// Increment the numeric counter (Counter 1)
function incrementCount() {
setCount(prevState => prevState + 1);
}
// Decrement the person's age. Use the spread operator to preserve other
// properties on the person object when updating nested state.
function decrementCounter2() {
setPerson(prevState => {
return {...prevState, age: prevState.age - 1}
});
}
// Increment the person's age (Counter 2)
function incrementCount2() {
setPerson(prevState => {
return {...prevState, age: prevState.age + 1}
});
}
return (
<>
{/* Counter 1: shows a simple number and two buttons to change it */}
<div>
<span>Counter 1: </span><span>{count}</span>
<button onClick={decrementCounter}>-</button>
<button onClick={incrementCount}>+</button>
</div>
{/* Counter 2: displays person object fields and buttons to update age.
Note: name is not changed here; only age is updated via setPerson. */}
<div>
<span>Counter 2: </span>
<span>Name: {person.name}, Age:{person.age}</span>
<button onClick={decrementCounter2}>+</button>
<button onClick={incrementCount2}>+</button>
</div>
</>
)
}
export default App
Using a function as the initial state parameter is a performance optimization. It’s recommended when the initial state is the result of a computationally expensive or complex calculation.
Without a function, the expensive calculation would run on every render of the component, even if the state isn’t being re-initialized. By wrapping the calculation in a function and passing that function to useState, the calculation will only run once on the first render. This prevents unnecessary work and improves performance.
// Example with a direct value (inefficient for heavy computation)
function MyComponent() {
// This function runs on every single render
const initialValue = someExpensiveCalculation();
const [data, setData] = useState(initialValue);
// ...
}
// Example with a function (lazy initializer)
function MyComponentLazy() {
// The function passed to useState is a lazy initializer.
// React will only call it once on the initial render.
const [data, setData] = useState(() => {
return someExpensiveCalculation();
});
// ...
}
References
https://react.dev/reference/react/useState
sudo nano /etc/systemd/system/battery-charge-limit.service
[Unit] Description=Set the battery charge limit to 80% After=multi-user.target [Service] Type=oneshot ExecStart=/bin/bash -c 'echo 60 > /sys/class/power_supply/BAT0/charge_control_end_threshold' [Install] WantedBy=multi-user.target
sudo systemctl daemon-reload sudo systemctl enable battery-charge-limit.service sudo systemctl start battery-charge-limit.service
sudo nano /etc/sysctl.conf
fs.file-max = 65535 fs.inotify.max_user_watches = 524288
sudo sysctl -p
sudo nano /etc/security/limits.conf
# add following lines to it * soft nproc 65535 * hard nproc 65535 * soft nofile 65535 * hard nofile 65535 root soft nproc 65535 root hard nproc 65535 root soft nofile 65535 root hard nofile 65535
sudo nano /etc/pam.d/common-session
# add this line to it session required pam_limits.so
The provided Go code sets up a simple web server that serves static files from a directory named public. It listens on port 8080.
func main() {
http.Handle("/", http.FileServer(http.Dir("public")))
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatalf("Server failed to start: %v", err)
}
}
To install a package, open your terminal or command prompt and run the following command:
go get [package path]
For example, to install the popular Chi router package, you would type:
go get github.com/go-chi/chi/v5
After you run this command, Go automatically downloads the package and its dependencies and adds them to your go.mod file, which tracks your project’s dependencies.
Since Go version 1.11, the official way to manage dependencies is with Go Modules. When you install a package with go get, Go automatically updates your project’s go.mod and go.sum files.
go.mod: Lists your project’s direct and indirect dependencies with their specific versions.
go.sum: Contains cryptographic checksums of the module dependencies to ensure their integrity.If you are inside a Go module (a directory with a go.mod file), go get updates that module. If you are not in a module, go get simply installs the package into a global cache. However, it’s best practice to always work within a Go module. You can initialize a new module with go mod init [module path].