Skip to content

Instantly share code, notes, and snippets.

@sandipchitale
sandipchitale / aexpath.js
Last active June 14, 2020 09:04
Get xPath of document.activeElement
{ let e = document.activeElement; let pchain = []; while (e.tagName !== 'BODY') { pchain.unshift(e.tagName + '[' + (Array.prototype.indexOf.call(e.parentElement.querySelectorAll(':scope > ' + e.tagName), e) + 1) + ']'); e = e.parentElement; } ; '/html/body/' + pchain.join('/').toLowerCase() }
@sandipchitale
sandipchitale / DumpServletsBean.java
Last active February 11, 2025 05:27
Springboot dump filters and spring security filter chains #spring-security-filter-chain
public class DumpServlets extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
System.out.println("---Servlets---");
Map<String, ? extends ServletRegistration> servletRegistrations = request.getServletContext()
.getServletRegistrations();
for (Entry<String, ? extends ServletRegistration> servletNameServletRegistrationEntry : servletRegistrations
.entrySet()) {
@sandipchitale
sandipchitale / pom.xml
Last active November 6, 2020 03:09
Generic mechanism to install self to local repository in m2 folder
<!--
To use this goal invoke it like this:
> mvnw install:install-file@m2
This will install the artifact in local folder m2/repository
-->
<build>
<plugins>
<plugin>
@sandipchitale
sandipchitale / build-only-tasks.gradle
Last active October 31, 2020 19:53
Specify which order tasks should run in specified or natural
// Apply this from main build script using:
// if (rootProject.hasProperty('only-tasks')) {
// apply from: 'build-only-tasks.gradle'
// }
//
// Usage:
//
// gradlew -Ponly-tasks
// gradlew -Ponly-tasks -Pprompt-for-tasks
// gradlew -Ponly-tasks -Pprompt-for-tasks -Pspecified-order
@sandipchitale
sandipchitale / apply-gradle-taskinfo.gradle
Created November 15, 2020 00:48
Apply gradle-taskinfo plugin to rootProject
initscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.org.barfuin.gradle.taskinfo:gradle-taskinfo:1.0.3"
}
}
@sandipchitale
sandipchitale / recipe.gradle
Last active November 18, 2020 22:41
Simple recipe based execution of tasks
// Apply using the following at the end of build.gradle
//
// if (hasProperty('RECIPE')) {
// apply from: 'recipe.gradle'
// }
//
// Usage:
//
// > .\gradlew.bat -PRECIPE=First
//
@sandipchitale
sandipchitale / doskey.mac
Last active December 18, 2020 04:17
Save and show and put history in clipboard with REM prefix
-="C:\Program Files\Microsoft VS Code\Code.exe" "%USERPROFILE%\cmd.history"
_=doskey /history | wsl grep -e '^^[-_+.]' -v | wsl grep -e '^^break' -v | wsl grep -e '^^)' -v | findstr "^" >> "%USERPROFILE%\cmd.history"
+=type "%USERPROFILE%\cmd.history"
.=type "%USERPROFILE%\cmd.history" | wsl awk 'BEGIN { print "break||(" ;} { print $1 } END { print ")" }' | clip
_u=(type "%USERPROFILE%\cmd.history" | wsl awk '!a[$0]++' | findstr "^" > "%USERPROFILE%\cmd.history.bkp") && (type "%USERPROFILE%\cmd.history.bkp" > "%USERPROFILE%\cmd.history") && (del "%USERPROFILE%\cmd.history.bkp")
@sandipchitale
sandipchitale / tabId.js
Created December 21, 2020 01:31
Assign next tabId to every new tab and save in session storage
(function() {
// Does this tab have a tabId
let tabId = sessionStorage.getItem("tabId");
if (tabId === null) {
// no tabId for this tab
// Is lastTabId stored in local storage
let lastTabId = localStorage.getItem("lastTabId");
if (lastTabId === null) {
// no lastTabId saved in local storage
lastTabId = -1;
@sandipchitale
sandipchitale / URIComponentsFromCurrentRequest.java
Created December 31, 2020 07:57
Build URI compoents from current request considering4 x-forwarded-* headers #springboot
UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(
new ServletServerHttpRequest(((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest())).build();
@sandipchitale
sandipchitale / index.js
Created January 14, 2021 01:20
axe+puppeteer
const util = require('util');
const puppeteer = require('puppeteer');
const axe = require('axe-core');
const urls = [
];
const results = [];