Skip to content

Instantly share code, notes, and snippets.

Avatar

Amol Deshmukh adeshmukh-quizlet

View GitHub Profile
@adeshmukh-quizlet
adeshmukh-quizlet / awk_netstat.sh
Created Sep 3, 2020 — forked from staaldraad/awk_netstat.sh
AWK to get details from /proc/net/tcp and /proc/net/udp when netstat and lsof are not available
View awk_netstat.sh
# Gawk version
# Remote
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($3,index($3,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($3,i,2))}{print x":"strtonum("0x"substr($3,index($3,":")+1,4))}'
# Local
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($2,index($2,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($2,i,2))}{print x":"strtonum("0x"substr($2,index($2,":")+1,4))}'
# No Gawk
# Local
grep -v "rem_address" /proc/net/tcp | awk 'function hextodec(str,ret,n,i,k,c){
@adeshmukh-quizlet
adeshmukh-quizlet / md5b64
Created Apr 25, 2020
kscript to generate base64 of md5 values
View md5b64
#!/usr/bin/env kscript
import java.security.MessageDigest
import java.util.Base64
val md5 = MessageDigest.getInstance("MD5")
println(args.map { Base64.getEncoder().encodeToString(md5.digest(it.toByteArray())) }.joinToString(" "))
@adeshmukh-quizlet
adeshmukh-quizlet / bitrev
Created Apr 23, 2020
Kotlin script to generate bitrev values
View bitrev
#!/usr/bin/env kscript
println(args.map { java.lang.Long.reverse(it.toLong()) }.joinToString(" "))
View keybase.md

Keybase proof

I hereby claim:

  • I am adeshmukh-quizlet on github.
  • I am adeshmukh_qz (https://keybase.io/adeshmukh_qz) on keybase.
  • I have a public key ASBWRTbbokm4Kr9FuY7H4YeyHCyeqJLJyB1Yh-NUQI9wfwo

To claim this, I am signing this object:

@adeshmukh-quizlet
adeshmukh-quizlet / ShardIdGenerator.kt
Last active Jul 16, 2019
Distributed ID Generation in Kubernetes
View ShardIdGenerator.kt
// 32-bit value will overflow in 2038. Migrate to 64-bit support by then.
// Ref: https://en.wikipedia.org/wiki/Year_2038_problem
private const val TIME_PART_MASK = 0x0000_0000_FFFF_FFFF
const val SHARD_PART_WIDTH = 5
const val SEQ_PART_WIDTH = 15
const val SEQ_PART_LIMIT_EXCLUSIVE = 1.shl(SEQ_PART_WIDTH)
/**
* A distributed, thread-safe ID generator that generates