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 / .unibeautifyrc.json
Created January 7, 2020 11:07
Unibeautify configuration file for html, ejs, css and javascript
{
"HTML": {
"beautifiers": [
"Pretty Diff",
"JS-Beautify"
],
"indent_size": 2,
"indent_style": "space",
"max_preserve_newlines": 0,
"multiline_ternary": "never",
@poudelmadhav
poudelmadhav / remove_duplicate.md
Last active April 14, 2020 12:05
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
end

Source: Remove duplicate records based on multiple columns?

@poudelmadhav
poudelmadhav / copy_data_from_one_to_another_and_insert.md
Created July 15, 2020 14:10
Copy one data from another table SQL

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
poudelmadhav / docker-pry-rails.md
Created August 20, 2020 07:22 — forked from briankung/docker-pry-rails.md
Using pry-rails with Docker

First, add pry-rails to your Gemfile:
https://github.com/rweng/pry-rails

gem 'pry-rails', group: :development

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

@poudelmadhav
poudelmadhav / lamp.md
Last active November 9, 2020 13:27
LAMP Setup in ubuntu
@poudelmadhav
poudelmadhav / add_unique_index_on_user_id_to_kycs.rb
Created January 19, 2021 07:08
Add unique constrainst on existing foreign_key constrant in rails migration
# 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
end
end
@poudelmadhav
poudelmadhav / web-servers.md
Created May 11, 2021 12:24 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@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
@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 / 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;