Skip to content

Instantly share code, notes, and snippets.

@sandipchitale
sandipchitale / scan-session-storage.js
Created August 28, 2018 21:31
Scan session storage for JWT access tokens
function tryFromStorage() {
chrome.tabs.executeScript(null, {
code: `
(function readFrom(result) {
([window.sessionStorage, window.localStorage]).forEach(function(storage) {
for (let i = 0; i < storage.length; ++i) {
const key = storage.key(i);
if (key.includes('access')) {
result.push(storage.getItem(key));
}
@sandipchitale
sandipchitale / post.java
Last active September 12, 2018 19:49
Post with RestTemplate
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
// add to map the form parameters
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
try {
restTemplate.postForEntity(url, request, String.class);
} catch (RestClientException e) {
@sandipchitale
sandipchitale / ctoroverride.js
Last active September 14, 2018 22:17
Generic constructor override with example of Date
(function (context, constructorName, special) {
var Original;
Original = context[constructorName];
context[constructorName] = function PatchedOriginal() {
var args;
args = Array.prototype.slice.call(arguments);
var returnObject;
if (special) {
returnObject = special(Original, PatchedOriginal, args);
}
@sandipchitale
sandipchitale / winpath.sh
Last active July 29, 2022 17:28
Show Windows path of PWD in WSL. Example usage to launch explorer: /mnt/c/Windows/explorer.exe `winpwd`
#!/bin/bash
# set -x
LXSS_PATH="$(/mnt/c/Windows/System32/cmd.exe /C echo %LOCALAPPDATA% | tr -d '\f\n\r')\\lxss"
# Show help
if [[ "$1" == "--help" ]] ; then
echo "$0 [--help] [absolute or relative path]"
exit
fi
@sandipchitale
sandipchitale / angular.json
Last active December 7, 2018 23:09
Snippet for bootstrap.js stuff
[
"node_modules/jquery/dist/jquery.js",
"node_modules/popper.js/dist/umd/popper.js",
"node_modules/bootstrap/dist/js/bootstrap.js"
]
@sandipchitale
sandipchitale / componentLifecycleMethodOrderRule.ts
Last active January 5, 2020 22:56
TSLInt rule that ensures that a @component has constructor, ngOnInit and ngOnDestroy in correct order.
/**
* TSLInt rule that ensures that a @Component has constructor, ngOnInit and ngOnDestroy in correct order.
*/
import {
SourceFile, ClassDeclaration, MethodDeclaration,
createNodeArray,
isCallExpression,
isIdentifier,
Decorator,
SyntaxKind
@sandipchitale
sandipchitale / console.table.js
Created March 13, 2019 17:52
Highlight elements with id's (or other selectors), display in table form in Chrome Devtools Console.
console.table(([].slice.call(document.querySelectorAll("[id]"))).map((e) => { e.style.outline = '1px solid red'; e.title = (e.id + ' ' + e.title); return {'id': e.id, 'element': e} }))
<html>
<head>
<style>
html,
body {
top: 0;
left: 0;
}
<html>
<head>
<style>
html,
body {
top: 0;
left: 0;
}
@sandipchitale
sandipchitale / nfs-client-provisioner.yml
Created June 20, 2019 20:58
NFS Server + dynamic NFS Client provisioner
---
kind: ServiceAccount
apiVersion: v1
metadata:
name: nfs-client-provisioner
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: nfs-client-provisioner-runner