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 / redirect ... to ja...js
Last active May 20, 2019 10:04
Redirect based on browser languae lambda function redirect .. to ja..
'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;
@poudelmadhav
poudelmadhav / deploy.sh
Last active October 23, 2019 06:58
sysc dist/ to aws s3 and create invalidations in cloudfront with notifying at slack
#!/bin/sh
target_env=$1
profile=$2
REPO="https://gitlab.com/namespace-inc/corporate"
SLACK_URL="https://hooks.slack.com/services/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"
CHANNEL="#corporate"
BOTNAME="deployer"
@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