Skip to content

Instantly share code, notes, and snippets.

View smarteist's full-sized avatar
🙂
I may be slow to respond.

Ali Hosseini smarteist

🙂
I may be slow to respond.
View GitHub Profile
@smarteist
smarteist / extractHrefsAsBashArray.js
Last active February 21, 2025 16:59
extractHrefsAsBashArray
(function extractHrefsAsBashArray() {
const domain = window.location;
const links = document.querySelectorAll('body main.container div.list table.table tbody tr td a');
const hrefsArray = Array.from(links).map(link => {
const href = link.getAttribute('href');
return href ? (href.startsWith('http') ? href : domain + href) : '';
}).filter(href => href);
console.log(`urls=(\n ${hrefsArray.map(href => `"${href}"`).join('\n ')}\n)`);
})();
@smarteist
smarteist / .wezterm.lua
Last active January 14, 2025 18:25
My wezterm conf
local wezterm = require('wezterm')
local bell_sent = false
-- Window focus event handler: Resets the bell_sent flag when the window gains focus
wezterm.on('window-focus-changed', function(window, has_focus)
if has_focus then
bell_sent = false
end
end)
@smarteist
smarteist / kitty.conf
Last active January 10, 2025 13:46
My kitty conf
# Colors
background_opacity 0.95
#foreground #d2d7d7
#background #120e0a
#cursor #d2d7d7
#active_tab_foreground #120e0a
#active_tab_background #d2d7d7
#inactive_tab_foreground #d2d7d7
#inactive_tab_background #120e0a
#!/bin/bash
set -euo pipefail
exclude_networks=("1.2.3.4" "1.2.3.0/24")
for net in "${exclude_networks[@]}"; do
if sudo ip route del "$net" 2>/dev/null; then
echo "Deleted existing route for $net"
fi
done
@smarteist
smarteist / RepositoryMechanisms.kt
Last active October 9, 2024 09:55
Repository caching mechanisms
/**
* Cache-Aside (Lazy Loading): Read from cache and return it, then update the cache later.
*/
fun getUserConfigLazily(): Flow<UserConfig?> = flow {
emitAll(local.getUserConfigAsFlow())
if (onlineChecker.isOnline) {
val remoteConf = remote.getUserConfig()
if (remoteConf != null) {
local.updateUserConfig(remoteConf)
}
@smarteist
smarteist / RetryPolicyInterceptor.java
Last active September 8, 2024 15:40
its a retry policy interceptor for retrofit.
import android.util.Log;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
import java.net.SocketTimeoutException;
public class RetryPolicyInterceptor implements Interceptor {
sudo rm /usr/lib/python3.*/EXTERNALLY-MANAGED
@smarteist
smarteist / downloader.sh
Last active September 6, 2024 15:53
bash downloader via curl
#!/bin/bash
# Define the list of URLs
urls=(
"https://example.com/file1.mkv"
"https://example.com/file2.mp3"
)
# Resumable downloader function
download_file() {
@smarteist
smarteist / sshproxy.sh
Last active October 17, 2024 19:31
This script runs ssh proxy in local socks5 port 1080
#!/bin/bash -i
user="root"
pass="@PASS@@@@"
ip_address="111.111.11.11"
ssh_port=22
sudo_pass_file="/tmp/sshpass"
proxy_port=1080

In Linux, groups are a collection of users. They are used as a means to manage and control access to resources such as files and directories. By assigning appropriate permissions to groups rather than individual users, system administrators can more efficiently manage access rights.

find /path/to/base/dir -type d | xargs chmod 755
find /path/to/base/dir -type f | xargs chmod 644

or changing files with specific extention:

find /path/to/base/dir -iname "*.php" | xargs chmod 644