Skip to content

Instantly share code, notes, and snippets.

View shortthirdman's full-sized avatar
🎯
Focusing

Swetank Mohanty shortthirdman

🎯
Focusing
View GitHub Profile
@shortthirdman
shortthirdman / ReflectionUtils.java
Created June 27, 2024 08:13
Java Reflection Utils
import java.lang.reflect.Field;
public class ReflectionUtils {
public static <T> T getOrDefault(T object, String propertyName, Class<T> clazz, T defaultValue) {
try {
// Get the field by name
Field field = object.getClass().getDeclaredField(propertyName);
// Ensure field is accessible
@shortthirdman
shortthirdman / JwtAuthenticationFilter.java
Created June 27, 2024 07:56
JWT Authentication Filter
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
@shortthirdman
shortthirdman / IdGenerator.java
Created June 24, 2024 05:52
Identifier Generator using Hibernate
package com.example.generator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.Configurable;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type;
@shortthirdman
shortthirdman / INSTALL.md
Last active June 1, 2024 14:45
IBM WebSphere Liberty Developer Tools Configuration

IBM WebSphere Application Server Liberty

  bin/installUtility install adminCenter-1.0
  bin/installUtility install openidConnectServer-1.0
  bin/installUtility install javaMail-1.5
  bin/installUtility install jwtSso-1.0
  bin/installUtility install springBoot-2.0
  bin/installUtility install oauth-2.0
  bin/installUtility install jsp-2.2
@shortthirdman
shortthirdman / MANIFEST.md
Created June 1, 2024 12:13
Manifest Configurations in Spring Boot

JAR - MANIFEST.MF

Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.mycompany.project.MyApplication

WAR - MANIFEST.MF

@shortthirdman
shortthirdman / codetemplates.xml
Created June 1, 2024 10:48
Eclipse CodeTemplate
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<templates>
<template autoinsert="true" context="org.eclipse.jsdt.delegatecomment_context" deleted="false" description="Comment for delegate functions" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">/**
* ${tags}
* ${see_to_target}
*/
</template>
<template autoinsert="true" context="org.eclipse.jsdt.constructorcomment_context" deleted="false" description="Comment for created constructors" enabled="true" id="org.eclipse.wst.jsdt.ui.text.codetemplates.constructorcomment" name="constructorcomment">/**
* ${tags}
*/
@shortthirdman
shortthirdman / count_semiprimes.py
Created April 21, 2024 09:07
Count Semi-Primes - Codility
def count_semiprimes(N, P, Q):
from math import sqrt
# Find out all the primes with Sieve of Eratosthenes
prime_table = [False] * 2 + [True] * (N-1)
prime = []
prime_count = 0
for element in xrange(2, int(sqrt(N))+1):
if prime_table[element] == True:
prime.append(element)
prime_count += 1
@shortthirdman
shortthirdman / minimum_bit_flips.py
Created April 12, 2024 19:01
Minimum number of flips of binary bit (0 or 1)
from collections import Counter
def getMinFlips(pwd):
# O(n)
zeroCounter = Counter()
reverseOnesCounter = Counter()
n = len(pwd)
if n % 2 != 0:
return 0
@shortthirdman
shortthirdman / groupAnagrams.py
Created June 2, 2022 19:21
Group similar anagrams (Python)
# Function to group anagrams from a given list of words
def groupAnagrams(words):
# a list to store anagrams
anagrams = []
# base case
if not words:
return anagrams
# sort each word on the list
@shortthirdman
shortthirdman / topKFrequent.py
Created May 17, 2022 12:27
Finding the top K frequent elements from the array/list of integers
from heapq import heappush, heappop
from collections import defaultdict
class Solution:
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
if nums == []:
return []
map = {}
for num in nums:
if num in map: