Posts

MySQL search value methods

If you want to find a specific value anywhere in a MySQL database (any column, any table), there are a few common approaches—ranging from quick-and-dirty to more systematic. 1️⃣ Search a known table but any column If you know the table but not the column: SELECT * FROM your_table WHERE col1 = 'value' OR col2 = 'value' OR col3 = 'value'; ⚠️ This requires you to list columns manually. 2️⃣ Search all columns of all tables (automatic way) This is the practical solution when you have no idea where the value lives. Step 1: Generate search queries using INFORMATION_SCHEMA SELECT CONCAT( 'SELECT "', TABLE_NAME, '" AS table_name, "', COLUMN_NAME, '" AS column_name FROM ', TABLE_SCHEMA, '.', TABLE_NAME, ' WHERE ', COLUMN_NAME, ' = ''your_value'';' ) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'your_database'; This generates SQL statem...

Join vs Model vs Relationship in Laravel

Understanding SQL joins, Eloquent relationships, and model accessors. 1) Join (Database level) A join is a database operation used to combine rows from multiple tables. It happens at the SQL level and is focused on performance and filtering. Example: SELECT users.name, posts.title FROM users JOIN posts ON posts.user_id = users.id; Runs in the database Returns raw rows Very fast 2) Relationship (Eloquent ORM level) A relationship defines how models are connected. It represents business meaning, not just raw data. class User extends Model { public function posts() { return $this->hasMany(Post::class); } } Usage: $user->posts; Returns model objects Supports lazy & eager loading Encodes domain logic 3) Model Accessor (Presentation level) An accessor is a computed attribute on a model. It does not fetch data from the dat...

Check Change Files in Git

You can compare only the files that differ between your current local branch and another branch on the remote using Git. Here are the most common and useful ways, from simplest to more detailed. 1. List only the changed files (most common) git fetch origin git diff --name-only origin/other-branch If you want to be explicit about your current branch: git diff --name-only origin/other-branch..HEAD ➡️ Shows only file paths that are different. 2. List changed files with change type (added / modified / deleted) git diff --name-status origin/other-branch..HEAD Example output: M src/app.js A src/new-file.ts D src/old-file.css 3. Compare against the common ancestor (recommended for PR-style comparison) This avoids noise from changes made in the target branch after you branched. git diff --name-only origin/other-branch...HEAD ... (three dots) means: changes on your branch since it diverged from the other branch This is usually what you want when prepari...

Compare local files with remote Git repo using WinMerge

Here’s a clean step-by-step way to compare your local WSL repo folder vs the remote repo state in WinMerge , and then show only changed files . 1) In WSL: go to your repo and fetch remote cd /path/to/your/repo git fetch origin 2) In WSL: create a “remote snapshot” folder (safe, no checkout) This exports the remote branch into a temp folder. REMOTE_BRANCH=origin/main SNAP=/tmp/repo_remote_snapshot rm -rf " $SNAP " mkdir -p " $SNAP " git archive " $REMOTE_BRANCH " | tar -x -C " $SNAP " Change origin/main if your remote branch is different (e.g. origin/master , origin/develop ). 3) Open WinMerge and start a folder compare Launch WinMerge (on Windows) File → Open… (or “Open”) Select Folder Compare 4) Pick the two folders (WSL paths via \\wsl$ ) In WinMerge: Left (Local working folder) Use your actual repo path in WSL: \\wsl$\Ubuntu\home\<youruser>\ path \ to \your\repo Right (Remote snapshot folder) \\wsl $ \Ubu...

Revert Git to last commit

  If you want to revert everything back to the last commit and discard all local changes , use this 👇 🔥 Hard reset (most common & safest) This restores your working tree and index to the latest commit . git reset --hard HEAD What this does ❌ Discards all modified files ❌ Discards all staged files ❌ Discards all untracked changes in tracked files ✅ Leaves your repo exactly as the last commit 🧹 Also remove untracked files (optional but often needed) If you also want to delete untracked files and folders : git clean -fd Or preview first (recommended): git clean -fdn ✅ One-liner (full nuclear option) git reset --hard HEAD && git clean -fd ⚠️ Important warning This is irreversible unless: Changes were committed Or stashed Or still exist elsewhere

"Unpushed" from Git remote branch

✅ SAFE (Recommended): Revert the pushed commit Find the commit you pushed git log --oneline Copy the commit hash (e.g. abc1234 ). Revert that commit git revert abc1234 Git creates a new commit that undoes the changes. If multiple commits: git revert abc1234..HEAD Push the revert git push ✅ Best practice for shared branches ⚠️ DANGEROUS (Only if you are 100% sure) Use this only if you are the only one working on the branch or it’s a personal feature branch: Reset and force-push git reset --hard HEAD~1 git push --force This will remove the commit locally and rewrite remote history ❌. If the pushed commit was a deletion and you want to restore a file: git checkout HEAD~1 -- path/to/file git commit -m "Restore accidentally deleted file" git push Which one should YOU use? Situation Command Shared branch git revert <commit> ...

Revert file from Git remote branch

You can revert just that single file from other remote branch without touching anything else. Option 1: Restore file from remote branch (recommended) git fetch origin git checkout origin/[remote_branch] -- file_path_in_GIT This will: Take the version of the file from remote origin/[remote_branch] Overwrite your local copy Leave you on your current branch Then commit it: git commit -m "Revert file from other branch" Option 2: If your local branch is already tracking the remote branch You can shorten it to: git checkout [remote_branch] -- file_path_in_GIT (Still followed by a commit.) Option 3: Using modern git restore (Git ≥ 2.23) git fetch origin git restore --source=origin/[remote_branch] -- file_path_in_GIT Then commit: git commit -m " Revert file from other branch" Verify before committing (optional but smart) git diff ⚠️ Notes This does not switch branches This does not affec...

Useful aliases

alias ll="ls -lah" alias branch="git branch" alias checkout="git checkout" commit() { echo "Enter commit message (Ctrl+D to finish):" msg=$(cat) git commit -m "$msg" } add() { # Ensure git repo git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return 0 # Colors GREEN="\e[32m" RED="\e[31m" YELLOW="\e[33m" CYAN="\e[36m" BOLD="\e[1m" RESET="\e[0m" local current_branch remote_branch behind local files file answer local added_files=() local skipped_files=() local temp_ignored_files=() local existing_temp_ignored=() current_branch=$(git branch --show-current) # ---------- STEP 0: Check existing temp-ignore files ---------- mapfile -t existing_temp_ignored /dev/null 2>&1 || { echo -e "${RED}Fetch failed.${RESET}" return 1 } behind=$(git rev-list --count HEAD.."$remote_branch" ...

Start all Docker containers

To start (bring up) all existing Docker containers , use this: docker start $(docker ps -aq) Explanation docker ps -aq → lists all containers (running or stopped) docker start → starts stopped containers If you are using Docker Compose From the directory with docker-compose.yml: docker compose up -d Or for multiple compose projects (containers already created): docker compose start Useful checks See all containers and their status: docker ps -a See only running containers: docker ps Common gotcha If you see access forbidden , it means: Image not pulled (private registry) Not logged in Login first: docker login Then retry: docker start $(docker ps -aq)  

Back up from Android to OneDrive with rclone

Backing up your Android device to OneDrive is easy using rclone . Even if your OneDrive account has two-factor authentication (2FA) , rclone works perfectly by authorizing once through a web browser. Step 1 — Install rclone in Termux pkg install rclone Step 2 — Configure OneDrive Run the following command: rclone config Answer the prompts as follows: New remote: n Name: onedrive Storage: OneDrive Client ID: press Enter Client Secret: press Enter Edit advanced config? n Use auto config? n (important on Android) After choosing No for auto config, rclone will show a long URL. Copy the URL Open it in your Android web browser Sign in to OneDrive and approve access Copy the verification code Paste it back into Termux Two-factor authentication works normally during this step. Step 3 — Test the OneDrive Connection rclone lsd onedrive: If your OneDrive folders appear, the setup is complete. Step 4 — Backup Using ...

Using NextDNS to block ad on Android

Here’s a full guide to understanding NextDNS — what it does, how to set it up on your Android device (and elsewhere), and tips to get the most out of it. What is NextDNS? NextDNS is a cloud-based DNS filtering and security service. According to its website, it: Blocks ads, trackers, malicious domains, phishing, cryptojacking and more. Works across all devices and networks (WiFi, mobile, public hotspots) Supports modern DNS encryption protocols (DNS-over-TLS, DNS-over-HTTPS) for better privacy. Provides customization: blocklists, allow-lists, content categories, parental controls, logging & analytics. In short: it works like a “smart hosts file + firewall” but at the DNS level, meaning you don’t need root or filesystem hacks. How to set up NextDNS on Android STEP 1 — Create your NextDNS profile Go to: https://my.nextdns.io Create an account (free) You will see a profile ID like: abcd12.dns.nextdns.io This ...

Run termux script using macrodroid

Running a Termux script from MacroDroid is best done using the Termux:Tasker plugin. Despite the name, this plugin works perfectly with MacroDroid. Prerequisite: The "F-Droid" Rule Critical: You must install both Termux and the Termux:Tasker plugin from F-Droid . If you installed Termux from the Google Play Store, it will not work because the Play Store version is outdated. Action: Uninstall the Play Store version and install the latest versions from F-Droid. Step 1: Set up the Termux Environment Open Termux. Create the mandatory folder for external scripts: mkdir -p ~/.termux/tasker Move your script to this folder (or create a new one there). Example: nano ~/.termux/tasker/myscript.sh Important: Make the script executable. chmod +x ~/.termux/ta...

Disable accessibilty and Developer mode to run app

APP="com.banking.app" # Turn OFF Developer Options (UI only, does not reset settings) ~/rish/rish -c "settings put global development_settings_enabled 0" # Backup the current accessibility services ORIGINAL=$(~/rish/rish -c "settings get secure enabled_accessibility_services") echo "Original accessibility services:" echo "$ORIGINAL" echo "Disabling all accessibility services..." ~/rish/rish -c "settings put secure enabled_accessibility_services \"\"" ~/rish/rish -c "settings put secure accessibility_enabled 0" echo "Launching $APP..." ~/rish/rish -c "monkey -p $APP -c android.intent.category.LAUNCHER 1 >/dev/null 2>&1" echo "Waiting for $APP to close..." while true; do     TOP=$(~/rish/rish -c "dumpsys activity activities | grep mResumedActivity | grep $APP")     if [ -z "$TOP" ]; then         break     fi     sleep 1 done echo "$APP...

Archive and Unarchive app using rish

Archive and Unarchive App Using Rish To archive: ~/rish/rish -c 'pm archive --user 0 com.example.app' To unarchive: ~/rish/rish -c 'pm request-unarchive --user 0 com.example.app' This will unarchive from Play Store. To backup and restore locally: Archive and backup: # Create backup folder ~/rish/rish -c "mkdir -p /data/local/tmp/com.example.app" # Delete old backup ~/rish/rish -c "rm -f /data/local/tmp/com.example.app/*" # Copy all APK files for p in $(~/rish/rish -c "pm path com.example.app" | cut -d: -f2); do ~/rish/rish -c "cp "$p" /data/local/tmp/com.example.app/" done # Archive ~/rish/rish -c "pm archive --user 0 com.example.app" exit Restore: PACKAGE="com.example.app" APK_DIR="/data/local/tmp/com.example.app" # Install / unarchive with Play Store as installer SESSION=$(~/rish/rish -c "pm install-create -i com.android.vending" | awk -F'[][]...

Open app using rish

~/rish/rish -c 'monkey -p com.example.app 1'

Disable battery optimization with rish

 ~/rish/rish -c 'dumpsys deviceidle whitelist +com.example.app'   Example: ~/rish/rish -c 'dumpsys deviceidle whitelist +com.arlosoft.macrodroid'  

Turn off and on Developer options without losing any setting with risk

 ~/rish/rish -c 'settings put global development_settings_enabled 0' ~/rish/rish -c 'settings put global development_settings_enabled 1'

Enable all accessibility services with rish

This method is for Samsung devices. First, dump all accessibility services: ~/rish/rish -c 'dumpsys accessibility' > dump.txt This saves the output to dump.txt . Make sure your rish path is correct or added to PATH . In the dump output, look for: installed services: You can ignore the first few com.samsung.xxx entries. The rest will look like: com.anydesk.adcontrol.ad1/com.anydesk.adcontrol.AccService com.arlosoft.macrodroid/.triggers.services.MacroDroidAccessibilityServiceJellyBean com.arlosoft.macrodroid/.action.services.UIInteractionAccessibilityService com.catalinagroup.callrecorder.helper/com.catalinagroup.callrecorder.service.AnyCallListenerService com.eset.ems2.gp/com.eset.commoncore.core.accessibility.CoreAccessibilityService org.skvalex.cr/.full.service.MyAccessibilityService Combine them into one line, separated by : and ending with a trailing : (important for One UI): ~/rish/rish -c 'settings put secure enabled_accessibility_services ...