Skip to content

Instantly share code, notes, and snippets.

Light a candle than to curse the darkness.

Madhav Paudel poudelmadhav

Light a candle than to curse the darkness.
View GitHub Profile
poudelmadhav / add_unique_index_on_user_id_to_kycs.rb
Created Jan 19, 2021
Add unique constrainst on existing foreign_key constrant in rails migration
View add_unique_index_on_user_id_to_kycs.rb
# Example:
# Adding unique index on user_id(existing foreign_key) of kycs table
class AddUniqueIndexOnUserIdToKycs < ActiveRecord::Migration[6.0]
def change
remove_foreign_key :kycs, :users
remove_index :kycs, :user_id
add_index :kycs, :user_id, unique: true
add_foreign_key :kycs, :users
poudelmadhav / cplus_program_to_transfer_balance.cpp
Last active Dec 24, 2020
C++ program to transfer money from one account to another
View cplus_program_to_transfer_balance.cpp
Balance Transfer
//Author Madhav Paudel
#include <iostream>
using namespace std;
poudelmadhav /
Last active Nov 9, 2020
LAMP Setup in ubuntu
poudelmadhav /
Created Aug 20, 2020 — forked from briankung/
Using pry-rails with Docker

First, add pry-rails to your Gemfile:

gem 'pry-rails', group: :development

Then you'll want to rebuild your Docker container to install the gems


Copy data from one table to another table, and insert it.

INSERT INTO destination_table(
  col1, col2, col3, col4, col5, col6
SELECT col1, col2, col3, 'custom_value' as col4, col5, col6
FROM source_table;
poudelmadhav /
Last active Apr 14, 2020
removing duplicates from rails model
models = Model.all.group_by{|model| [model.attr1,model.attr2,model.attr3] }; nil
models.values.each do |duplicates|
  first_one = duplicates.shift
  duplicates.each{|double| double.destroy} # duplicates can now be destroyed

Source: Remove duplicate records based on multiple columns?

poudelmadhav / .unibeautifyrc.json
Created Jan 7, 2020
Unibeautify configuration file for html, ejs, css and javascript
View .unibeautifyrc.json
"HTML": {
"beautifiers": [
"Pretty Diff",
"indent_size": 2,
"indent_style": "space",
"max_preserve_newlines": 0,
"multiline_ternary": "never",
poudelmadhav /
Last active Oct 23, 2019
sysc dist/ to aws s3 and create invalidations in cloudfront with notifying at slack
poudelmadhav / redirect ... to ja...js
Last active May 20, 2019
Redirect based on browser languae lambda function redirect .. to ja..
View redirect ... to ja...js
'use strict';
// Configure authentication
const authUser = 'user';
const authPass = 'pass';
exports.handler = (event, context, callback) => {
// Get request and request headers
const request = event.Records[0].cf.request;
const headers = request.headers;
View get language redirect url in language switch button.js
<div id="myDropdown" class="dropdown-content">
<a href="/ja/index.html" id="JapaneseLanguage">JAPANESE</a>
<a href="/en/index.html" id="EnglishLanguage">ENGLISH</a>
$( document ).ready(function() {
var ja = document.getElementById("JapaneseLanguage");
var en = document.getElementById("EnglishLanguage");
You can’t perform that action at this time.