This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package x.y.z; | |
import lombok.extern.log4j.Log4j2; | |
import org.springframework.security.core.Authentication; | |
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.Cookie; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Date arithematic in Shell: | |
# Assign a specific date to variable | |
start=`date -d 2021-03-22` | |
# Add 1 day to the start | |
date -d "$start 1 days" # 2021-04-01 | |
# Subtract 1 day from the start | |
date -d "$start -1 days" # 2021-03-29 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add below function to the ~/.bashrc file to make it available globally | |
vpn_fix () { | |
# Get the DNS servers from windows and add then to the /etc/resolv.conf | |
powershell.exe -Command 'Get-DnsClientServerAddress -AddressFamily ipv4 | Select-Object -ExpandProperty ServerAddresses' | awk 'BEGIN { print "# Generated by vpn fix func on", strftime("%c"); print } { print "nameserver", $1 } END { print "search", "nuance.com" }' | tr -d '\r' | tee /etc/resolv.conf | |
echo "/etc/resolv.conf re-written!!" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.piyush; | |
import org.junit.jupiter.api.Test; | |
import org.springframework.boot.test.context.SpringBootTest; | |
@SpringBootTest | |
public class MyApplicationTest { | |
@Test | |
public void contextLoads() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from datetime import timezone | |
# Get timezone unaware current date time | |
print(datetime.datetime.now()) # 2020-09-18 22:17:52.878325 | |
# Get timezone unaware current date time in UTC | |
print(datetime.datetime.utcnow()) # 2020-09-18 16:48:17.822981 | |
# Preferred way is to use 'now' and pass it a timezone | |
print(datetime.datetime.now(timezone.utc)) # 2020-09-18 16:48:17.822981 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
client = boto3.client('sns') | |
topics = client.list_topics() | |
print(topics) | |
topicArn = topics['Topics'][0]['TopicArn'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nth highest salary - [Generic] | |
SELECT * from employee e1 where N-1 = (SELECT COUNT(DISTINCT(salary)) from employee e2 where e2.salary > e1.salary); | |
# Ex: To get 2nd highest, N = 2 | |
SELECT * from employee e1 where 1 = (SELECT COUNT(DISTINCT(salary)) from employee e2 where e2.salary > e1.salary); | |
# Nth highest salary - [PostgreSQL] - Faster | |
SELECT DISTINCT(salary) from employee order by salary desc limit 1 offset N-1; | |
# Ex: To get 2nd highest, N = 2 | |
SELECT DISTINCT(salary) from employee order by salary desc limit 1 offset 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tomtom.postal; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutionException; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
import java.util.stream.Stream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5"> | |
<div> | |
<b>Username:</b> | |
<div sec:authentication="name"> | |
The value of the "name" property of the authentication object should appear here. | |
</div> | |
</div> | |
<div> | |
<b>User Roles: </b> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using AWS Route 53 DNS: | |
1. As active and passive failover setup: Make 2 record sets with the same domain name and set one as primary and the other as secondary under Routing Policy Type "Failover". | |
2. As round-robin DNS setup: Make 2 record sets with same domain name and set weight to 50 percent on both under Routing Policy Type "Weighted". | |
NewerOlder