Skip to content

Instantly share code, notes, and snippets.

View vihangpatil's full-sized avatar
:octocat:
Happy with Kotlin

Vihang Patil vihangpatil

:octocat:
Happy with Kotlin
View GitHub Profile
alias bu='brew update && brew upgrade && brew cleanup'
alias dcu='docker compose up --build'
alias dcua='docker compose up --build --abort-on-container-exit'
alias dcd='docker compose down'
alias drmi='docker images -q --filter dangling=true | xargs docker rmi'
alias drmv='docker volume prune -f'
alias drmn='docker network prune -f'
alias drmc='docker ps -a -q | xargs docker rm -f'
@vihangpatil
vihangpatil / validated.kt
Last active July 27, 2022 09:07
Kotlin custom monad bind() for Arrow-kt Validated returning ValidatedNei similar to either, option and nullable.
import arrow.core.NonEmptyList
import arrow.core.Validated
import arrow.core.ValidatedNel
import arrow.core.invalid
import arrow.core.nonEmptyListOf
import arrow.core.valid
interface ValidatedEffect<INVALID, VALID> {
suspend fun toValidatedNel(): ValidatedNel<INVALID, VALID>
}
@vihangpatil
vihangpatil / StripeCustomersEmailDomainAsCSV.kt
Last active July 27, 2022 09:04
Check email domains of Stripe Customers from exported CSV file
import java.io.File
data class Domain(
val fqdn: String,
val withoutTLD: String,
)
fun main() {
val emailDomainList = File("src/main/resources/customers.csv")
.readLines()
@vihangpatil
vihangpatil / AppleIdAuthClient.kt
Created November 18, 2021 08:36
Kotlin Backend Client to verify AppleId Auth Code
import arrow.core.Either
import arrow.core.left
import arrow.core.right
import com.typesafe.config.ConfigFactory
import io.github.config4k.extract
import io.jsonwebtoken.JwtBuilder
import io.jsonwebtoken.Jwts
import io.jsonwebtoken.SignatureAlgorithm
import io.ktor.client.*
import io.ktor.client.call.*
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.ktor.client.HttpClient
import io.ktor.client.request.post
import io.ktor.client.request.put
import io.ktor.content.TextContent
import io.ktor.http.ContentType
import java.util.*
class PubSubClient(label: String) {
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.junit.jupiter.api.Test
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime
class DispatcherTest {
@vihangpatil
vihangpatil / PriorityQueue.kt
Created June 1, 2018 06:44
Priority Queue sorted by timestamp in message. Will guarantee order for messages delayed upto 3 sec.
package io.github.vihangpatil.sandbox
import java.time.Instant
import java.util.*
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit.MILLISECONDS
import kotlin.Comparator
data class Message(
val timestamp: Long,
@vihangpatil
vihangpatil / .bash_profile
Last active March 6, 2018 04:06
Have random emoticons in your shell prompts.
emoji[0]='🔥'
emoji[1]='💰'
emoji[2]='🐚'
emoji[3]='🏹'
emoji[4]='🖥'
emoji[5]='🎯'
emoji[6]='💯'
emoji[7]='🛡'
emoji[8]='🚀'
emoji[9]='🇮🇳'
@vihangpatil
vihangpatil / DigitTrie.java
Last active October 15, 2017 08:17
Digit Trie
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.LinkedList;
/**
* Put list of prefixes and their corresponding labels.
* Then get the label for longest matching prefix.
*
* @author Vihang Patil <vihang.patil@gmail.com>

Keybase proof

I hereby claim:

  • I am vihangpatil on github.
  • I am vihang_patil (https://keybase.io/vihang_patil) on keybase.
  • I have a public key whose fingerprint is 6FDF F1EC 8682 5CA7 5736 CF47 089C FBBB E120 EBC6

To claim this, I am signing this object: