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
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')){
@poudelmadhav
poudelmadhav / slacknotify.html
Last active Feb 21, 2019
An example in jquery to notify slack filled data in the contact form
View slacknotify.html
<!-- Dont forget to keep your webhook url in ENV["webhook_url"] -->
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<style>
input[type=text], select {
width: 100%;
padding: 12px 20px;
View add-or-remove-table-row-based-focus.html
<input type="number" id="days"> <!-- the td and tr are added equal to this value -->
<input type="text" onfocus="addItineraryDays()"> <!-- function calling onfocus this input -->
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Day</th>
<th>Itineraries</th>
</tr>
</thead>
<tbody id="myTable">
You can’t perform that action at this time.