Skip to content

Instantly share code, notes, and snippets.

View poudelmadhav's full-sized avatar
🕯️
Light a candle than to curse the darkness.

Madhav Paudel poudelmadhav

🕯️
Light a candle than to curse the darkness.
View GitHub Profile
@poudelmadhav
poudelmadhav / downloads_controller.rb
Last active June 12, 2026 11:05
A zero-dependency Ruby on Rails implementation to redirect users to the Apple App Store or Google Play Store using User-Agent matching.
class DownloadsController < ApplicationController
APP_STORE_URL = "https://apps.apple.com/us/app/google/id284815942".freeze
PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox".freeze
def show
if apple_device?
redirect_to APP_STORE_URL, allow_other_host: true
else
redirect_to PLAY_STORE_URL, allow_other_host: true
end
@poudelmadhav
poudelmadhav / backup.md
Last active February 3, 2025 07:20
Export/Dump and import mysql data

Dump MySQL data

mysqldump --no-tablespaces --extended-insert --single-transaction --quick -h example.com -u username -p databasename > dump.sql --set-gtid-purged=OFF

With PV command:

mysqldump --no-tablespaces --extended-insert --single-transaction --quick -h example.com -u username -p databasename --set-gtid-purged=OFF | pv > dump.sql
@poudelmadhav
poudelmadhav / phpmyadmin-in-docker.md
Last active November 28, 2025 05:07
Run phpmyadmin in docker and connect to local mysql

Run phpmyadmin in docker

Find the ip address running this command:

ip addr show docker0 | grep inet

This will be the PMA_HOST in below steps. The PMA_HOST of local machine is like this: 172.17.0.1

Now, run phppmyadmin on docker.

@poudelmadhav
poudelmadhav / docker-in-rails-7-with-mysql.md
Last active July 24, 2024 07:31
Starting docker in rails 7.1 with a separate MySQL container

Setting Up MySQL

  1. Pull the MySQL image:

    docker pull mysql/mysql-server
  2. Run the MySQL container in a persistent volume:

@poudelmadhav
poudelmadhav / charset-and-collation.md
Last active June 18, 2025 04:34
View or change charset and collation of database and table in sql

View all databases charset and collation:

SELECT SCHEMA_NAME 'database', default_character_set_name 'charset', DEFAULT_COLLATION_NAME 'collation' FROM information_schema.SCHEMATA;

View specified database charset and collation:

USE db_name;
SELECT @@character_set_database, @@collation_database;
@poudelmadhav
poudelmadhav / comma_separate_number.js
Created December 9, 2022 16:30
Comma separate number js
commaSeparateNumber(event) {
let x, x1, x2;
let nStr = event.target.value + '';
nStr = nStr.replace(/\D+/g, '');
x = nStr.split( '.' );
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while ( rgx.test(x1) ) {
x1 = x1.replace( rgx, '$1' + ',' + '$2' );
@poudelmadhav
poudelmadhav / index.html
Created August 5, 2022 06:20
Align content horizontally and vertically center
<div class="parent">
<section>
<h1>Center elements</h1>
<p>Center elements vertically or horizontally using following css</p>
<pre>
<code>
.parent {
display: flex;
justify-content: center;
align-items: center;
@poudelmadhav
poudelmadhav / cache_assets_precompilation.yml
Last active May 17, 2022 03:50
Cache webpacker and assets precombile
# Source: https://git.521000.bestmunity/t/cache-rails-assets-generated-by-webpacker/189057/4
- name: Get Webpacker cache key
id: get-webpacker-cache-key
run: |
echo "::set-output name=key::$(bin/rails r 'print Webpacker::Instance.new.compiler.send(:watched_files_digest)')"
shell: bash
- name: Cache precompiled assets
uses: actions/cache@v3
with:
@poudelmadhav
poudelmadhav / change_mysql_plugin.sql
Last active April 10, 2025 11:22
Change root mysql password and auth plugin (known case)
-- Plugin can be 'auth_socket', 'mysql_native_password' or 'caching_sha2_password'
SELECT user, authentication_string,plugin,host FROM mysql.user;
-- Change the auth socket plugin to caching_sha2_password of root user
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';
FLUSH PRIVILEGES;
-- Create another user that uses caching_sha2_password as plugin
USE mysql;
CREATE USER '{user}'@'localhost' IDENTIFIED WITH caching_sha2_password BY '{password}';
@poudelmadhav
poudelmadhav / reset_mysql_password.md
Last active May 23, 2025 08:58
Reset mysql root password

Reset MySQL Root Password:

  • Stop MySQL
sudo service mysql stop
  • Make MySQL service directory.
sudo mkdir /var/run/mysqld
  • Give MySQL user permission to write to the service directory.