Skip to content

Instantly share code, notes, and snippets.

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 / lamp.md
Last active Nov 9, 2020
LAMP Setup in ubuntu
View lamp.md
@poudelmadhav
poudelmadhav / docker-pry-rails.md
Created Aug 20, 2020 — forked from briankung/docker-pry-rails.md
Using pry-rails with Docker
View docker-pry-rails.md

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

View copy_data_from_one_to_another_and_insert.md

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 / remove_duplicate.md
Last active Apr 14, 2020
removing duplicates from rails model
View remove_duplicate.md
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 / .unibeautifyrc.json
Created Jan 7, 2020
Unibeautify configuration file for html, ejs, css and javascript
View .unibeautifyrc.json
{
"HTML": {
"beautifiers": [
"Pretty Diff",
"JS-Beautify"
],
"indent_size": 2,
"indent_style": "space",
"max_preserve_newlines": 0,
"multiline_ternary": "never",
@poudelmadhav
poudelmadhav / deploy.sh
Last active Oct 23, 2019
sysc dist/ to aws s3 and create invalidations in cloudfront with notifying at slack
View deploy.sh
#!/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 / 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>
</div>
*************************************************************/
$( document ).ready(function() {
var ja = document.getElementById("JapaneseLanguage");
var en = document.getElementById("EnglishLanguage");
View serverless authentication using cloudfront.js
'use strict';
exports.handler = (event, context, callback) => {
// Get request and request headers
const request = event.Records[0].cf.request;
const headers = request.headers;
// Configure authentication
const authUser = 'user';
const authPass = 'pass';
View lambda function to redirect based of browser's language.js
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')){
You can’t perform that action at this time.