Skip to content

Instantly share code, notes, and snippets.

@Kshitij09
Kshitij09 / sjira.sh
Created September 22, 2022 15:09
Utility shell function to perform common operations around Jira Ticket URLs. Currently supports macOS only
function sjira() {
local __usage="
Usage: sjira GROW-3599 [-poc]
Options:
-p, --print Print genereated URL
-o, --open Open generated URL in browser (Default)
-c, --copy Copy generated URL to clipboard
"
if [ "$#" -lt 1 ]; then
@Kshitij09
Kshitij09 / generate_PKCS8-X509_keypair.md
Last active November 8, 2021 21:17
Guide to generate public-private keypair to be used for Asymmetric JWT Signing with Java
  1. Generate a 2048-bit RSA private key

    openssl genrsa -out private_key.pem 2048
  2. Convert private Key to PKCS#8 format (so Java can read it)

openssl pkcs8 -topk8 -inform pem -in private_key.pem -outform der -nocrypt -out private_key.der.pkcs8

@Kshitij09
Kshitij09 / ComposeAutoCompleteTextField.kt
Last active April 3, 2023 10:06
AutoCompleteTextView implemented in Jetpack Compose.
@Composable
fun AutoCompleteTextField(
initialText: String,
itemList: List<String>,
onQuery: (String) -> Unit,
onClearResults: () -> Unit,
modifier: Modifier = Modifier
) {
val (field, changeField) = savedInstanceState(saver = TextFieldValue.Saver) { TextFieldValue(text = initialText) }
LaunchedEffect(subject = field.text) {
@Kshitij09
Kshitij09 / get-compose-samples.sh
Last active November 15, 2020 16:22
Download and install latest "compose-samples" (https://github.com/android/compose-samples/releases). Make sure you have "curl, wget, jq and adb" installed on your machine
#!/bin/bash
check_if_assets_empty() {
release_id=$1
assets=$(curl -q https://api.github.com/repos/android/compose-samples/releases/$release_id/assets 2>/dev/null)
[ ${#assets[@]} -eq 0 ]
}
ask() {
read -ep "$1" answer
@Kshitij09
Kshitij09 / android_snippets.kt
Last active July 5, 2020 20:17
some snippets that could be useful in various scenarios
// Hide the keyboard on button click
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, 0)
// hide the menu item if doesn't resolve
// getShareIntent() is supposed to return your intent object
if (null == getShareIntent().resolveActivity(activity!!.packageManager)) {
menu.findItem(R.id.share).setVisible(false)
}
@Kshitij09
Kshitij09 / lightning_utils.py
Created June 22, 2020 17:58
Utility functions for Pytorch Lightning (heavily borrowed from fastai)
from pytorch_lightning import Callback
from IPython.display import display, clear_output
import copy
import pandas as pd
import torch
from torch import nn
import matplotlib.pyplot as plt
import math
imagenet_stats = ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
@Kshitij09
Kshitij09 / imagewoof-class-mappings.py
Created June 21, 2020 11:10
Imagewoof class id to name mapping
lbl_dict = dict(
n02086240= 'Shih-Tzu',
n02087394= 'Rhodesian ridgeback',
n02088364= 'Beagle',
n02089973= 'English foxhound',
n02093754= 'Australian terrier',
n02096294= 'Border terrier',
n02099601= 'Golden retriever',
n02105641= 'Old English sheepdog',
n02111889= 'Samoyed',
@Kshitij09
Kshitij09 / PrintCallback.py
Last active June 20, 2020 12:31
`PrintCallback` for PytorchLightining to create tabular logs of metrics in Jupyter Notebook
import torch
from pytorch_lightning import Callback
from IPython.display import display, clear_output
import copy
import pandas as pd
def unwrap(x):
if isinstance(x,torch.Tensor):
return x.item()
return x
@Kshitij09
Kshitij09 / fastai2_colab_setup.sh
Last active May 8, 2020 10:40
Utility script to setup fastai2 on colab
#!/bin/bash
if [ ! -e /content/models ]; then
mkdir -p /root/.fastai/data
ln -s /root/.cache/torch/checkpoints/ /content
ln -s /root/.fastai/data /content
rm -rf /content/sample_data/
mkdir /content/models
fi
echo Installing dependencies
pip install -q feather-format kornia pyarrow wandb nbdev fastprogress --upgrade
@Kshitij09
Kshitij09 / parse_xml.js
Last active April 12, 2019 04:12
Javascript code to open an xml file from client machine and parse its contents
/**
* <input type="file" id="xmlFile" />
* include this tag in your html file
* you can use the following xml file for testing
* file URL: https://drive.google.com/file/d/1Ifef0RCqCq5apRT2LQbB6HguD43VpTXF/view?usp=sharing
*/
document.querySelector('#xmlFile').addEventListener('change', readFile, false);
function readFile(e) {