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 / backup.md
Created March 19, 2024 12:09
Export/Dump and import mysql data

Dump MySQL data

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

Import it

mysql -h example.com -u username -p databasename < dump.sql
@poudelmadhav
poudelmadhav / phpmyadmin-in-docker.md
Last active March 19, 2024 11:46
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 March 14, 2024 09:17
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 September 4, 2023 07:18
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://github.community/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 March 5, 2024 11:04
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 mysql_native_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 September 13, 2023 07:50
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.
@poudelmadhav
poudelmadhav / routes
Created June 4, 2021 05:11 — forked from zernel/routes
Devise disable signup
devise_for :users, :skip => [:registrations]
as :user do
get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'
put 'users' => 'devise/registrations#update', :as => 'user_registration'
end
# And then modify the app/views/devise/shared/_links.erb