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 / 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 / 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 / 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 / cplus_program_to_transfer_balance.cpp
Last active October 29, 2023 12:29
C++ program to transfer money from one account to another
/******************************************************************************
Balance Transfer
//Author Madhav Paudel
*******************************************************************************/
#include <iostream>
#include<iomanip>
using namespace std;
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
const headers = request.headers;
if(request.uri == '/') {
if (typeof headers['accept-language'] !== 'undefined') {
const supportedLanguages = headers['accept-language'][0].value;
console.log('Supported languages:', supportedLanguages);
if(supportedLanguages.startsWith('en')){
callback(null, redirect('/en/index.html'));
} else if(supportedLanguages.startsWith('ja')){
@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 / 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 / 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 / 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