Skip to content

Instantly share code, notes, and snippets.

@sandipchitale
sandipchitale / FileTypes.md
Last active September 9, 2024 23:15
FileTypes in IntelliJ Ultimate #intellij

Class: com.intellij.openapi.fileTypes.impl.AbstractFileType Name: IDL Description: IDL Class: com.intellij.openapi.fileTypes.impl.AbstractFileType Name: JavaFX Description: JavaFX Class: com.intellij.openapi.fileTypes.impl.AbstractFileType Name: C++ Description: C/C++ Class: com.intellij.openapi.fileTypes.impl.AbstractFileType Name: C# Description: C# Class: com.intellij.openapi.fileTypes.impl.AbstractFileType Name: Perl Description: Perl Class: com.intellij.openapi.fileTypes.impl.AbstractFileType Name: AspectJ Description: AspectJ (syntax highlighting only) Class: com.intellij.openapi.fileTypes.impl.AbstractFileType Name: Haskell Description: Haskell Class: com.intellij.openapi.fileTypes.impl.AbstractFileType Name: PHP Description: PHP (syntax highlighting only) Class: com.intellij.ide.highlighter.ArchiveFileType Name: ARCHIVE Description: Archive Class: com.intellij.openapi.fileTypes.PlainTextFileType Name: PLAIN_TEXT Description: Text

@sandipchitale
sandipchitale / Kaitenzushi.java
Last active August 29, 2024 04:00
Kaitenzushi #facebook
public int getMaximumEatenDishCount(int N, int[] D, int K) {
// N must be less than D.length right?
if (N > D.length) {
throw new IllegalArgumentException("N must be less than or equal to D.length");
}
int count = 0;
// LRU cache to store the last K dishes
Map<Integer, Integer> lastK = new LinkedHashMap<Integer, Integer>(K, 0.75f, false) {
@Override
@sandipchitale
sandipchitale / uniform.java
Created August 28, 2024 22:50
Uniform INteger Count between inclusive Range #facebook
static int getUniformIntegerCountInInterval(long A, long B) {
int count = 0;
int lenA = String.valueOf(A).length();
int lenB = String.valueOf(B).length();
for (int i = lenA; i <= lenB; i++) {
String spacesOfLengthI = String.format("%" + i + "s", " ");
for (int j = 1; j <= 9; j++) {
Long uniformNumber = Long.valueOf(spacesOfLengthI.replace(" ", String.valueOf(j)));
if (uniformNumber >= A && uniformNumber <= B) {
count++;
@sandipchitale
sandipchitale / README.md
Last active June 22, 2024 02:30
Connect to desktop chrome #pupeteer

create a new chrome shortcut on your desktop and add --remote-debugging-port=9222 to the target. open it using the just created shortcut and go to http://127.0.0.1:9222/json/version

example: ws://127.0.0.1:9222/devtools/browser/1a59ad92-052d-4d44-b614-b6bf15999d10

Browser "Chrome/126.0.6478.114" Protocol-Version "1.3" User-Agent "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36" V8-Version "12.6.228.19"

@sandipchitale
sandipchitale / reg.bat
Created May 15, 2024 21:31
Directly invoke Explorer context menu #windows11
reg add HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32 /ve /d "" /f
@sandipchitale
sandipchitale / Insecure.java
Last active November 27, 2023 02:54
SslBundles #https #ssl #sslbundles
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import io.netty.handler.ssl.util.KeyManagerFactoryWrapper;
import javax.net.ssl.KeyManager;
SslManagerBundle insecureSslManagerBundle = SslManagerBundle.of(
new KeyManagerFactoryWrapper(new KeyManager() {}),
InsecureTrustManagerFactory.INSTANCE);
insecureSslBundle = SslBundle.of(null,
null,
@sandipchitale
sandipchitale / PostProcessor.java
Last active November 19, 2023 11:28
Set portmapper for oauth2Login() #oauth2Login #portMapper
ObjectPostProcessor<AuthenticationEntryPoint> authenticationEntryPointFilterPostProcessor = new ObjectPostProcessor<>() {
@Override
public <O extends AuthenticationEntryPoint> O postProcess(O authenticationEntryPoint) {
if (authenticationEntryPoint instanceof DelegatingAuthenticationEntryPoint delegatingAuthenticationEntryPoint) {
Field entryPointsField = ReflectionUtils.findField(DelegatingAuthenticationEntryPoint.class, "entryPoints");
assert entryPointsField != null;
entryPointsField.setAccessible(true);
LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPoints =
(LinkedHashMap<RequestMatcher, AuthenticationEntryPoint>) ReflectionUtils.getField(entryPointsField,
delegatingAuthenticationEntryPoint);
@sandipchitale
sandipchitale / application.properties
Created November 13, 2023 20:27
Hidden Spring HandlerMapping logger #logging
logging.level._org.springframework.web.servlet.HandlerMapping=DEBUG
@sandipchitale
sandipchitale / ErrorHandling.java
Created November 10, 2023 05:15
ErrorHandling #spring-web-mvc
@ExceptionHandler(Exception.class)
public ResponseEntity<String> handleError(HttpServletRequest req, Exception ex) {
if (ex.getCause() instanceof SocketTimeoutException) {
return ResponseEntity.status(HttpStatus.GATEWAY_TIMEOUT).body(HttpStatus.GATEWAY_TIMEOUT.getReasonPhrase());
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
}
@sandipchitale
sandipchitale / wraprequest.java
Last active October 29, 2023 22:31
Where request dispatcher creates forward request #tomcat #requestdispatcher
org.apache.catalina.core.ApplicationDispatcher#wrapRequest